[#BloombergLP-bdlc-FlatHashTable] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlc.adoc[bdlc]::FlatHashTable :relfileprefix: ../../ :mrdocs: 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>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< class KEY, class ENTRY, class ENTRY_UTIL, class HASH, class EQUAL> class FlatHashTable; ---- == Type Aliases [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlc/FlatHashTable/const_iterator.adoc[`const_iterator`] | Iterator over non‐modifiable entries. | xref:BloombergLP/bdlc/FlatHashTable/entry_type.adoc[`entry_type`] | Entry type stored by this table. | xref:BloombergLP/bdlc/FlatHashTable/entry_util_type.adoc[`entry_util_type`] | Utility that extracts keys from entries. | xref:BloombergLP/bdlc/FlatHashTable/hash_type.adoc[`hash_type`] | Hash functor type. | xref:BloombergLP/bdlc/FlatHashTable/iterator.adoc[`iterator`] | Iterator over modifiable entries. | xref:BloombergLP/bdlc/FlatHashTable/key_equal_type.adoc[`key_equal_type`] | Key equality predicate type. | xref:BloombergLP/bdlc/FlatHashTable/key_type.adoc[`key_type`] | Key type of this table. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlc/FlatHashTable/2constructor-0f.adoc[`FlatHashTable`] [.small]#[constructor]# | Constructors | xref:BloombergLP/bdlc/FlatHashTable/2destructor.adoc[`~FlatHashTable`] [.small]#[destructor]# | Destroy this object and each of its entries. | xref:BloombergLP/bdlc/FlatHashTable/operator_assign-00.adoc[`operator=`] | Assignment operators | xref:BloombergLP/bdlc/FlatHashTable/allocator.adoc[`allocator`] | Return the allocator used by this hash table to supply memory. | xref:BloombergLP/bdlc/FlatHashTable/begin-05.adoc[`begin`] | `begin` overloads | xref:BloombergLP/bdlc/FlatHashTable/capacity.adoc[`capacity`] | Return the number of elements this table could hold if the load factor were 1. | xref:BloombergLP/bdlc/FlatHashTable/cbegin.adoc[`cbegin`] | Return an iterator representing the beginning of the sequence of entries held by this container. | xref:BloombergLP/bdlc/FlatHashTable/cend.adoc[`cend`] | Return an iterator one past the last entry in this table. | xref:BloombergLP/bdlc/FlatHashTable/clear.adoc[`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. | xref:BloombergLP/bdlc/FlatHashTable/contains.adoc[`contains`] | Return `true` if this table contains an entry having the specified `key`, and `false` otherwise. | xref:BloombergLP/bdlc/FlatHashTable/controls.adoc[`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). | xref:BloombergLP/bdlc/FlatHashTable/count.adoc[`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. | xref:BloombergLP/bdlc/FlatHashTable/emplace.adoc[`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`. | xref:BloombergLP/bdlc/FlatHashTable/empty.adoc[`empty`] | Return `true` if this table contains no entries, and `false` otherwise. | xref:BloombergLP/bdlc/FlatHashTable/end-07.adoc[`end`] | Return an iterator representing one past the end of the sequence of entries held by this container. | xref:BloombergLP/bdlc/FlatHashTable/entries.adoc[`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. | xref:BloombergLP/bdlc/FlatHashTable/equal_range-07.adoc[`equal_range`] | `equal_range` overloads | xref:BloombergLP/bdlc/FlatHashTable/erase-03.adoc[`erase`] | `erase` overloads | xref:BloombergLP/bdlc/FlatHashTable/find-082.adoc[`find`] | `find` overloads | xref:BloombergLP/bdlc/FlatHashTable/hash_function.adoc[`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. | xref:BloombergLP/bdlc/FlatHashTable/insert-0e.adoc[`insert`] | `insert` overloads | xref:BloombergLP/bdlc/FlatHashTable/insertTransparent.adoc[`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). | xref:BloombergLP/bdlc/FlatHashTable/key_eq.adoc[`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. | xref:BloombergLP/bdlc/FlatHashTable/load_factor.adoc[`load_factor`] | Return the current ratio between the number of elements in this table and its capacity. | xref:BloombergLP/bdlc/FlatHashTable/max_load_factor.adoc[`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. | xref:BloombergLP/bdlc/FlatHashTable/operator_subs.adoc[`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`. | xref:BloombergLP/bdlc/FlatHashTable/rehash.adoc[`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. | xref:BloombergLP/bdlc/FlatHashTable/reserve.adoc[`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())) ` | xref:BloombergLP/bdlc/FlatHashTable/reset.adoc[`reset`] | Remove all entries from this table and release all memory from this table, returning the table to the zero‐capacity state. | xref:BloombergLP/bdlc/FlatHashTable/size.adoc[`size`] | Return the number of entries in this table. | xref:BloombergLP/bdlc/FlatHashTable/swap.adoc[`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`. | xref:BloombergLP/bdlc/FlatHashTable/try_emplace-0b.adoc[`try_emplace`] | `try_emplace` overloads |=== == Static Data Members [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlc/FlatHashTable/k_HASHLET_MASK.adoc[`k_HASHLET_MASK`] | Mask extracting the 7‐bit hashlet from a full hash value. | xref:BloombergLP/bdlc/FlatHashTable/k_MAX_LOAD_FACTOR_DENOMINATOR.adoc[`k_MAX_LOAD_FACTOR_DENOMINATOR`] | Denominator of the maximum load‐factor fraction (7/8). | xref:BloombergLP/bdlc/FlatHashTable/k_MAX_LOAD_FACTOR_NUMERATOR.adoc[`k_MAX_LOAD_FACTOR_NUMERATOR`] | Numerator of the maximum load‐factor fraction (7/8). | xref:BloombergLP/bdlc/FlatHashTable/k_MIN_CAPACITY.adoc[`k_MIN_CAPACITY`] | Minimum non‐zero table capacity (two control groups). |=== == Non-Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlc/operator_not_eq-0be.adoc[`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. | xref:BloombergLP/bdlc/operator_eq-0d5.adoc[`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. | xref:BloombergLP/bdlc/swap-0b6.adoc[`swap`] | Exchange 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. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#