在std :: map中查找

时间:2011-04-04 14:30:54

标签: c++ stl

  

可能重复:
  STL like container with O(1) performance.

我一直认为std :: map是一个散列列表。在那种情况下,不应该查找O(1)。文档说它是O(logn)。什么是STL中适当的数据结构,模拟散列映射最好用O(1)插入和查找。

3 个答案:

答案 0 :(得分:6)

std::map实现为二叉搜索树。所以查找不是O(1)。 TR1和C ++ 0x正在向STL添加一个名为unordered_map的哈希映射。见http://en.wikipedia.org/wiki/Unordered_map_(C%2B%2B

根据您的编译器,STL中可能有unordered_maphash_map

答案 1 :(得分:2)

没有正式的STL容器具有常量查找功能。但是,一些库实现提供了一个非标准的hash_map容器,它执行O(1)查找(http://www.sgi.com/tech/stl/hash_map.html

答案 2 :(得分:-1)

您正在寻找std::hash_map

相关问题