Destroys the element pointed to by p, and removes it from a. a.size() is decremented by 1.
Erase range a.erase(p, q) [p, q) is a valid range in a. Destroys the elements in the range [p,q) and removes them from a. a.size() is decremented by the distance from i to j.
Find a.find(k) Returns an iterator pointing to an element whose key is the same as k, or a.end() if no such element exists. Either the return value is a.end(), or else the return value has a key that is the same as k.
Count a.count(k) Returns the number of elements in a whose keys are the same as k.
Equal range a.equal_range(k) Returns a pair P such that [P.first, P.second) is a range containing all elements in a whose keys are the same as k. [3] If no elements have the same key as k , the return value is an empty range. The distance between P.first and P.second is equal to a.count(k). If p is a dereferenceable iterator in a, then either a lies in the range [P.first, P.second), or else *a has a key that is not the same as k.
Bucket count a.bucket_count() Returns the number of buckets in a.
Resize a.resize(n) Increases the bucket count of a. The bucket count of a will be at least n. All iterators pointing to element in a will remain valid. [3]
Complexity guarantees

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 O(count(k)). Worst case is linear in the size of the container.

Erase Element is amortized constant time.

Average complexity for Erase Range is O(N), where N is the length of the range being erased. Worse case is linear in the size of the container.

Average complexity for Find is constant time. Worst case is linear in the size of the container.

Average complexity for Equal Range is O(count(k)). Worst case is linear in the size of the container.

Average complexity for Count is O(count(k)). Worst case is linear in the size of the container.

Bucket Count is amortized constant time.

Resize is linear in the size of the container.

Models

• hash_set

• hash_map

• hash_multiset

• hash_multimap

Notes

[1] There is an extensive literature dealing with hash tables. See, for example, section 6.4 of Knuth. (D. E. Knuth, The Art of Computer Programming. Volume 3: Sorting and Searching. Addison- Wesley, 1975.)

[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 i and j are iterators that point into a Hashed Associative Container such that i comes immediately before j, then there is no guarantee that i will still come immediately before j after the container is resized. The only guarantee about about the ordering of elements is the contiguous storage invariant: elements with the same key are always adjacent to each other.

See also

Associative Container, Sorted Associative Container, Unique Hashed Associative Container, Multiple Hashed Associative Container

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату