BloombergLP::bdlc::FlatHashTable

This class template provides a flat hash table implementation useful for implementing a flat hash set and flat hash map.

Synopsis

Declared in <bdlc_flathashtable.h>

template<
    class KEY,
    class ENTRY,
    class ENTRY_UTIL,
    class HASH,
    class EQUAL>
class FlatHashTable;

Type Aliases

NameDescription
const_iterator Iterator over non-modifiable entries.
entry_type Entry type stored by this table.
entry_util_type Utility that extracts keys from entries.
hash_type Hash functor type.
iterator Iterator over modifiable entries.
key_equal_type Key equality predicate type.
key_type Key type of this table.

Member Functions

NameDescription
FlatHashTable [constructor]Constructors
~FlatHashTable [destructor]Destroy this object and each of its entries.
operator= Assignment operators
allocator Return the allocator used by this hash table to supply memory.
begin begin overloads
capacity Return the number of elements this table could hold if the load factor were 1.
cbegin Return an iterator representing the beginning of the sequence of entries held by this container.
cend Return an iterator one past the last entry in this table.
clear Remove all entries from this table. Note that this table will be empty after calling this method, but allocated memory may be retained for future use. See the capacity method.
contains Return true if this table contains an entry having the specified key, and false otherwise.
controls Return the address of the first element of the underlying array of control values in this table, or 0 if this table is in the zero-capacity state. An element of this array has the value FlatHashTable_GroupControl::k_EMPTY, FlatHashTable_GroupControl::k_ERASED, or a seven bit hashlet value for the in-use position (the highest-order bit is unset).
count Return the number of objects contained within this table having the specified key. Note that since a table maintains unique keys, the returned value will be either 0 or 1.
emplace Create an ENTRY object from the specified args, and attempt to add it to this flat hash table. Return a bsl::pair containing an iterator to the newly inserted object and true if the element was added. If an entry with the same key already exists in this flat hash table, return an iterator to that entry and false. This method requires that the ENTRY be copy-constructible.
empty Return true if this table contains no entries, and false otherwise.
end Return an iterator representing one past the end of the sequence of entries held by this container.
entries Return the address of the first element of the underlying array of entries in this table, or 0 if this table is in the zero-capacity state. The behavior is undefined unless the address is verified in-use through use of the controls array before dereferencing an entry in this array.
equal_range equal_range overloads
erase erase overloads
find find overloads
hash_function Return (a copy of) the unary hash functor used by this flat hash table to generate a hash value (of type bsl::size_t) for a KEY' object.
insert insert overloads
insertTransparent Insert the specified key into this table if a key equivalent to key does not already exist in this table; otherwise, this method has no effect. Return a pair whose first member is an iterator referring to the (possibly newly inserted) object in this table whose key is the equal to that of the object to be inserted, and whose second member is true if a new entry was inserted, and false if a entry having an equal key was already present. Bitwise movable types that are not bitwise copyable will be copied (to avoid confusion with regard to calling the entry destructor after this call).
key_eq Return (a copy of) the binary key-equality functor used by this flat hash table that returns true if two KEY objects are equal, and false otherwise.
load_factor Return the current ratio between the number of elements in this table and its capacity.
max_load_factor Return the maximum load factor allowed for this table. Note that if an insert operation would cause the load factor to exceed the max_load_factor, that same insert operation will increase the capacity and rehash the entries of the container (see insert and rehash). Note that the value returned by max_load_factor is implementation dependent and cannot be changed by the user.
operator[] If an entry with the specified key is not already present in this table, insert an entry having the value defined by ENTRY_UTIL::construct; otherwise, this method has no effect. Return an iterator referring to the (possibly newly inserted) object in this table with the key.
rehash Change the capacity of this table to at least the specified minimumCapacity, and redistribute all the contained elements into a new sequence of entries, according to their hash values. If 0 == minimumCapacity and 0 == size(), the table is returned to the zero-capacity state. On return, load_factor() is less than or equal to max_load_factor() and all iterators, pointers, and references to elements of this FlatHashTable are invalidated.
reserve Change the capacity of this table to at least a capacity that can accommodate the specified numEntries (accounting for the load factor invariant), and redistribute all the contained elements into a new sequence of entries, according to their hash values. If 0 == numEntries and 0 == size(), the table is returned to the zero-capacity state. After this call, load_factor() will be less than or equal to max_load_factor(). Note that this method is effectively equivalent to: ` rehash(bsl::ceil(numEntries / max_load_factor())) `
reset Remove all entries from this table and release all memory from this table, returning the table to the zero-capacity state.
size Return the number of entries in this table.
swap Efficiently exchange the value of this table with the value of the specified other table. This method provides the no-throw exception-safety guarantee. The behavior is undefined unless this array was created with the same allocator as other.
try_emplace try_emplace overloads

Static Data Members

NameDescription
k_HASHLET_MASK Mask extracting the 7-bit hashlet from a full hash value.
k_MAX_LOAD_FACTOR_DENOMINATOR Denominator of the maximum load-factor fraction (7/8).
k_MAX_LOAD_FACTOR_NUMERATOR Numerator of the maximum load-factor fraction (7/8).
k_MIN_CAPACITY Minimum non-zero table capacity (two control groups).

Non-Member Functions

NameDescription
operator!=Return true if the specified lhs and rhs objects do not have the same value, and false otherwise. Two FlatHashTable objects do not have the same value if they do not have the same number of entries, or that for some entry contained in lhs there is not a entry in rhs having the same value. Note that this method requires the (template parameter) type ENTRY to be equality-comparable.
operator==Return true if the specified lhs and rhs objects have the same value, and false otherwise. Two FlatHashTable objects have the same value if they have the same number of entries, and for each entry that is contained in lhs there is a entry contained in rhs having the same value. Note that this method requires the (template parameter) type ENTRY to be equality-comparable.
swapExchange the values of the specified a and b objects. This function provides the no-throw exception-safety guarantee if the two objects were created with the same allocator and the basic guarantee otherwise.