我计算交集,并集和集合的差异。 我有一个类型的typedef:
typedef set< node_type> node_set;当它替换为
typedef hash_set< node_type> node_set;结果不同。这是一个复杂的程序,在我开始调试之前 - 我做对吗?当我使用这样的功能:
set_intersection(v_higher.begin(),v_higher.end(),neighbors [w]。 begin(),neighbors [w] .end(), insert_iterator< node_set>(tmp1,tmp1.begin如果它们与set和hash_set无缝地工作,则
- <
我不这么认为。
set_intersection 是:
- [first1,last1) > 运算符< 按升序排序。也就是说,对于中的每对迭代器 i 和 j [first1,last1) / code>,使 i 在之前, * j < c $> ( unordered_set )是无序的,因此无法满足有序条件。
请参阅 stackoverflow/questions/896155/c-tr1unordered-set-union-and-intersection 如何与 unordered_set 相交。
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_intersection is:
- [first1, last1) is ordered in ascending order according to operator<. That is, for every pair of iterators i and j in [first1, last1) such that i precedes j, *j < *i is false.
The hash_set (and unordered_set) is unordered, so the ordered condition cannot be satisfied.
See stackoverflow/questions/896155/c-tr1unordered-set-union-and-intersection on how to intersect unordered_sets.
更多推荐
在C ++中,set
发布评论