Why would anyone use set instead of unordered_set?(为什么有人会使用 set 而不是 unordered_set?)
问题描述
C++0x 正在引入 unordered_set
,它可以在 boost
和许多其他地方使用.我的理解是 unordered_set
是具有 O(1)
查找复杂性的哈希表.另一方面,set
只不过是具有 log(n)
查找复杂性的树.到底为什么有人会使用set
而不是unordered_set
?即是否需要 set
了?
C++0x is introducing unordered_set
which is available in boost
and many other places. What I understand is that unordered_set
is hash table with O(1)
lookup complexity. On the other hand, set
is nothing but a tree with log(n)
lookup complexity. Why on earth would anyone use set
instead of unordered_set
? i.e is there a need for set
anymore?
推荐答案
对于想要迭代集合中的项目的人来说,顺序很重要.
When, for someone who wants to iterate over the items of the set, the order matters.
这篇关于为什么有人会使用 set 而不是 unordered_set?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么有人会使用 set 而不是 unordered_set?


基础教程推荐
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 从 std::cin 读取密码 2021-01-01