- Unordered map
unordered_map
is the proposedC++ TR1 name for ahash table , accessible asstd::tr1::unordered_map
.unordered_map
works very similarly to the existingmap
class in the C++ STL. It will replace the various incompatible implementations of the hash table (calledhash_map
by GCC and MSVC).Until TR1 is officially accepted into the upcoming
C++0x standard,unordered_map
is available from theheader file , and from
in MSVC [ [http://msdn.microsoft.com/en-us/library/bb983026.aspxAs its name implies, unlike the
map
class, the elements of anunordered_map
are not ordered. This is due to the use of hashing to store objects.unordered_map
can still be iterated through like a regular map.It is closely related to
unordered_multimap
(available in the same header file), which is an implementation ofmultimap using hashing. It is also similar tounordered_set
andunordered_multiset
, implementations of theset andmultiset containers respectively and available in the
or
headers.unordered_map
takes at least two and at most five template parameters, called Key, Data, Hash (or Hasher), Compare and Alloc.unordered_map
will associate elements of type Key to elements of type Data; keys are unique in the map (for duplicate keys,unordered_multimap
is used). Hash is ahash function which takes elements of type Key and produces an integer. Compare is a function which compares two keys for equality: this is needed for custom data types to resolvehash collisions , which occur when two elements hash to the same value but are actually different. Finally, Alloc is a function which allocates new elements.References
Wikimedia Foundation. 2010.