在C ++中,set_intersection可以和hash_set一起使用吗? [英] Can set_intersection be used with hash_set in C++?
问题描述
我计算交集,并集和集合的差异。
我有一个类型的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无缝地工作,则
<
我不这么认为。
-
[first1,last1)
>运算符<
按升序排序。也就是说,对于中的每对迭代器
i
和j
[first1,last1) / code>,使i
在之前
,* j < c $> (
unordered_set
)是无序的,因此无法满足有序条件。
请参阅 http://stackoverflow.com/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 tooperator<
. That is, for every pair of iteratorsi
andj
in[first1, last1)
such thati
precedesj
,*j < *i
is false.
The
hash_set
(andunordered_set
) is unordered, so the ordered condition cannot be satisfied.See http://stackoverflow.com/questions/896155/c-tr1unordered-set-union-and-intersection on how to intersect
unordered_set
s.这篇关于在C ++中,set_intersection可以和hash_set一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!