Fra*_*ank 36
您可以将第一个列表的所有元素放入哈希集中.然后,迭代第二个,并为其每个元素检查哈希,看它是否存在于第一个列表中.如果是,则将其输出为交集的元素.
Ane*_*apu 22
您可能想看一下Bloom过滤器.它们是位向量,它给出概率回答元素是否是集合的成员.可以使用简单的按位AND运算来实现集合交集.如果您有大量的空交叉点,Bloom过滤器可以帮助您快速消除这些交叉点.但是,您仍然必须使用此处提到的其他算法来计算实际交点. http://en.wikipedia.org/wiki/Bloom_filter
没有散列,我想你有两个选择:
From the eviews features list it seems that it supports complex merges and joins (if this is 'join' as in DB terminology, it will compute an intersection). Now dig through your documentation :-)
Additionally, eviews has their own user forum - why not ask there_
小智 6
在C++中,可以使用STL map尝试以下内容
vector<int> set_intersection(vector<int> s1, vector<int> s2){
vector<int> ret;
map<int, bool> store;
for(int i=0; i < s1.size(); i++){
store[s1[i]] = true;
}
for(int i=0; i < s2.size(); i++){
if(store[s2[i]] == true) ret.push_back(s2[i]);
}
return ret;
}
Run Code Online (Sandbox Code Playgroud)
小智 6
使用set 1构建一个二进制搜索树,O(log n)
并使用和迭代set2并搜索BST m X O(log n)
总数O(log n) + O(m)+O(log n) ==> O(log n)(m+1)