将信息保存到哈希表或向量中
saving information into hash table or vectors
我想知道哪一个更快哈希表或向量
如果我想循环遍历里面的所有信息并将其与当前数据进行比较,如果它已经在里面,我想打破循环。
的例子:
我有[{1,2},{1,2,3}],在循环中,我当前的新数据是{1,2}(它在我的向量或哈希表中),所以我将打破循环,如果我有{2,1},我也会打破循环。
如果所有元素都匹配,不管顺序如何,否则继续循环。如果哈希表要快得多,我可以有一个关于如何实现它的提示吗?因为我是c++新手
Hashtable将更好地工作,因为您可以创建键值对。唯一的条件是不能有多于一个键相同的组合。因此,表中不能有3,1和3,2,因为键是唯一的。
如果在lhs上有副本,那么最好使用vector
我将使用嵌套集,即std::set<std::set<int> >
。
#include <set>
#include <cassert>
typedef std::set<int> Entry;
typedef std::set<Entry> Table;
int main () {
int e1[] = {1,2};
int e2[] = {1,2,3};
int e3[] = {2,1};
int e4[] = {3,2};
Table t;
t.insert(Entry(e1, e1+2));
t.insert(Entry(e2, e2+3));
Table::iterator it;
Table::iterator end = t.end();;
// Search for 1,2
it = t.find(Entry(e1, e1+2));
// Should find it
assert(it != end);
// Search for 2,1
it = t.find(Entry(e3, e3+2));
// Should find it
assert(it != end);
// Search for 3,2
it = t.find(Entry(e4, e4+2));
// Should NOT find it
assert(it == end);
}
相关文章:
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 如何将这个C++哈希表转换为动态扩展和收缩,而不是使用硬设置的最大值
- 用C++将哈希表写入文件并从文件中恢复
- C++中的并发哈希表
- 在具有开放寻址的哈希表中插入节点 [优化逻辑]
- 与C++哈希表的基础知识混淆
- 调整大小和复制哈希表数组中的元素
- 带链接的基本哈希表
- C++哈希表中,两个相同的实现,但一个给出错误
- 如果索引不是整数,我们如何在 C++ 中插入哈希表
- 为什么C++ STL 哈希表 (unordered_map) 不接受向量作为键
- 创建哈希表,其中每个值都是许多值的向量
- 使用对数据类型的向量的哈希表中的分段错误错误
- 将对向量对矢量转换为哈希表 /地图
- 使用向量<对<字符串,int > >表示哈希表
- 将信息保存到哈希表或向量中
- 哈希表搜索函数使用向量在c++中
- 人对象向量哈希表c
- c++哈希表,其中键是字符串,值是字符串的向量
- 我怎样才能让一对向量像哈希表一样工作呢?