Compare two different size vectors of the same struct

Cristopher Sosa

I'm developing a super-small package manager for custom purposes with a simple dependency checker, for that i need to compare two vectors (but same data type, an struct) the first vector has the installed packages by the user (using a simple SQLite query) , and the second vector the required packages to install.

The struct code is like:

typedef struct {
  std::string UniformTypeID;
  std::string PackageName;
  unsigned int Version; 
} PackageInfo;

i need to know how to compare these two vectors but here's a problem, the size of the two vectors may vary, for example, if i use the size of the installed packages vector is smaller than the dependency packages (more larger), no find any package in their limit, but the requested package is more beyond of their limit.

I can use C++11.

Chad

Provide a strict weak ordering predicate for your PackageInfo class, either in terms of a binary predicate or simply provide an operator<.

With that you can sort your arrays (installed packages and required packages). Then you can use the set manipulation functions of the STL:

std::vector<PackageInfo> installed_packages = ...;
std::vector<PackageInfo> required_packages = ...;
std::vector<PackageInfo> met_requirements;

std::sort(installed_packages.begin(), installed_packages.end());
std::sort(required_packages.begin(), required_packages.end());

std::set_intersection(
   installed_packages.begin(), installed_packages.end(),
   required_packages.begin(), installed_packages.end(),
   std::back_inserter(met_requirements));

met_requirements is now the set of PackageInfo that is present in both the installed_pacakges and required_packages. You can then verify if all of the necessary required_packages are available.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Compare two different size vectors of the same struct

From Dev

Compare two vectors of same size in MATLAB

From Dev

Join two different size cells in the same struct

From Dev

Compare two different size of string arraylist in Java

From Dev

Compare two vectors in java?

From Dev

Compare values of two vectors

From Dev

Compare two vectors in java?

From Dev

Compare two vectors

From Dev

C: Two Different Arrays Pointing to the Same Struct

From Dev

Find all mappings between two binary vectors of same size?

From Dev

Two screens, same size with different density

From Dev

How to compare two different values of different functions or same function?

From Dev

Compare two character vectors in R

From Dev

How to compare two vectors for equality?

From Dev

How to compare two vectors for equality?

From Dev

How to traverse two same size matrices and compare them

From Java

Pandas compare and sum values between two DataFrame with different size

From Dev

How to compare two different size arraylists and check for order of elements

From Dev

how to compare two arrays with different size using php?

From Dev

Putting vectors of different size in a matrix

From Dev

Two pointers holding same Node struct address print different values

From Java

How to compare two different commits on the same branch in github?

From Dev

How do I compare two different values of the same field in MySQL?

From Java

How to compare two JSON objects with the same elements in a different order equal?

From Dev

Compare two different string with the same part in Ruby on Rails

From Dev

Compare two lines having the same key and determine whether a value is different or not

From Dev

Clojure - Merge two vectors of vectors different sizes

From Dev

Iterate two vectors with different lengths

From Dev

Iterate two vectors with different lengths

Related Related

  1. 1

    Compare two different size vectors of the same struct

  2. 2

    Compare two vectors of same size in MATLAB

  3. 3

    Join two different size cells in the same struct

  4. 4

    Compare two different size of string arraylist in Java

  5. 5

    Compare two vectors in java?

  6. 6

    Compare values of two vectors

  7. 7

    Compare two vectors in java?

  8. 8

    Compare two vectors

  9. 9

    C: Two Different Arrays Pointing to the Same Struct

  10. 10

    Find all mappings between two binary vectors of same size?

  11. 11

    Two screens, same size with different density

  12. 12

    How to compare two different values of different functions or same function?

  13. 13

    Compare two character vectors in R

  14. 14

    How to compare two vectors for equality?

  15. 15

    How to compare two vectors for equality?

  16. 16

    How to traverse two same size matrices and compare them

  17. 17

    Pandas compare and sum values between two DataFrame with different size

  18. 18

    How to compare two different size arraylists and check for order of elements

  19. 19

    how to compare two arrays with different size using php?

  20. 20

    Putting vectors of different size in a matrix

  21. 21

    Two pointers holding same Node struct address print different values

  22. 22

    How to compare two different commits on the same branch in github?

  23. 23

    How do I compare two different values of the same field in MySQL?

  24. 24

    How to compare two JSON objects with the same elements in a different order equal?

  25. 25

    Compare two different string with the same part in Ruby on Rails

  26. 26

    Compare two lines having the same key and determine whether a value is different or not

  27. 27

    Clojure - Merge two vectors of vectors different sizes

  28. 28

    Iterate two vectors with different lengths

  29. 29

    Iterate two vectors with different lengths

HotTag

Archive