BloombergLP::bslstl::HashTable::insertIfMissing

Insert a default-mapped value for key if the key is missing.

Synopsis

Declared in <bslstl_hashtable.h>

bslalg::BidirectionalLink*
insertIfMissing(KeyType const& key);

Description

Insert into this hash-table a newly-created ValueType object, constructed by forwarding the specified key and a default-constructed object of the type ValueType::second_type, to the corresponding constructor of ValueType, if key does not already exist in this hash-table. Return the address of the (possibly newly created and inserted) element in this hash-table whose key is equivalent to key. If this hash-table contains more than one element with the supplied key, return the first such element (from the contiguous sequence of elements having a matching key). Additional buckets are allocated, as needed, to preserve the invariant loadFactor <= maxLoadFactor. If this function tries to allocate a number of buckets larger than can be represented by this hash table's SizeType, a std::length_error exception is thrown. This method requires that the ValueType defined in the (template parameter) type KEY_CONFIG be emplace-constructible into this hash-table from a pair of arguments representing the key and value, respectively (see {Requirements on KEY_CONFIG});

Return Value

address of the element whose key is equivalent to key

Parameters

NameDescription
keykey used to find or insert an element