在线文档教程

UnorderedAssociativeContainer

C++概念:UnorderedAssociativeContainer

无序关联容器是Container斯提供基于键的对象快速查找。最坏的情况复杂性是线性的,但对于大多数操作来说,平均速度要快得多。

无序关联容器被KeyHash,一Hash函数对象,充当散列函数。Key;和Pred,一BinaryPredicate评价等价性KeyS.std::unordered_mapstd::unordered_multimap也有映射类型。TKey...

如果两个KeyS是平等的Pred,,,Hash必须为两个键返回相同的值。

std::unordered_mapstd::unordered_set最多可以包含一个具有给定键的元素,std::unordered_multisetstd::unordered_multimap相反,可以有多个具有相同键%28的元素,而在迭代%29时,这些元素必须总是相邻的。

为std::unordered_set和std::unordered_multiset值类型与键类型相同,两者都是iterator和const_iterator是常量迭代器。为std::unordered_map和std::unordered_multimap值类型是std::pair<const Key, T>...

无序关联容器中的元素被组织成桶,具有相同哈希的键将在同一个桶中结束。当容器的大小增加时,桶的数量会增加,以将每个桶中的元素的平均数量保持在一定的值以下。

重哈希会使迭代器无效,并可能导致元素在不同的桶中重新排列,但它不会使对元素的引用无效。

无序关联容器满足AllocatorAwareContainer.为std::unordered_mapstd::unordered_multimap对...的要求value_typeAllocatorAwareContainer适用于key_typemapped_type%28未调至value_type29%。

所需

传说

*。

X容器型

X型对象

B型对象

阿[医]当X支持唯一键时,X中的Uniq对象

阿[医]当X支持多个等价键时,X中的EQ对象

i,j表示有效范围的输入器

P,Q2有效Const[医]迭代器到

q,q1可解除引用的常数[医]表示有效范围的迭代器

STD的IL对象::初始化器[医]列表<X::值[医]类型>

类型为X::value的T对象[医]类型

类型为X::Key的K对象[医]类型

X型HF Const对象::Hasher

类型为X::Key的EQConst对象[医]平等

X型N值::大小[医]类型

浮子型Z值

expressionreturn typepre/requirementspost/effectscomplexity
X::key_typeKeycompile time
X::mapped_typeTstd::unordered_map and std::unordered_multimap onlycompile time
X::value_typeKeystd::unordered_set and std::unordered_multiset only. Erasable in Xcompile time
X::value_typestd::pair<const Key, T>std::unordered_map and std::unordered_multimap only. Erasable in Xcompile time
X::hasherHashHashcompile time
X::key_equalPredBinaryPredicate taking two arguments of type Key and expressing an equivalence relation.compile time
X::local_iteratorAn Iterator whose category and types are the same as X::iteratorCan be used to iterate through a single bucketcompile time
X::const_local_iteratorAn Iterator whose category and types are the same as X::const_iteratorCan be used to iterate through a single bucketcompile time
X(n,hf,eq)Xhasher and key_equal CopyConstructibleConstructs an empty container with at least n buckets, using the given hash function and equality predicatelinear in n
X(n,hf)Xhasher CopyConstructible, key_equal DefaultConstructibleConstructs an empty container with at least n buckets, using the given hash function and key_equal() as equality predicatelinear in n
X(n,hf)Xhasher and key_equal DefaultConstructibleConstructs an empty container with at least n buckets, using hasher() as hash function and key_equal() as equality predicatelinear in n
X()Xhasher and key_equal DefaultConstructibleConstructs an empty container with an unspecified number of buckets, using hasher() as hash function and key_equal() as equality predicateconstant
X(i,j,n,hf,eq)Xhasher and key_equal CopyConstructible, value_type EmplaceConstructible into X from *iConstructs an empty container with at least n buckets, using the given hash function and equality predicate, and inserts elements from [i,j) into it.average linear, worst quadratin (on the distance between i and j)
X(i,j,n,hf)Xkey_equal DefaultConstructibleAs above, with eq=key_equal()see above
X(i,j,n)Xhasher DefaultConstructibleAs above, with hf=hasher()see above
X(i,j)XAs above, with an unspecified number of bucketssee above
X(il)XX(il.begin(),il.end()see above
X(il,n)XX(il.begin(),il.end(),nsee above
X(il,n,hf)XX(il.begin(),il.end(),n,hfsee above
X(il,n,hf,eq)XX(il.begin(),il.end(),n,hf,eqsee above
X(b)XCopy constructors, also copies the hash function, predicate and maximum load factoraverage linear, worst quadratic (in b.size())
a = bX&Copy assignment, also copies the hash function, predicate and maximum load factoraverage linear, worst quadratic (in b.size())
a = ilX&value_type CopyAssignable and CopyInsertable into Xa = X(il)see above

标准库中的UnorderedAssociativeContainer

unordered_set (since C++11)collection of unique keys, hashed by keys (class template)
unordered_multiset (since C++11)collection of keys, hashed by keys (class template)
unordered_map (since C++11)collection of key-value pairs, hashed by keys, keys are unique (class template)
unordered_multimap (since C++11)collection of key-value pairs, hashed by keys (class template)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/Concept/UnorderedAssociativeContainer