boolcontains(constKey&key,std::size_thash)const; (1)(since C++20) template<classK>boolcontains(constK&x)const; (2)(since C++20) template<classK>boolcontains(constK&x,std::size_thash)const; (2)(since C++20) 1)Checks if there is an element with key equivalent tokeyin the container...
unordered_map 是关联容器,含有带唯一键的键-值 pair 。搜索、插入和元素移除拥有平均常数时间复杂度。 元素在内部不以任何特定顺序排序,而是组织进桶中。元素放进哪个桶完全依赖于其键的哈希。这允许对单独元素的快速访问,因为一旦计算哈希,则它准确指代元素所放进的桶。
bool contains(const KeyType& key) { BucketIterator it = findBucketIterator(key); return it != buckets[hashFunction(key) % capacity].end(); } ValueType& operator[](const KeyType& key) { BucketIterator it = findBucketIterator(key); if (it != buckets[hashFunction(key) % capacity].end())...
Example Run this code #include <iostream>#include <unordered_map>intmain(){std::unordered_map<int,char>example{{1,'a'},{2,'b'}};for(intx:{2,5})if(example.contains(x))std::cout<<x<<": Found\n";elsestd::cout<<x<<": Not found\n";} ...
std::unordered_map<Key,T,Hash,KeyEqual,Allocator>::contains std::unordered_map<Key,T,Hash,KeyEqual,Allocator>::equal_range std::unordered_map<Key,T,Hash,KeyEqual,Allocator>::begin(size_type), std::unordered_map<Key,T,Hash,KeyEqual,Allocator>::cbegin(size_type) std::unordered_map<Key,...
unordered_map::contains (C++20) unordered_map::equal_range Bucket interface unordered_map::begin(size_type)unordered_map::cbegin(size_type) unordered_map::end(size_type)unordered_map::cend(size_type) unordered_map::bucket_count unordered_map::max_bucket_count ...
std::unordered_map template<classKey,// unordered_map::key_typeclassT,// unordered_map::mapped_typeclassHash= hash<Key>,// unordered_map::hasherclassPred = equal_to<Key>,// unordered_map::key_equalclassAlloc = allocator< pair<constKey,T> >// unordered_map::allocator_type>classunordered...
如C++的名著《The C++ Standard Library》中所述: “A map is a sorted associative container that contains key-value pairs with unique keys. Keys are sorted by using the comparison function Compare…The complexity for searching operations is logarithmic in the size of the containers.”(map是一个排...
contains (C++20) 检查容器是否含有带特定键的元素 (公开成员函数) equal_range 返回匹配特定键的元素范围 (公开成员函数) 桶接口 begin(size_type)cbegin(size_type) 返回一个迭代器,指向指定的桶的开始 (公开成员函数) end(size_type)cend(size_type) ...
contains (C++20) 检查容器是否含有带特定键的元素 (公开成员函数) equal_range 返回匹配特定键的元素范围 (公开成员函数) 桶接口 begin(size_type)cbegin(size_type) 返回指向指定的桶的开始的迭代器 (公开成员函数) end(size_type)cend(size_type)