Matching between sets of integers

I need to map a set of integers to sets of integers.

First of all, I want to note that not all possible sets of integers are taken into account. Rather, I create the appropriate sets that the application will use (ever) - programmatically, only once and serializes it in a binary file.

Then I built QMap<QSet<int>, QSet<int> > setMap.

In the future, the application creates another set of integers (by user input), calls it userSetand quickly gets it setMap[userSet].

Now the problem is what QMapneeds operator <, specific to the key types, and obviously QSet<int>does not have this.

What can i do with this?

+2
source share
4 answers

, (QVector<QSet<int> >) (QMap<int,int>) .

+1

< . Employee QMap . ​​:

 bool operator<(const QSet<int> &first, const QSet<int> &second)
 {
    // your logic to compare the two sets
 }
+1

a QString. , - ( ) .

+1

I would convert sets into ordered lists and map them (and then convert back to set). It is easier to define a comparison operator for an ordered list than for a set. Of course, this may be too slow for you.

You can also use a hash map.

0
source

All Articles