[#BloombergLP-bdlc-FlatHashSet] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlc.adoc[bdlc]::FlatHashSet :relfileprefix: ../../ :mrdocs: This class template implements a value‐semantic container type holding an unordered set of unique values of (template parameter) type `KEY`. The (template parameter) type `HASH` is a functor providing the hash value for `KEY`. The (template parameter) type `EQUAL` is a functor providing the equality function for two `KEY` values. See {Requirements on `KEY`, `HASH`, and `EQUAL`} for more information. == Synopsis Declared in `<bdlc_flathashset.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< class KEY, class HASH = xref:BloombergLP/bslh/FibonacciBadHashWrapper.adoc[bslh::FibonacciBadHashWrapper<bsl::hash<KEY>>], class EQUAL = xref:bsl/equal_to-0d.adoc[bsl::equal_to<KEY>]> class FlatHashSet; ---- == Type Aliases [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlc/FlatHashSet/const_iterator.adoc[`const_iterator`] | Const iterator over elements. | xref:BloombergLP/bdlc/FlatHashSet/const_pointer.adoc[`const_pointer`] | Pointer to a non‐modifiable value. | xref:BloombergLP/bdlc/FlatHashSet/const_reference.adoc[`const_reference`] | Reference to a non‐modifiable value. | xref:BloombergLP/bdlc/FlatHashSet/difference_type.adoc[`difference_type`] | Signed type used for iterator distances. | xref:BloombergLP/bdlc/FlatHashSet/hasher.adoc[`hasher`] | Hash functor type. | xref:BloombergLP/bdlc/FlatHashSet/iterator.adoc[`iterator`] | Iterator over elements (const, since set values are immutable). | xref:BloombergLP/bdlc/FlatHashSet/key_compare.adoc[`key_compare`] | Key equality predicate type. | xref:BloombergLP/bdlc/FlatHashSet/key_type.adoc[`key_type`] | Key type of this set (also the element type). | xref:BloombergLP/bdlc/FlatHashSet/pointer.adoc[`pointer`] | Pointer to a modifiable value. | xref:BloombergLP/bdlc/FlatHashSet/reference.adoc[`reference`] | Reference to a modifiable value. | xref:BloombergLP/bdlc/FlatHashSet/size_type.adoc[`size_type`] | Unsigned type used for sizes and capacities. | xref:BloombergLP/bdlc/FlatHashSet/value_compare.adoc[`value_compare`] | Value equality predicate type (same as `key_compare`). | xref:BloombergLP/bdlc/FlatHashSet/value_type.adoc[`value_type`] | Element type stored by this set. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlc/FlatHashSet/2constructor-0a.adoc[`FlatHashSet`] [.small]#[constructor]# | Constructors | xref:BloombergLP/bdlc/FlatHashSet/2destructor.adoc[`~FlatHashSet`] [.small]#[destructor]# | Destroy this object and each of its elements. | xref:BloombergLP/bdlc/FlatHashSet/operator_assign-003.adoc[`operator=`] | Assignment operators | xref:BloombergLP/bdlc/FlatHashSet/allocator.adoc[`allocator`] | Return the allocator used by this flat hash set to supply memory. | xref:BloombergLP/bdlc/FlatHashSet/begin.adoc[`begin`] | Return a `const_iterator` to the first element in the sequence of elements maintained by this set, or the `end` iterator if this set is empty. | xref:BloombergLP/bdlc/FlatHashSet/capacity.adoc[`capacity`] | Return the number of elements this set could hold if the load factor were 1. | xref:BloombergLP/bdlc/FlatHashSet/cbegin.adoc[`cbegin`] | Return a `const_iterator` to the first element in the sequence of elements maintained by this set, or the `end` iterator if this set is empty. | xref:BloombergLP/bdlc/FlatHashSet/cend.adoc[`cend`] | Return a `const_iterator` to the past‐the‐end element in the sequence of `KEY` elements maintained by this set. | xref:BloombergLP/bdlc/FlatHashSet/clear.adoc[`clear`] | Remove all elements from this set. Note that this set will be empty after calling this method, but allocated memory may be retained for future use. See the `capacity` method. | xref:BloombergLP/bdlc/FlatHashSet/contains-03.adoc[`contains`] | `contains` overloads | xref:BloombergLP/bdlc/FlatHashSet/count-00.adoc[`count`] | `count` overloads | xref:BloombergLP/bdlc/FlatHashSet/emplace.adoc[`emplace`] | Insert into this set a newly created `value_type` object, constructed by forwarding `get_allocator()` (if required) and the specified (variable number of) `args` to the corresponding constructor of `value_type`, if a key equivalent to such a value does not already exist in this set; otherwise, this method has no effect (other than possibly creating a temporary `value_type` object). Return a pair whose `first` member is an iterator referring to the (possibly newly created and inserted) object in this set whose value is equivalent to that of an object constructed from `arguments`, and whose `second` member is `true` if a new value was inserted, and `false` if an equivalent key was already present. | xref:BloombergLP/bdlc/FlatHashSet/emplace_hint.adoc[`emplace_hint`] | Insert into this set a newly created `value_type` object, constructed by forwarding `get_allocator()` (if required) and the specified (variable number of) `args` to the corresponding constructor of `value_type`, if a key equivalent to such a value does not already exists in this set; otherwise, this method has no effect (other than possibly creating a temporary `value_type` object). Return an iterator referring to the (possibly newly created and inserted) object in this set whose value is equivalent to that of an object constructed from `arguments`. The average and worst case complexity of this operation is not affected by the specified `hint`. Note that `hint` is ignored (other than possibly asserting its validity in some build modes). | xref:BloombergLP/bdlc/FlatHashSet/empty.adoc[`empty`] | Return `true` if this set contains no elements, and `false` otherwise. | xref:BloombergLP/bdlc/FlatHashSet/end.adoc[`end`] | Return a `const_iterator` to the past‐the‐end element in the sequence of `KEY` elements maintained by this set. | xref:BloombergLP/bdlc/FlatHashSet/equal_range-0f.adoc[`equal_range`] | `equal_range` overloads | xref:BloombergLP/bdlc/FlatHashSet/erase-05.adoc[`erase`] | `erase` overloads | xref:BloombergLP/bdlc/FlatHashSet/find-08.adoc[`find`] | Return a `const_iterator` referring to the element in this set having the specified `key`, or `end()` if no such entry exists in this set. | xref:BloombergLP/bdlc/FlatHashSet/hash_function.adoc[`hash_function`] | Return (a copy of) the unary hash functor used by this set to generate a hash value (of type `bsl::size_t`) for a `KEY` object. | xref:BloombergLP/bdlc/FlatHashSet/insert-0c.adoc[`insert`] | `insert` overloads | xref:BloombergLP/bdlc/FlatHashSet/key_eq.adoc[`key_eq`] | Return (a copy of) the binary key‐equality functor that returns `true` if the value of two `KEY` objects are equivalent, and `false` otherwise. | xref:BloombergLP/bdlc/FlatHashSet/load_factor.adoc[`load_factor`] | Return the current ratio between the number of elements in this container and its capacity. | xref:BloombergLP/bdlc/FlatHashSet/max_load_factor.adoc[`max_load_factor`] | Return the maximum load factor allowed for this set. Note that if an insert operation would cause the load factor to exceed `max_load_factor()`, that same insert operation will increase the capacity and rehash the entries of the container (see {Load Factor and Resizing}). Also note that the value returned by `max_load_factor` is implementation defined and cannot be changed by the user. | xref:BloombergLP/bdlc/FlatHashSet/print.adoc[`print`] | Format this object to the specified output `stream` at the (absolute value of) the optionally specified indentation `level`, and return a reference to the modifiable `stream`. If `level` is specified, optionally specify `spacesPerLevel`, the number of spaces per indentation level for this and all of its nested objects. If `level` is negative, suppress indentation of the first line. If `spacesPerLevel` is negative, format the entire output on one line, suppressing all but the initial indentation (as governed by `level`). If `stream` is not valid on entry, this operation has no effect. | xref:BloombergLP/bdlc/FlatHashSet/rehash.adoc[`rehash`] | Change the capacity of this set 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 set is returned to the default constructed state. After this call, `load_factor()` will be less than or equal to `max_load_factor()` and all iterators, pointers, and references to elements of this set are invalidated. | xref:BloombergLP/bdlc/FlatHashSet/reserve.adoc[`reserve`] | Change the capacity of this set 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 set is returned to the default constructed state. After this call, `load_factor()` will be less than or equal to `max_load_factor()` and all iterators, pointers, and references to elements of this set are invalidated. Note that this method is effectively equivalent to: ` rehash(bsl::ceil(numEntries / max_load_factor())) ` | xref:BloombergLP/bdlc/FlatHashSet/reset.adoc[`reset`] | Remove all elements from this set and release all memory from this set, returning the set to the default constructed state. | xref:BloombergLP/bdlc/FlatHashSet/size.adoc[`size`] | Return the number of elements in this set. | xref:BloombergLP/bdlc/FlatHashSet/swap.adoc[`swap`] | Exchange the value of this object as well as its hasher and equality functors with those of the specified `other` object. The behavior is undefined unless this object was created with the same allocator as `other`. |=== == Friends [cols="1,4"] |=== | Name| Description | `xref:BloombergLP/bdlc/swap-060.adoc[BloombergLP::bdlc::swap]` | Exchange the contents of the two sets. | `xref:BloombergLP/bdlc/operator_not_eq-0473.adoc[BloombergLP::bdlc::operator!=]` | Return whether the sets differ in contents. | `xref:BloombergLP/bdlc/operator_eq-096.adoc[BloombergLP::bdlc::operator==]` | Return whether the sets have the same contents. |=== == Non-Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlc/operator_not_eq-01f.adoc[`operator!=`] | Return `true` if the specified `lhs` and `rhs` objects do not have the same value, and `false` otherwise. Two `FlatHashSet` objects do not have the same value if their sizes are different or one contains an element equal to no element of the other. The hash and equality functors are not involved in the comparison. | xref:BloombergLP/bdlc/operator_eq-042.adoc[`operator==`] | Return `true` if the specified `lhs` and `rhs` objects have the same value, and `false` otherwise. Two `FlatHashSet` objects have the same value if their sizes are the same and each element contained in one is equal to an element of the other. The hash and equality functors are not involved in the comparison. | xref:BloombergLP/bdlc/swap-0b8.adoc[`swap`] | Exchange the value, the hasher, and the key‐equality functor 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]#