【问题标题】:what is c++ std::unordered_map default container?什么是 c++ std::unordered_map 默认容器?
【发布时间】:2020-12-22 07:57:34
【问题描述】:

我正在研究 unordered_map 的内部逻辑。

发现它使用了容器。并使用键值来寻找价值。

unordered_map的默认容器是std::vector吗??

还有其他容器,例如 std::map 可以吗?

【问题讨论】:

标签: c++ containers std unordered-map


【解决方案1】:

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;

这里唯一的“默认”类型是键散列函数、键比较器和分配器。

如果你指的是装桶的容器,它通常只是原始的BucketType*

【讨论】:

  • 哈希表是由数组组成的吗?还是 std::vector??
猜你喜欢
  • 2013-10-25
  • 1970-01-01
  • 2019-01-11
  • 2017-04-27
  • 1970-01-01
  • 2020-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多