BloombergLP::bslstl::HashTable

Value-semantic unordered container of keyed elements.

Synopsis

Declared in <bslstl_hashtable.h>

template<
    class KEY_CONFIG,
    class HASHER,
    class COMPARATOR,
    class ALLOCATOR = bsl::allocator<KEY_CONFIG::ValueType>>
class HashTable;

Description

This class template implements a value-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. The value type and key type of the elements maintained by a HashTable are determined by aliases provided through the (template parameter) type KEY_CONFIG. Elements in a HashTable are stored in "nodes" 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++11 standard under the allocator-aware container requirements in ([container.requirements.general], C++11 23.2.1). The (template parameter) types HASHER and COMPARATOR shall be copy-constructible function-objects. HASHER shall support a function call operator compatible with the following statements: ` HASHER hash; KEY_CONFIG::KeyType key; std::size_t result = hash(key); ` where the definition of the called function meets the requirements of a hash function, as specified in {bslstl_hash}. COMPARATOR shall support the a function call operator compatible with the following statements: ` COMPARATOR compare; KEY_CONFIG::KeyType key1, key2; bool result = compare(key1, key2); ` where the definition of the called function defines an equivalence relationship on keys that is both reflexive and transitive. 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.

This class: * supports a complete set of value-semantic operations

  • except for bdex serialization * is exception-neutral (agnostic except for the at method) * is alias-safe * is const thread-safe For terminology see {bsldoc_glossary}.

Type Aliases

NameDescription
AllocatorTraits This typedef is an alias to bsl::allocator_traits<AllocatorType>.
AllocatorType This typedef is an alias to the (template parameter) ALLOCATOR.
KeyType This typedef is an alias to KEY_CONFIG::KeyType.
NodeType Node type stored in the hash table.
NonConstKeyType This typedef is an alias to the non-const form of KeyType.
SizeType This typedef is an alias to AllocatorTraits::size_type.
ValueType Alias to the ValueType defined in the (template parameter) KEY_CONFIG.

Member Functions

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

Non-Member Functions

NameDescription
operator!=Return true if lhs and rhs do not have the same value.
operator==Return true if lhs and rhs have the same value.
swapExchange the value and policies of x with those of y.