[#BloombergLP-bslstl-HashTable]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslstl.adoc[bslstl]::HashTable
:relfileprefix: ../../
:mrdocs:

Value&hyphen;semantic unordered container of keyed elements&period;

== Synopsis

Declared in `&lt;bslstl&lowbar;hashtable&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class KEY&lowbar;CONFIG,
    class HASHER,
    class COMPARATOR,
    class ALLOCATOR = xref:bsl/allocator-0df.adoc[bsl::allocator&lt;KEY&lowbar;CONFIG::ValueType&gt;]&gt;
class HashTable;
----

== Description

This class template implements a value&hyphen;semantic container type holding an unordered sequence of (possibly duplicate) elements, that can be rapidly accessed using their key, with the constraint on the container that elements whose keys compare equal according to the specified `COMPARATOR` will be stored in a stable, contiguous sequence within the container&period; The value type and key type of the elements maintained by a `HashTable` are determined by aliases provided through the (template parameter) type `KEY&lowbar;CONFIG`&period; Elements in a `HashTable` are stored in &quot;nodes&quot; that are allocated using an allocator of the specified `ALLOCATOR` type (rebound to the node type), and elements are constructed directly in the node using the allocator as described in the C&plus;&plus;11 standard under the allocator&hyphen;aware container requirements in (&lsqb;container&period;requirements&period;general&rsqb;, C&plus;&plus;11 23&period;2&period;1)&period; The (template parameter) types `HASHER` and `COMPARATOR` shall be `copy&hyphen;constructible` function&hyphen;objects&period; `HASHER` shall support a function call operator compatible with the following statements&colon; &grave; HASHER hash&semi; KEY&lowbar;CONFIG&colon;&colon;KeyType key&semi; std&colon;&colon;size&lowbar;t result &equals; hash(key)&semi; &grave; where the definition of the called function meets the requirements of a hash function, as specified in &lcub;`bslstl&lowbar;hash`&rcub;&period; `COMPARATOR` shall support the a function call operator compatible with the following statements&colon; &grave; COMPARATOR compare&semi; KEY&lowbar;CONFIG&colon;&colon;KeyType key1, key2&semi; bool result &equals; compare(key1, key2)&semi; &grave; where the definition of the called function defines an equivalence relationship on keys that is both reflexive and transitive&period; The `HASHER` and `COMPARATOR` attributes of this class are further constrained, such for any two objects whose keys compare equal by the comparator, shall produce the same value from the hasher&period;

This class&colon; &ast; supports a complete set of _value&hyphen;semantic_ operations

* except for `bdex` serialization &ast; is _exception&hyphen;neutral_ (agnostic except for the `at` method) &ast; is _alias&hyphen;safe_ &ast; is `const` _thread&hyphen;safe_ For terminology see &lcub;`bsldoc&lowbar;glossary`&rcub;&period;

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslstl/HashTable/AllocatorTraits.adoc[`AllocatorTraits`] 
| This `typedef` is an alias to `bsl&colon;&colon;allocator&lowbar;traits&lt;AllocatorType&gt;`&period;
| xref:BloombergLP/bslstl/HashTable/AllocatorType.adoc[`AllocatorType`] 
| This `typedef` is an alias to the (template parameter) `ALLOCATOR`&period;
| xref:BloombergLP/bslstl/HashTable/KeyType.adoc[`KeyType`] 
| This `typedef` is an alias to `KEY&lowbar;CONFIG&colon;&colon;KeyType`&period;
| xref:BloombergLP/bslstl/HashTable/NodeType.adoc[`NodeType`] 
| Node type stored in the hash table&period;
| xref:BloombergLP/bslstl/HashTable/NonConstKeyType.adoc[`NonConstKeyType`] 
| This `typedef` is an alias to the non&hyphen;`const` form of `KeyType`&period;
| xref:BloombergLP/bslstl/HashTable/SizeType.adoc[`SizeType`] 
| This `typedef` is an alias to `AllocatorTraits&colon;&colon;size&lowbar;type`&period;
| xref:BloombergLP/bslstl/HashTable/ValueType.adoc[`ValueType`] 
| Alias to the `ValueType` defined in the (template parameter) `KEY&lowbar;CONFIG`&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslstl/HashTable/2constructor-03.adoc[`HashTable`]         [.small]#[constructor]#
| Constructors
| xref:BloombergLP/bslstl/HashTable/2destructor.adoc[`&#126;HashTable`] [.small]#[destructor]#
| Destroy this object&period;
| xref:BloombergLP/bslstl/HashTable/operator_assign-02.adoc[`operator&equals;`] 
| Assignment operators
| xref:BloombergLP/bslstl/HashTable/allocator.adoc[`allocator`] 
| Return a copy of the allocator used to construct this hash table&period;
| xref:BloombergLP/bslstl/HashTable/bucketAtIndex.adoc[`bucketAtIndex`] 
| Return a reference to the bucket at the specified `index`&period;
| xref:BloombergLP/bslstl/HashTable/bucketIndexForKey-0b.adoc[`bucketIndexForKey`] 
| `bucketIndexForKey` overloads
| xref:BloombergLP/bslstl/HashTable/comparator.adoc[`comparator`] 
| Return a reference providing non&hyphen;modifiable access to the key&hyphen;equality comparison functor used by this hash table&period;
| xref:BloombergLP/bslstl/HashTable/countElementsInBucket.adoc[`countElementsInBucket`] 
| Return the number of elements in the bucket at `index`&period;
| xref:BloombergLP/bslstl/HashTable/elementListRoot.adoc[`elementListRoot`] 
| Return the address of the first element in this hash table, or a null pointer value if this hash table is empty&period;
| xref:BloombergLP/bslstl/HashTable/emplace.adoc[`emplace`] 
| Emplace a newly constructed value into this hash table&period;
| xref:BloombergLP/bslstl/HashTable/emplaceIfMissing.adoc[`emplaceIfMissing`] 
| Emplace a value if no equivalent key is present&period;
| xref:BloombergLP/bslstl/HashTable/emplaceWithHint.adoc[`emplaceWithHint`] 
| Emplace a value, optionally inserted near `hint`&period;
| xref:BloombergLP/bslstl/HashTable/find-0e.adoc[`find`] 
| `find` overloads
| xref:BloombergLP/bslstl/HashTable/findEndOfRange.adoc[`findEndOfRange`] 
| Return the address of the first node after the key&hyphen;equivalent range&period;
| xref:BloombergLP/bslstl/HashTable/findRange-09.adoc[`findRange`] 
| `findRange` overloads
| xref:BloombergLP/bslstl/HashTable/hasSameValue.adoc[`hasSameValue`] 
| Return `true` if `other` has the same value as this object&period;
| xref:BloombergLP/bslstl/HashTable/hasher.adoc[`hasher`] 
| Return a reference providing non&hyphen;modifiable access to the hash functor used by this hash&hyphen;table&period;
| xref:BloombergLP/bslstl/HashTable/insert-08.adoc[`insert`] 
| `insert` overloads
| xref:BloombergLP/bslstl/HashTable/insertIfMissing-00d.adoc[`insertIfMissing`] 
| `insertIfMissing` overloads
| xref:BloombergLP/bslstl/HashTable/insertIfMissingTransparent.adoc[`insertIfMissingTransparent`] 
| Insert a value from `value` if no equivalent key is present&period;
| xref:BloombergLP/bslstl/HashTable/insertOrAssign.adoc[`insertOrAssign`] 
| Insert or assign a mapped value for `key`&period;
| xref:BloombergLP/bslstl/HashTable/insertOrAssignTransparent.adoc[`insertOrAssignTransparent`] 
| Insert or assign a mapped value for a transparent `key`&period;
| xref:BloombergLP/bslstl/HashTable/loadFactor.adoc[`loadFactor`] 
| Return the current load factor for this table&period; The load factor is the statistical mean number of elements per bucket&period;
| xref:BloombergLP/bslstl/HashTable/maxLoadFactor.adoc[`maxLoadFactor`] 
| Return the maximum load factor permitted by this hash table&period;
| xref:BloombergLP/bslstl/HashTable/maxNumBuckets.adoc[`maxNumBuckets`] 
| Return a theoretical upper bound on the number of buckets&period;
| xref:BloombergLP/bslstl/HashTable/maxSize.adoc[`maxSize`] 
| Return a theoretical upper bound on the number of elements&period;
| xref:BloombergLP/bslstl/HashTable/numBuckets.adoc[`numBuckets`] 
| Return the number of buckets contained in this hash table&period;
| xref:BloombergLP/bslstl/HashTable/rehashForNumBuckets.adoc[`rehashForNumBuckets`] 
| Re&hyphen;organize to have at least `newNumBuckets` buckets&period;
| xref:BloombergLP/bslstl/HashTable/rehashThreshold.adoc[`rehashThreshold`] 
| Return the number of elements this hash table can hold without requiring a rehash operation in order to respect the `maxLoadFactor`&period;
| xref:BloombergLP/bslstl/HashTable/remove.adoc[`remove`] 
| Remove `node` from this hash table and return the following node&period;
| xref:BloombergLP/bslstl/HashTable/removeAll.adoc[`removeAll`] 
| Remove all elements from this hash table&period;
| xref:BloombergLP/bslstl/HashTable/reserveForNumElements.adoc[`reserveForNumElements`] 
| Reserve capacity for at least `numElements` without exceeding max load&period;
| xref:BloombergLP/bslstl/HashTable/setMaxLoadFactor.adoc[`setMaxLoadFactor`] 
| Set the maximum load factor permitted by this hash table&period;
| xref:BloombergLP/bslstl/HashTable/size.adoc[`size`] 
| Return the number of elements in this hash table&period;
| xref:BloombergLP/bslstl/HashTable/swap.adoc[`swap`] 
| Exchange this object&apos;s value and policies with those of `other`&period;
| xref:BloombergLP/bslstl/HashTable/tryEmplace-02.adoc[`tryEmplace`] 
| `tryEmplace` overloads
|===


== Non-Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslstl/operator_not_eq-065.adoc[`operator!&equals;`]
| Return `true` if `lhs` and `rhs` do not have the same value&period;
| xref:BloombergLP/bslstl/operator_eq-0f.adoc[`operator&equals;&equals;`]
| Return `true` if `lhs` and `rhs` have the same value&period;
| xref:BloombergLP/bslstl/swap-0e8.adoc[`swap`]
| Exchange the value and policies of `x` with those of `y`&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
