This class template implements a value‐semantic container type holding an unordered map of KEY‐VALUE pairs having unique keys that provides a mapping from keys of (template parameter) type KEY to their associated mapped values of (template parameter) type VALUE. 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_flathashmap.h>

template<
    class KEY,
    class VALUE,
    class HASH = bslh::FibonacciBadHashWrapper<bsl::hash<KEY>>,
    class EQUAL = bsl::equal_to<KEY>>
class FlatHashMap;

Type Aliases

Name

Description

const_iterator

Iterator over non‐modifiable elements.

const_pointer

Pointer to a non‐modifiable value.

const_reference

Reference to a non‐modifiable value.

difference_type

Signed type used for iterator distances.

hasher

Hash functor type.

iterator

Iterator over modifiable elements.

key_compare

Key equality predicate type.

key_type

Key type of this map.

mapped_type

Mapped value type of this map.

pointer

Pointer to a modifiable value.

reference

Reference to a modifiable value.

size_type

Unsigned type used for sizes and capacities.

value_type

Key/value pair type stored by this map.

Member Functions

Name

Description

FlatHashMap [constructor]

Constructors

~FlatHashMap [destructor]

Destroy this object and each of its elements.

operator=

Assignment operators

allocator

Return the allocator used by this flat hash map to supply memory.

at

at overloads

begin

begin overloads

capacity

Return the number of elements this map could hold if the load factor were 1.

cbegin

Return a const_iterator to the first element in the sequence of elements maintained by this map, or the end iterator if this map is empty.

cend

Return a const_iterator to the past‐the‐end element in the sequence of elements maintained by this map.

clear

Remove all elements from this map. Note that this map will be empty after calling this method, but allocated memory may be retained for future use. See the capacity method.

contains

contains overloads

count

count overloads

emplace

Insert into this map 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 map; 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 map whose key is equivalent to that of an object constructed from args, and whose second member is true if a new value was inserted, and false if an equivalent key was already present. This method requires that the (template parameter) types KEY and VALUE both be emplace‐constructible from args (see {Requirements on value_type}).

emplace_hint

Insert into this map 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 map; 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 map whose key is equivalent to that of an object constructed from args. The average and worst case complexity of this operation is not affected by the specified hint. This method requires that the (template parameter) types KEY and VALUE both be emplace‐constructible from args (see {Requirements on value_type}). The behavior is undefined unless hint is an iterator in the range [begin() .. end()] (both endpoints included). Note that hint is ignored (other than possibly asserting its validity in some build modes).

empty

Return true if this map contains no elements, and false otherwise.

end

end overloads

equal_range

equal_range overloads

erase

erase overloads

find

find overloads

hash_function

Return (a copy of) the unary hash functor used by this map to generate a hash value (of type bsl::size_t) for a KEY object.

insert

insert overloads

insert_or_assign

insert_or_assign overloads

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.

load_factor

Return the current ratio between the number of elements in this container and its capacity.

max_load_factor

Return the maximum load factor allowed for this map. 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.

operator[]

Subscript operators

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.

rehash

Change the capacity of this map 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 map 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 map are invalidated.

reserve

Change the capacity of this map 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 map 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 map are invalidated. Note that this method is effectively equivalent to: ` rehash(bsl::ceil(numEntries / max_load_factor())) `

reset

Remove all elements from this map and release all memory from this map, returning the map to the default constructed state.

size

Return the number of elements in this map.

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.

try_emplace

try_emplace overloads

Friends

Name

Description

BloombergLP::bdlc::swap

Exchange the contents of the two maps.

BloombergLP::bdlc::operator!=

Return whether the maps differ in key/value contents.

BloombergLP::bdlc::operator==

Return whether the maps have the same key/value contents.

Non-Member Functions

Name

Description

operator!=

Return true if the specified lhs and rhs objects do not have the same value, and false otherwise. Two FlatHashMap 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.

operator==

Return true if the specified lhs and rhs objects have the same value, and false otherwise. Two FlatHashMap 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.

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.

Created with MrDocs