Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does std::unordered_multimap's bucket only contain elements with equivalent keys

On www.CPlusPlus.com, it states the following for unordered_multimap,

Elements with equivalent keys are grouped together in the same bucket and in such a way that an iterator (see equal_range) can iterate through all of them.

I know we cannot infer this from that statement, but I'd like to know if a given bucket only contains elements with the equivalent keys?

like image 848
lancery Avatar asked Oct 24 '25 14:10

lancery


1 Answers

Here are the only pertinent requirements:

[C++11: 23.2.5/5]: Two values k1 and k2 of type Key are considered equivalent if the container’s key_equal function object returns true when passed those values. If k1 and k2 are equivalent, the hash function shall return the same value for both. [..]

[C++11: 23.2.5/8]: The elements of an unordered associative container are organized into buckets. Keys with the same hash code appear in the same bucket. [..]

There is nothing prohibiting all elements with key hash a and all elements with key hash b from being stored in the same bucket. It is up to the standard library implementation that you use as to whether or not this fact is used.

No standard wording exists to make this explicit; it's defined by omission.

like image 121
Lightness Races in Orbit Avatar answered Oct 27 '25 02:10

Lightness Races in Orbit