Destroys the element pointed to by | ||||
Erase range | a.erase(p, q) | Destroys the elements in the range | ||
Find | a.find(k) | Returns an iterator pointing to an element whose key is the same as | Either the return value is | |
Count | a.count(k) | Returns the number of elements in | ||
Equal range | a.equal_range(k) | Returns a pair | The distance between | |
Bucket count | a.bucket_count() | Returns the number of buckets in | ||
Resize | a.resize(n) | Increases the bucket count of | The bucket count of |
The default constructor, constructor with bucket count, constructor with hash function, and constructor with key equal, are all amortized constant time.
Hash Function and Key Equal are amortized constant time.
Average complexity for Erase Key is
Erase Element is amortized constant time.
Average complexity for Erase Range is
Average complexity for Find is constant time. Worst case is linear in the size of the container.
Average complexity for Equal Range is
Average complexity for Count is
Bucket Count is amortized constant time.
Resize is linear in the size of the container.
• hash_set
• hash_map
• hash_multiset
• hash_multimap
[1] There is an extensive literature dealing with hash tables. See, for example, section 6.4 of Knuth. (D. E. Knuth,
[2] If the hash function is poor (that is, if many different keys hash to the same value) then this will hurt performance. The worst case is where every key hashes to the same value; in this case, run-time complexity of most Hashed Associative Container operations will be linear in the size of the container.
[3] Resizing does not invalidate iterators; however, it does not necessarily preserve the ordering relation between iterators. That is, if
Associative Container, Sorted Associative Container, Unique Hashed Associative Container, Multiple Hashed Associative Container