I am calculating intersection, union and differences of sets.
I have a typedef of my set type:
typedef set<node_type> node_set;
When it is replaced with
typedef hash_set<node_type> node_set;
The results are different. It’s a complicated program, and before I start debugging – am I doing it right? When I use functions like this:
set_intersection(v_higher.begin(), v_higher.end(), neighbors[w].begin(), neighbors[w].end(),
insert_iterator<node_set>(tmp1, tmp1.begin()));
- should they work seamlessly with both set and hash_set?
I don’t think so.
One of the pre-condition of
set_intersectionis:[first1, last1)is ordered in ascending order according tooperator<. That is, for every pair of iteratorsiandjin[first1, last1)such thatiprecedesj,*j < *iis false.The
hash_set(andunordered_set) is unordered, so the ordered condition cannot be satisfied.See tr1::unordered_set union and intersection on how to intersect
unordered_sets.