C++ STL源码剖析之unordered_map、unordered_multimap、unordered_set、unordered_multiset
导语
前面学到了hashtable,而这节是hashtable的容器适配器:unordered_map。
所以无序map的底层容器采用hashtable。
unordered_map与unordered_multimap本质区别
先来看一下unordered_map源码:
template<class _Key, class _Tp,
class _Hash = hash<_Key>,
class _Pred = std::equal_to<_Key>,
class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
class unordered_map
{
typedef __umap_hashtable<_Key, _Tp, _Hash, _Pred, _Alloc> _Hashtable;
_Hashtable _M_h;
};
去看底层容器的__umap_hashtable的声明:
template<bool _Cache>
using __umap_traits = __detail::_Hashtable_traits<_Cache, false, true>;
tem