|
| StripedUnorderedMap (bsl::size_t numInitialBuckets=k_DEFAULT_NUM_BUCKETS, bsl::size_t numStripes=k_DEFAULT_NUM_STRIPES, bslma::Allocator *basicAllocator=0) |
|
| StripedUnorderedMap (bslma::Allocator *basicAllocator) |
|
| ~StripedUnorderedMap ()=default |
| Destroy this hash map.
|
|
void | clear () |
|
void | disableRehash () |
| Prevent future rehash until enableRehash is called.
|
|
void | enableRehash () |
|
bsl::size_t | erase (const KEY &key) |
|
template<class RANDOM_ITER > |
bsl::size_t | eraseBulk (RANDOM_ITER first, RANDOM_ITER last) |
|
bsl::size_t | eraseIf (const KEY &key, const EraseIfValuePredicate &predicate) |
|
bsl::size_t | insert (const KEY &key, const VALUE &value) |
|
bsl::size_t | insert (const KEY &key, bslmf::MovableRef< VALUE > value) |
|
template<class RANDOM_ITER > |
bsl::size_t | insertBulk (RANDOM_ITER first, RANDOM_ITER last) |
|
void | maxLoadFactor (float newMaxLoadFactor) |
|
void | rehash (bsl::size_t numBuckets) |
|
int | setComputedValue (const KEY &key, const VisitorFunction &visitor) |
|
bsl::size_t | setValue (const KEY &key, const VALUE &value) |
|
bsl::size_t | setValue (const KEY &key, bslmf::MovableRef< VALUE > value) |
|
int | update (const KEY &key, const VisitorFunction &visitor) |
|
int | visit (const VisitorFunction &visitor) |
|
int | visit (const KEY &key, const VisitorFunction &visitor) |
|
bsl::size_t | bucketCount () const |
|
bsl::size_t | bucketIndex (const KEY &key) const |
|
bsl::size_t | bucketSize (bsl::size_t index) const |
|
bool | empty () const |
|
EQUAL | equalFunction () const |
|
bsl::size_t | getValue (VALUE *value, const KEY &key) const |
|
HASH | hashFunction () const |
|
bool | isRehashEnabled () const |
| Return true if rehash is enabled, or false otherwise.
|
|
float | loadFactor () const |
|
float | maxLoadFactor () const |
|
bsl::size_t | numStripes () const |
| Return the number of stripes in the hash.
|
|
int | visitReadOnly (const ReadOnlyVisitorFunction &visitor) const |
|
int | visitReadOnly (const KEY &key, const ReadOnlyVisitorFunction &visitor) const |
|
bsl::size_t | size () const |
| Return the current number of elements in this hash map.
|
|
bslma::Allocator * | allocator () const |
|
template<class KEY, class VALUE, class HASH = bsl::hash<KEY>, class EQUAL = bsl::equal_to<KEY>>
class bdlcc::StripedUnorderedMap< KEY, VALUE, HASH, EQUAL >
This class template defines a fully thread-safe container that provides a mapping from keys (of template parameter type KEY
) to their associated mapped values (of template parameter type VALUE
).
The buckets of this hash map are guarded by numStripes
reader-writer locks, a value specified on construction. Partitioning the buckets among several locks allows greater overall concurrency than a bsl::unordered_map
object guarded by a single lock.
The interface is inspired by, but not identical to that of bsl::unordered_map
. Notably absent are iterators, which are of limited practicality in the typical use case because they are readily invalidated when the map population is open to modification by multiple threads.
See bdlcc_stripedunorderedmap
template<class KEY , class VALUE , class HASH , class EQUAL >
Create an empty StripedUnorderedMap
object, a fully thread-safe hash map where access is partitioned into "stripes" (a group of buckets protected a reader-writer mutex). Optionally specify numInitialBuckets
and numStripes
which define the minimum number of buckets and the (fixed) number of stripes in this map. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used. The hash map has rehash enabled. Note that the number of stripes will not change after construction, but the number of buckets may (unless rehashing is disabled via disableRehash
).
template<class KEY , class VALUE , class HASH , class EQUAL >
template<class RANDOM_ITER >
Erase from this hash map elements in this hash map having any of the values in the keys contained between the specified first
(inclusive) and last
(exclusive) random-access iterators. The iterators provide read access to a sequence of KEY
objects. All erasures are done by the calling thread and the order of erasure is not specified. Return the number of elements removed. The behavior is undefined unless first <= last
. Note that the map may not have an element for every value in keys
.
template<class KEY , class VALUE , class HASH , class EQUAL >
template<class RANDOM_ITER >
Insert into this hash map elements having the key-value pairs obtained between the specified first
(inclusive) and last
(exclusive) random-access iterators. The iterators provide read access to a sequence of bsl::pair<KEY, VALUE>
objects. If an element having one of the keys already exists in this hash map, set the value attribute to the corresponding value from data
. All insertions are done by the calling thread and the order of insertion is not specified. Return the number of elements inserted. The behavior is undefined unless first <= last
.
template<class KEY , class VALUE , class HASH , class EQUAL >
Invoke the specified visitor
on the value associated with the specified key
. The visitor
will be passed the address of the value, and key
. If key
is not in the map, value
will be default constructed. That is, visitor
must be invocable with the VisitorFunction
signature:
bool visitor(VALUE *value, const Key& key);
If no element in the map has key
, insert (key, VALUE())
and invoke visitor
with value
pointing to the default constructed value. Return 1 if key
was found and visitor
returned true
, 0 if key
was not found, and -1 if key
was found and visitor
returned false
. visitor
, when invoked, has exclusive access (i.e., write access) to the element. The behavior is undefined if hash map manipulators and getValue*
methods are invoked from within visitor
, as it may lead to a deadlock. Note that the return value equals the number of elements found having key
. Also note that a return value of 0
implies that an element was inserted.
template<class KEY , class VALUE , class HASH , class EQUAL >
Set the value attribute of the element in this hash map having the specified key
to the specified move-insertable value
. If no such such element exists, insert (key, value)
. Return 1 if key
was found, and 0 otherwise. The value
object is left in a valid but unspecified state. If value
is allocator-enabled and allocator() != value.allocator()
this operation may cost as much as a copy. Note that the return value equals the number of elements found having key
.
template<class KEY , class VALUE , class HASH , class EQUAL >
Set the value attribute of the element in this hash map having the specified key
to the specified value
. If no such such element exists, insert (key, value)
. Return 1 if key
was found, and 0 otherwise. Note that the return value equals the number of elements found having key
.
template<class KEY , class VALUE , class HASH , class EQUAL >
- Deprecated:
- Use visit(key, visitor) instead.
Call the specified visitor
with the element (if one exists) in this hash map having the specified key
. That is:
bool visitor(&value, key);
Return the number of elements updated or -1 if visitor
returned false
. visitor
has exclusive access (i.e., write access) the element for during its invocation. The behavior is undefined if hash map manipulators and getValue*
methods are invoked from within visitor
, as it may lead to a deadlock.
template<class KEY , class VALUE , class HASH , class EQUAL >
Call the specified visitor
with the element (if one exists) in this hash map having the specified key
. That is:
bool visitor(&value, key);
Return the number of elements updated or -1 if visitor
returned false
. visitor
has exclusive access (i.e., write access) the element for during its invocation. The behavior is undefined if hash map manipulators and getValue*
methods are invoked from within visitor
, as it may lead to a deadlock.
template<class KEY , class VALUE , class HASH , class EQUAL >
Call the specified visitor
(in an unspecified order) on all elements in this hash table until each such element has been visited or visitor
returns false
. That is, for (key, value)
, invoke:
bool visitor(&value, key);
Return the number of elements visited or the negation of that value if visitations stopped because visitor
returned false
. visitor
has exclusive access (i.e., write access) to each element for duration of each invocation. Every element present in this hash map at the time visit
is invoked will be visited unless it is removed before visitor
is called for that element. Each visitation is done by the calling thread and the order of visitation is not specified. Elements inserted during the execution of visit
may or may not be visited. The behavior is undefined if hash map manipulators and getValue*
methods are invoked from within visitor
, as it may lead to a deadlock. Note that visitor
can change the value of the visited elements.
template<class KEY , class VALUE , class HASH , class EQUAL >
Call the specified visitor
on element (if one exists) in this hash map having the specified key
. That is, for (key, value)
, invoke:
bool visitor(value, key);
Return the number of elements visited or -1
if visitor
returned false
. visitor
has read-only access to each element for duration of each invocation. The behavior is undefined if hash map manipulators are invoked from within visitor
, as it may lead to a deadlock.
template<class KEY , class VALUE , class HASH , class EQUAL >
Call the specified visitor
(in an unspecified order) on all elements in this hash table until each such element has been visited or visitor
returns false
. That is, for (key, value)
, invoke:
bool visitor(value, key);
Return the number of elements visited or the negation of that value if visitations stopped because visitor
returned false
. visitor
has read-only access to each element for duration of each invocation. Every element present in this hash map at the time visit
is invoked will be visited unless it is removed before visitor
is called for that element. Each visitation is done by the calling thread and the order of visitation is not specified. The behavior is undefined if hash map manipulators are invoked from within visitor
, as it may lead to a deadlock. Note that visitor
can not change the value of the visited elements.