如何保持一组没有重复的向量
How to maintain a set of vectors with no repetitions
我有一个c++程序,它产生了很多整数向量(每个向量都是排序的),它们的产生速度非常快,而且数量很多,我需要跟踪它们并删除重复的部分,最后把它们全部打印出来。我应该使用什么数据结构?
我尝试使用hash_map
和unordered_map
,但我得到了很多的错误,似乎他们不支持向量的哈希映射(所以他们如何支持字符串虽然?):
(.text+0xdc56): undefined reference to `std::tr1::hash<std::vector<int, std::allocator<int> > >::operator()(std::vector<int, std::allocator<int> >) const'
objects/Prog.o: In function `std::tr1::_Hashtable<std::vector<int, std::allocator<int> >, std::pair<std::vector<int, std::allocator<int> > const, int>, std::allocator<std::pair<std::vector<int, std::allocator<int> > const, int> >, std::_Select1st<std::pair<std::vector<int, std::allocator<int> > const, int> >, std::equal_to<std::vector<int, std::allocator<int> > >, std::tr1::hash<std::vector<int, std::allocator<int> > >, std::tr1::__detail::_Mod_range_hashing, std::tr1::__detail::_Default_ranged_hash, std::tr1::__detail::_Prime_rehash_policy, false, false, true>::_M_rehash(unsigned long)':
Prog.cpp:(.text._ZNSt3tr110_HashtableISt6vectorIiSaIiEESt4pairIKS3_iESaIS6_ESt10_Select1stIS6_ESt8equal_toIS3_ENS_4hashIS3_EENS_8__detail18_Mod_range_hashingENSE_20_Default_ranged_hashENSE_20_Prime_rehash_policyELb0ELb0ELb1EE9_M_rehashEm[std::tr1::_Hashtable<std::vector<int, std::allocator<int> >, std::pair<std::vector<int, std::allocator<int> > const, int>, std::allocator<std::pair<std::vector<int, std::allocator<int> > const, int> >, std::_Select1st<std::pair<std::vector<int, std::allocator<int> > const, int> >, std::equal_to<std::vector<int, std::allocator<int> > >, std::tr1::hash<std::vector<int, std::allocator<int> > >, std::tr1::__detail::_Mod_range_hashing, std::tr1::__detail::_Default_ranged_hash, std::tr1::__detail::_Prime_rehash_policy, false, false, true>::_M_rehash(unsigned long)]+0x126): undefined reference to `std::tr1::hash<std::vector<int, std::allocator<int> > >::operator()(std::vector<int, std::allocator<int> >) const'
collect2: ld returned 1 exit status
make: *** [run] Error 1
有其他方法可以绕过这个吗?有没有其他的数据结构效率更高?
您需要为vector提供一个散列函数来使用unordered_map。默认情况下提供string的哈希函数。或者,您可以使用std::set。std::set的元素保证没有重复。
相关文章:
- 在 c++ 中拥有一组结构的正确方法是什么?
- 有哪些有效的方法可以消除一组 100 万个字符串>重复数据?
- 程序以使用 C++ 中的 while 循环查找一组数字的最小值
- 如何在向量数组中插入元素?
- 不同大小的向量数组的大小 cpp
- 很好的语法来获取对向量/数组数据的大小引用?
- C++向量和数组
- Push_back一组(异构)向量的实现
- 创建一组向量
- 从向量<T>创建一组字符串
- 检查向量中的一组值
- C :通过一组向量的向量进行迭代
- STL向量和地图在删除一组记录时应该更喜欢
- C++:为什么创建的向量没有传递到下一组 for 循环
- 如何用c++将一个向量数组放入一个一维数组中
- 将一组字符串分配给向量c++的内容
- C++是否有任何方法可以将一组派生类存储在基类的一个向量中,并仍然访问它们的成员
- 如何在 C++ 中从一组向量中删除重复的向量
- 实例化一个二维向量,其中一组对作为单元值
- 如何保持一组没有重复的向量