如何用树数据结构有效地实现无序映射
How can unordered_map be efficiently implemented with tree data structures?
考虑unordered_map
:
template<
class Key,
class T,
class Hash = std::hash<Key>,
class KeyEqual = std::equal_to<Key>,
class Allocator = std::allocator< std::pair<const Key, T> >
> class unordered_map;
我知道(a==b)
比!(a<b) && !(b>a)
快,但由于unordered_map
不使用std::less<Key>
来比较/存储映射中的密钥,我想知道一个实现如何通过树数据结构以最有效的方式读取/存储同一存储桶中的不同密钥来获利。似乎任何使用树的实现都无法避免从Key转换为定义了operator<()
的KeyWrapper。
不能在unordered_map
中使用树,即使只是在bucket中。unordered_map
的接口根本不允许这样做。只要求密钥类型具有相等性,仅此而已。这就是为什么它被称为"无序"地图;因为不存在元素的特定排序。要使用某种二叉树,需要严格的弱排序,而这不是必需的。
如果你想使用unordered_map
的变体,你可以。但它不是标准定义的unordered_map
。
相关文章:
- 递归无序映射
- 正在将无序映射设置为无序映射的值
- 智能指针作为无序映射键,并通过引用进行比较
- 打印无序映射的第二个元素,即集合
- 由并发无序映射查找线程调用的函数是否安全?
- 将大数字(10-12 位数字)存储在无序映射中<字符串,整数>
- 使用无序映射在STL中存储键值对
- 为C++中的无序映射获取给定输入键的错误值
- 将大型对象存储在无序映射中是否效率低下
- 在无序映射的结构化绑定中推导类型
- 使用无序映射进行错误索引
- 将一个向量对放在一个无序映射与一个映射中
- 如何在c++中修改无序映射中的每个值
- C++:使用一对(cpp_int,int)整数作为无序映射中的键(其中cpp_int是boost多精度整数)
- 将 [] 索引到无序映射时出现段错误
- 以std::字符串作为关键字,按字典顺序对一个无序映射进行排序
- 无序映射存储桶的节点大小
- 在无序映射<字符串上使用 find(),向量<string>>与 C++ 中的有序映射花费相同的时间
- 以三个无符号字符为关键字的无序映射
- 无序映射比c++中的映射慢吗