1. Introduction
2. Hash Set vs. Hash Map Mode
3. Single And Multiple Entries
4. Re-Hashing
5. Iterators
6. Hash Codes
6.1 Caching Hash Codes
6.2 Hash Codes Pre-calculation
6.3 Hash Codes Pre-calculation
7. Memory Use
8. Comparison To Standard Library Hash-Types
Reference Documentation
This class implements a hash table that stores and retrieves objects very efficiently in respect to execution performance. All memory for the hash table and its entries are allocated using a MonoAllocator , which has to be provided with construction of an instance.
Two type definitions based on this class exists, which reduce the set of template parameters of this type by providing reasonable replacements. These types are:
In most cases, one of the two definitions are to be used instead of instantiating this type directly. The meaning of these types are discussed in the next section.
Besides storing values of custom type T , the template parameters and implementation of this class support the concept of "hash maps" which are hash tables that store objects of MappedType which are associated to a value of KeyType.
With that, two type definitions mentioned in the previous section go along well with what is found in the standard C++ library:
The type definition is similar to what types std::unordered_set
and std::unordered_multiset
of the standard C++ class library provide.
std::pair<const TKey, TMapped>
. The type definition is similar to what types std::unordered_map
and std::unordered_multimap
of the standard C++ class library provide.
If instead of one of these two type definitions, this type HashTable is "directly" used, the terms "set" and "map" become become a slightly different meaning. Therefore this documentation defines "modes of operation" with this type:
The advantage of this approach is obvious: This types supports custom value types T that have a key-portion embedded, as often found in custom types. Remember, this case leads to "hash set mode" although it also has some notion that usual "hash maps" have.
As a sample for the advantage consider method EmplaceIfNotExistent(const KeyType& key, TArgs&&... args). A corresponding method is found with type std::unordered_map::try_emplace
, but not with std::unordered_set
. In contrast with this implementation, the method is usable with hash map mode as well as with hash set mode!
The only precondition to the availability of this method in hash set mode, is that value type T has to be constructible from the combined list of given arguments, hence the KeyType argument along with given arguments of variadic template types TArgs . The same is true for method EmplaceOrAssign(const KeyType&, TArgs&&... args)
The set of available interface methods slightly changes with the two operation modes:
Hash map mode:
The following method overloads are exclusively available with hash maps:
In addition, the following method overloads of inner types are also exclusively available with hash maps.
A hint to restrictions is given with the documentation of each method of concern. Note that methods that expect a single KeyType are usable with both operation modes, as with hash sets the key-type equals type ValueType.
std::enable_if
).The standard C++ library differentiates between hashing containers that accept only one element with a specific key-portion of the value (see std::unordered_set
and std::unordered_map
) and those that accept multiple insertions of objects with the same key-portion (see std::unordered_multiset
std::unordered_multimap
).
This library does not provide separate types and any instantiation of this class allows multiple entries. But this is rather an extension of functionality, than a restriction and does not impose a penalty on performance.
If unique entries are to be achieved, the user of the type has to make sure for herself that no multiple entries are inserted. This can be guaranteed, with the exclusive use of the following set of (partly overloaded) methods, which prevent the creation of multiple entries:
In contrast to this, methods Insert and Emplace (and their overloads) will insert an equal value without giving further notice (for example by providing a special return value that indicates if the inserted key existed before).
Method EraseUnique(const KeyType&) is more efficient than Erase(const KeyType&) and a further advantage is that it asserts (in debug-compilations) that not more than one element is found in the table.
std
-types with C++ 14 and 17 reflect the design problems of the approach to provide "unique" and "multi" types.std::unordered_multimap/set
as well, a performance penalty is given, unless the extended interface of C++ 17 standard is used with great care.std
have equally named methods that act differently and return different result types.A check for the need to perform re-hashing is made with every insertion of an element. The policy for re-hashing is described as follows:
std::numeric_limits<float>::max()
The number of buckets is never decreased, unless method Reset is invoked.
Manual re-hashing is not supported by design. In our view, with monotonic growth (or stability in size) and hence the absence of dynamic increase/decrease scenarios, manual rehashing is not needed. Only the base and maximum load factors are of concern, which both can be specified with construction and with methods MaxLoadFactor respectively MaxLoadFactor.
What can be done however is to use method MaxLoadFactor to "disable" rehashing temporarily and thus to allow an efficient mass insertion. Nevertheless, if the number of elements to be inserted is known upfront, the use of method Reserve, respectively ReserveRecyclables is the preferred approach.
There are two types of iterators provided:
Both types satisfy the C++ standard library concept ForwardIterator .
The following rules define the validity of existing iterator instances on table operations:
Template parameter THashCaching may be used to control if hash codes are cached. Caching the hash codes increases the memory consumption of this class by sizeof(size_t)
per inserted element. While this is only a small amount and memory consumption should not be a great concern when monotonic allocation is used, caching the hash codes may impose a reasonable performance impact. This impact depends on the performance of functor THash working on the key-portion
of the inserted value.
The cached hash code is used when the table is re-hashed. In addition, the cached hash code is also used with almost all interface methods (insertion, deletion and search operations): If cached, any needed comparison of two elements will first compare the hash codes and only invoke templated functor TEqual if those match.
If template parameter THashCaching evaluates to Caching::Auto then this class defaults to use caching if type KeyType is not arithmetic (using std::is_arithmetic<TKey>
for this check).
The caching option of an instance of this class can be queried with enum CachedHashCodes.
The following overloaded methods accept parameter hashCode in addition to the parameters accepted by their corresponding base version:
The rational for the provision of these methods is to allow to "pre-calculate" a key's hash code prior to invoking the method. This is efficient in situations where one or more subsequent operations with the same key are performed. For example:
To have hash tables perform in constant time O(1) in the average case, a well implemented calculation of hash-codes has to be provided for template type TKey with template functor THash . This is an obligation of the user of this type.
This ALib Module supports compiler symbol ALIB_DEBUG_MONOMEM which enables extra features. The entities relevant for this type are:
These methods may be used to assert the quality of custom hash algorithms.
With template parameter TRecycling being either Recycling::Private (the default) or Recycling::Shared the internal "node objects" are remembered when elements are erased, and "recycled" with future insertions. The rational for this lies in the simple fact that memory can not be returned to the monotonic allocator. The recycling mechanism is very lightweight and does not cost measurable performance. If it is assured that no deletions are made during the life-cycle of an instance, type Recycling::None may be used to eliminate this little overhead of recycling.
If the table is re-hashed, the former bucket list is likewise recycled and sliced into as many internal node objects as possible.
With these two mechanisms in place, the use of monotonic allocation with this container is very safe in respect to avoid memory exhaustion. The use of this class, even in scenarios where a lot of (theoretically an endless amount of) erase and insert operations are performed, will not increase memory consumption, as long it is guaranteed that the overall size of the table is limited.
If a maximum number of possible insertions is known, method ReserveRecyclables might be used to allocate all needed memory at once. With that, a snapshot of the allocator can be taken and later used to reset the allocator to the minimum that preserves all memory in the according hash table instance.
For advanced usage, it is advisable to fully understand the concept of monotonic allocation implemented with this module ALib Monomem .
In the previous sections, it was already referred several times to types
std::unordered_map
,std::unordered_multimap,
std::unordered_set
andstd::unordered_multiset
of the C++ standard library. The uses cases and features of these four compared to this type are generally the same and this type can be used to replace the standard tyes without general limitations and vice versa.
Then with C++ 17, the standard library was extended by a new set of types, namely
std::pmr::unordered_map
,std::pmr::unordered_multimap,
std::pmr::unordered_set
andstd::pmr::unordered_multiset
which likewise this type, may use monotonic allocation (for example in combination with C++ 17 type std::pmr::monotonic_buffer_resource
). While on the one hand ALib in the past needed support of monotonic allocation already for C++ 11, on the other hand the C++ 17 library extensions follow slightly different design goal. Details of this are given in the previous section.
Beside these general differences, the specific similarities and differences can be summarized as follows:
std::pair
of key and value elements. For convenience, when the use of std::pair
is suitable, type definition HashMap offers exactly this.find
, which allows to perform the same optimization.operator[]
defined. The rational to omit this - at first sight convenient and intuitive - operator, is that it imposes insert operation even if used in r-value expressions. This is considered an unwanted side effect.operator=
is not available with this implementation. If needed such has to implemented by a user (full iteration with copying elements from one instance to another).T | The values that this hash table stores. In case of hash map mode, this type needs to contain both, the key-portion and the mapped-portion of the data. |
TStored | Internal storage version of T . This is used with hash map mode to provide a data type which is storage-compatible to T but with a constant key-portion. The internally stored (mutable) data is reinterpreted (!) as T in this case. Hence, a reinterpret cast from this type to T has to be "legal". With hash set mode, this type should be the same as T . |
TKey | The key type. In case of hash set mode, the type given has to be the same as T . This type is published as HashTable::KeyType . |
TIfMapped | The type of the mapped portion of the data. This type is published as HashTable::MappedType . In case of hash set mode, type void has to be given and the resulting type HashTable::MappedType is "undefined" (not usable). |
THash | With hash map mode, this type needs to be a hash functor on type TKey , which in hash set mode, equals T . This type is published as HashTable::HashType . |
TEqual | With hash map mode, this type needs to be a comparison functor on TKey , which in hash set mode, equals T . The type is published as HashTable::EqualType . |
TAccess | A functor-like struct used to access the key- and mapped-portion of type T . Needs to provide static method, Key with hash set mode and with hash map mode, in addition method Mapped() has to be defined. For details on required method signatures see provided implementations detail::HashSetAccess and detail::HashMapAccess as a sample. |
THashCaching | Determines if hash codes are cached when elements are inserted. Defaults to Caching::Auto, which enables caching if std::is_arithmetic<TKey>::value evaluates to false . |
TRecycling | Denotes the type of recycling that is to be performed. Possible values are Recycling::Private (the default), Recycling::Shared or Recycling::None . |
Definition at line 453 of file hashtable.hpp.
#include <hashtable.hpp>
Inner Type Index: | |
class | ElementHandle |
Public Method Index: | |
Construction/Destruction And Allocator Access | |
############################################################################################ ############################################################################################# | |
HashTable (MonoAllocator *pAllocator, float pBaseLoadFactor=1.0, float pMaxLoadFactor=2.0) | |
HashTable (MonoAllocator *pAllocator, TSharedRecycler &pRecycler, float pBaseLoadFactor=1.0, float pMaxLoadFactor=2.0) | |
~HashTable () | |
void | SetAllocatorPostConstruction (MonoAllocator *pAllocator) |
MonoAllocator * | GetAllocator () const |
Size and Capacity | |
############################################################################################ ############################################################################################# | |
void | Clear () |
void | Reset () |
integer | Size () const |
bool | IsEmpty () const |
void | Reserve (integer expected, lang::ValueReference reference) |
void | ReserveRecyclables (integer expected, lang::ValueReference reference) |
integer | RecyclablesCount () const |
Hash Policy | |
############################################################################################ ############################################################################################# | |
void | BaseLoadFactor (float newBaseLoadFactor) |
float | BaseLoadFactor () const |
void | MaxLoadFactor (float newMaxLoadFactor) |
float | MaxLoadFactor () const |
Bucket Interface | |
############################################################################################ ############################################################################################# | |
uinteger | BucketCount () const |
uinteger | BucketSize (uinteger bucketNumber) const |
uinteger | BucketNumber (const KeyType &key) const |
Element Insertion | |
############################################################################################ ############################################################################################# | |
Iterator | Insert (const T &value) |
Iterator | Insert (const T &value, size_t hashCode) |
Iterator | Insert (T &&value) |
Iterator | Insert (T &&value, size_t hashCode) |
Iterator | Insert (ElementHandle &handle) |
Iterator | InsertUnique (const T &value) |
Iterator | InsertUnique (const T &value, size_t hashCode) |
Iterator | InsertUnique (T &&value) |
Iterator | InsertUnique (T &&value, size_t hashCode) |
template<typename TEnableIf = TIfMapped> | |
InsertOrAssign (const KeyType &key, const MappedType &mapped) | |
template<typename TEnableIf = TIfMapped> | |
InsertOrAssign (const KeyType &key, MappedType &&mapped) | |
template<typename TEnableIf = TIfMapped> | |
InsertOrAssign (const KeyType &key, MappedType &&mapped, size_t hashCode) | |
template<typename TEnableIf = TIfMapped> | |
InsertIfNotExistent (const KeyType &key, const MappedType &mapped) | |
template<typename TEnableIf = TIfMapped> | |
InsertIfNotExistent (const KeyType &key, MappedType &&mapped, size_t hashCode) | |
template<typename TEnableIf = TIfMapped> | |
InsertIfNotExistent (const KeyType &key, MappedType &&mapped) | |
std::pair< Iterator, bool > | InsertIfNotExistent (const T &value) |
std::pair< Iterator, bool > | InsertIfNotExistent (T &&value) |
std::pair< Iterator, bool > | InsertIfNotExistent (T &&value, size_t hashCode) |
Iterator | InsertIfNotExistent (ElementHandle &handle) |
template<typename... TArgs> | |
Iterator | Emplace (TArgs &&... args) |
template<typename... TArgs> | |
Iterator | EmplaceUnique (TArgs &&... args) |
template<typename TEnableIf = TIfMapped, typename... TArgs> | |
std::pair< Iterator, bool > | EmplaceOrAssign (const KeyType &key, TArgs &&... args) |
template<typename TEnableIf = TIfMapped, typename... TArgs> | |
std::pair< Iterator, bool > | EmplaceIfNotExistent (TArgs &&... args) |
template<typename TEnableIf , typename... TArgs> | |
std::pair< Iterator, bool > | EmplaceIfNotExistent (const KeyType &key, TArgs &&... args) |
Element Search | |
############################################################################################ ############################################################################################# | |
Iterator | Find (const KeyType &key) |
ConstIterator | Find (const KeyType &key) const |
Iterator | Find (const KeyType &key, size_t hashCode) |
ConstIterator | Find (const KeyType &key, size_t hashCode) const |
bool | Contains (const KeyType &key) const |
std::pair< Iterator, Iterator > | EqualRange (const KeyType &key) |
std::pair< ConstIterator, ConstIterator > | EqualRange (const KeyType &key) const |
Element Removal | |
############################################################################################ ############################################################################################# | |
ElementHandle | Extract (const KeyType &key) |
ElementHandle | Extract (const KeyType &key, size_t hashCode) |
ElementHandle | Extract (ConstIterator pos) |
integer | Erase (const KeyType &key) |
integer | Erase (const KeyType &key, size_t hashCode) |
bool | EraseUnique (const KeyType &key) |
bool | EraseUnique (const KeyType &key, size_t hashCode) |
Iterator | Erase (ConstIterator pos) |
ALIB_WARNINGS_IGNORE_NOTHING_RETURNED Iterator | Erase (ConstIterator start, ConstIterator end) |
ALIB_WARNINGS_RESTORE LocalIterator | Erase (ConstLocalIterator pos) |
LocalIterator | Erase (ConstLocalIterator start, ConstLocalIterator end) |
std::iterator_traits Interface | |
############################################################################################ ############################################################################################# | |
Iterator | begin () |
Iterator | end () |
ConstIterator | begin () const |
ConstIterator | end () const |
ConstIterator | cbegin () const |
ConstIterator | cend () const |
LocalIterator | begin (uinteger bucketNumber) |
LocalIterator | end (uinteger bucketNumber) |
ConstLocalIterator | begin (uinteger bucketNumber) const |
ConstLocalIterator | end (uinteger bucketNumber) const |
ConstLocalIterator | cbegin (uinteger bucketNumber) const |
ConstLocalIterator | cend (uinteger bucketNumber) const |
using AccessType = TAccess |
Type definition publishing template parameter TAccess .
Definition at line 485 of file hashtable.hpp.
using ConstIterator = typename base::template TIterator <const T> |
The constant iterator exposed by this container.
Definition at line 502 of file hashtable.hpp.
using ConstLocalIterator = typename base::template TLocalIterator <const T> |
The constant iterator for a single bucket exposed by this container.
Definition at line 508 of file hashtable.hpp.
using EqualType = TEqual |
Type definition publishing template parameter TEqual .
Definition at line 482 of file hashtable.hpp.
using HashType = THash |
Type definition publishing template parameter THash .
Definition at line 479 of file hashtable.hpp.
using Iterator = typename base::template TIterator < T> |
The mutable iterator exposed by this container.
Definition at line 499 of file hashtable.hpp.
using KeyType = TKey |
Type definition publishing template parameter TKey .
Definition at line 472 of file hashtable.hpp.
using LocalIterator = typename base::template TLocalIterator < T> |
The mutable iterator for a single bucket exposed by this container.
Definition at line 505 of file hashtable.hpp.
using MappedType = typename base::TMapped |
Type definition publishing template parameter TIfMapped in the case void
is not given. If TIfMapped is void, this type definition is not usable.
Definition at line 476 of file hashtable.hpp.
using TSharedRecycler = lang::SidiListHelper<Element> |
This type definition may be used to define an externally managed shared recycler, which can be passed to the alternative constructor of this class when template parameter TRecycling equals Recycling::Shared .
Definition at line 493 of file hashtable.hpp.
using ValueType = T |
Type definition publishing template parameter T .
Definition at line 469 of file hashtable.hpp.
|
staticconstexpr |
TMP constant that denotes whether hash codes are cached or not.
Definition at line 496 of file hashtable.hpp.
|
inlineexplicit |
Constructor.
pAllocator | The monotonic allocator to use. |
pBaseLoadFactor | The base load factor. Defaults to 1.0 . |
pMaxLoadFactor | The maximum load factor. Defaults to 2.0 . |
|
inlineexplicit |
Constructor taking a shared recycler.
pAllocator | The monotonic allocator to use. |
pRecycler | The shared recycler. |
pBaseLoadFactor | The base load factor. See method BaseLoadFactor for details. Defaults to 1.0 . |
pMaxLoadFactor | The maximum load factor. See method MaxLoadFactor for details. Defaults to 2.0 . |
Definition at line 669 of file hashtable.hpp.
|
inline |
Destructor. Destructs all elements in this object.
Definition at line 682 of file hashtable.hpp.
|
inline |
Returns the actual base load factor.
Definition at line 868 of file hashtable.hpp.
|
inline |
Sets a new value for the "base load factor" used with this container. The base load factor determines the minimum number of buckets when re-hashing is performed.
The formula to determine the minimum number of buckets is Size divided by this factor. A static table of prime numbers is searched for the next higher number and this value is then used to determine the number of buckets.
The default value for this factor is defined as 1.0
by the default value of parameter pBaseLoadFactor of the constructor.
newBaseLoadFactor | The new base load factor to use when a rehash is performed. |
Definition at line 854 of file hashtable.hpp.
|
inline |
Returns an iterator referring to a mutable element at the start of this table.
Definition at line 2256 of file hashtable.hpp.
|
inline |
Returns an iterator referring to a constant element at the start of this container.
Definition at line 2264 of file hashtable.hpp.
|
inline |
Returns an iterator referring to a mutable element at the start of bucket of index bucketNumber .
bucketNumber | The bucket to iterate on. |
Definition at line 2284 of file hashtable.hpp.
|
inline |
Returns an iterator referring to a mutable element at the start of bucket of index bucketNumber .
bucketNumber | The bucket to iterate on. |
Definition at line 2308 of file hashtable.hpp.
|
inline |
Returns the number of "buckets" that this hash table currently uses.
Definition at line 922 of file hashtable.hpp.
|
inline |
Returns the number of the bucket corresponding to key .
key | The key to evaluate the bucket number for. |
Definition at line 948 of file hashtable.hpp.
|
inline |
Returns the number of entries stored in the bucket with the given number.
bucketNumber | The number of the bucket to receive the size for. |
Definition at line 933 of file hashtable.hpp.
|
inline |
Returns an iterator referring to a constant element at the start of this container.
Definition at line 2272 of file hashtable.hpp.
|
inline |
Returns an iterator referring to a mutable element at the start of bucket of index bucketNumber .
bucketNumber | The bucket to iterate on. |
Definition at line 2332 of file hashtable.hpp.
|
inline |
Returns an iterator referring to a constant, non-existing element.
Definition at line 2276 of file hashtable.hpp.
|
inline |
Returns an iterator referring to a constant, non-existing element in bucket of index bucketNumber .
bucketNumber | The bucket to iterate on. |
Definition at line 2345 of file hashtable.hpp.
|
inline |
Destructs and removes all elements from this hash table. The allocated space of the elements will be preserved and "recycled" with future insertions.
Definition at line 724 of file hashtable.hpp.
|
inline |
Tests if an element with given key is stored in this container.
key | The key to search for. |
true
if this hash table contains at least one element with given key-portion key , false
otherwise. Definition at line 1846 of file hashtable.hpp.
|
inline |
Constructs a new element within this container.
TArgs | Types of variadic parameters given with parameter args . |
args | Variadic parameters to be forwarded to constructor of the inserted element's custom data of ValueType. |
Definition at line 1468 of file hashtable.hpp.
|
inline |
Inserts a new mapped object only if no other object is contained that is associated already with a key that equals the given key .
TEnableIf | Used to disable this method where not available. |
TArgs | Types of variadic parameters given with parameter args . |
key | The key to use for search and insertion. |
args | Variadic parameters to be forwarded to constructor of the mapped object of type MappedType . |
true
if the insertion took place and false
nothing was changed.
|
inline |
Inserts a new element only if no other element is contained equals to the one that is constructed by args .
TEnableIf | Used to disable this method where not available. |
TArgs | Types of variadic parameters given with parameter args . |
args | Variadic parameters to be forwarded to constructor of T . |
true
if the insertion took place and false
nothing was changed.
|
inline |
Replaces an existing, respectively constructs a new element within this container.
TEnableIf | Used to disable this method where not available. |
TArgs | Types of variadic parameters given with parameter args . |
key | The key to use for search and insertion. |
args | Variadic parameters to be forwarded to constructor of the mapped object of type MappedType . |
true
if the insertion took place and false
if the assignment took place.
|
inline |
Constructs a value within this container without checking to place it in the right position in respect to existing elements with the same key-portion.
TArgs | Types of variadic parameters given with parameter args . |
args | Variadic parameters to be forwarded to constructor of the element to insert whose key-portion has to be different to all currently contained elements. |
Definition at line 1514 of file hashtable.hpp.
|
inline |
Returns an iterator referring to a mutable, non-existing element.
Definition at line 2260 of file hashtable.hpp.
|
inline |
Returns an iterator referring to a constant, non-existing element.
Definition at line 2268 of file hashtable.hpp.
|
inline |
Returns an iterator referring to a constant, non-existing element in bucket of index bucketNumber .
bucketNumber | The bucket to iterate on. |
Definition at line 2297 of file hashtable.hpp.
|
inline |
Returns an iterator referring to a constant, non-existing element in bucket of index bucketNumber .
bucketNumber | The bucket to iterate on. |
Definition at line 2321 of file hashtable.hpp.
|
inline |
Searches a key and returns a pair of iterators. The first is pointing to the first element of the range, the second is pointing to the first element past the range.
If both iterators are equal, the range is empty (both iterators will be equal to end).
key | The key to search for. |
Definition at line 1862 of file hashtable.hpp.
|
inline |
Searches a key and returns a pair of iterators. The first is pointing to the first element of the range, the second is pointing to the first element past the range.
If both iterators are equal, the range is empty (both iterators will be equal to end).
key | The key to search for. |
Definition at line 1876 of file hashtable.hpp.
|
inline |
Erases all elements stored with the given key.
key | The key to search elements for deletion. |
Definition at line 1969 of file hashtable.hpp.
|
inline |
Overloaded version of method Erase(const KeyType&) which accepts the hashCode of the given key as a second parameter.
See alib_ns_monomem_hashtable_hashprecalc for use cases of this method.
key | The key to search elements for deletion. |
hashCode | Pre-calculated hash code of key . |
Definition at line 1985 of file hashtable.hpp.
|
inline |
Removes an element specified by an iterator.
If the iterator was not valid (i.e end), the method has undefined behavior. With debug builds an ALib assertion is raised.
The order of the elements that are not erased is preserved, what makes it possible to erase individual elements while iterating through the container.
pos | The iterator to the element to remove. |
Definition at line 2072 of file hashtable.hpp.
|
inline |
Removes all elements from the given position start to the element before given position end .
The order of the elements that are not erased is preserved, what makes it possible to erase individual elements while iterating through the container.
start | The iterator to the element to remove. |
end | The first element not to remove. |
Definition at line 2108 of file hashtable.hpp.
|
inline |
Removes an element specified by a bucket iterator. Bucket iterators are receivable using overloaded methods begin(uinteger) and cbegin(uinteger) .
The order of the elements that are not erased is preserved, what makes it possible to erase individual elements while iterating through the container.
pos | The iterator to the element to remove. |
Definition at line 2190 of file hashtable.hpp.
|
inline |
Removes all element from the given bucket iterator position start to the element before given position end .
The order of the elements that are not erased is preserved, what makes it possible to erase individual elements while iterating through the container.
start | The bucket iterator to the element to remove. |
end | The bucket iterator to the first element not to remove. |
Definition at line 2218 of file hashtable.hpp.
|
inline |
Erases the unique element with the given key.
key | The key to search elements for deletion. |
true
if an element was found and removed, false
otherwise. Definition at line 2027 of file hashtable.hpp.
|
inline |
Overloaded version of method EraseUnique(const KeyType&) which accepts the hashCode of the given key as a second parameter.
See alib_ns_monomem_hashtable_hashprecalc for use cases of this method.
key | The key to search elements for deletion. |
hashCode | Pre-calculated hash code of key . |
true
if an element was found and removed, false
otherwise. Definition at line 2043 of file hashtable.hpp.
|
inline |
Extracts the first element found with the given key from the hash table and returns a handle to it.
Extracting a element invalidates only the iterators to the extracted element, and preserves the relative order of the elements that are not extracted.
Extracting and re-inserting nodes is the only way to change a key of an element without performing reallocation and or destruction/construction.
key | The key to search a first element for. |
Definition at line 1899 of file hashtable.hpp.
|
inline |
Overloaded version of method Extract(const KeyType&) which accepts the hashCode of the given key as a second parameter.
See alib_ns_monomem_hashtable_hashprecalc for use cases of this method.
key | The key to search a first element for. |
hashCode | Pre-calculated hash code of key . |
Definition at line 1917 of file hashtable.hpp.
|
inline |
Extracts the first element found with the given key from the hash table and returns a handle to it.
If the iterator was not valid (i.e. end), the method has undefined behavior. With debug builds an ALib assertion is raised.
Extracting a element invalidates only the iterators to the extracted element, and preserves the relative order of the elements that are not extracted.
Extracting and re-inserting nodes is the only way to change a key of an element without performing reallocation and or destruction/construction.
pos | The position of the element to extract. |
Definition at line 1947 of file hashtable.hpp.
|
inline |
Returns an iterator pointing to the first element of equal key value.
key | The key to search for. |
Definition at line 1782 of file hashtable.hpp.
|
inline |
Searches an element.
key | The key to search for. |
Definition at line 1796 of file hashtable.hpp.
|
inline |
Overloaded version of method Find(const KeyType&) which accepts the hashCode of the given key as a second parameter.
See alib_ns_monomem_hashtable_hashprecalc for use cases of this method.
key | The key to search for. |
hashCode | Pre-calculated hash code of key . |
Definition at line 1815 of file hashtable.hpp.
|
inline |
Overloaded version of method Find(const KeyType&)const which accepts the hashCode of the given key as a second parameter.
See alib_ns_monomem_hashtable_hashprecalc for use cases of this method.
key | The key to search for. |
hashCode | Pre-calculated hash code of key . |
Definition at line 1833 of file hashtable.hpp.
|
inline |
Returns the allocator of this object. Usually the allocator might be used to perform allocations in respect to data found in objects stored in this object. However, such allowance is dependent on the use case and not part of this class's contract.
Definition at line 710 of file hashtable.hpp.
|
inline |
See Insert(T&&) which is invoked with a copy of value .
value | A value to copy and insert. |
Definition at line 962 of file hashtable.hpp.
|
inline |
Overloaded version of method Insert(const T&) which accepts the hashCode of the given value as a second parameter.
See alib_ns_monomem_hashtable_hashprecalc for use cases of this method.
value | A value to copy and insert. |
hashCode | Pre-calculated hash code of value . |
Definition at line 977 of file hashtable.hpp.
|
inline |
Inserts the element contained in the given ElementHandle into the hash table.
Objects of type ElementHandle objects may be received using overloaded methods Extract. The combination of Extract and this method (as well as method InsertIfNotExistent(ElementHandle&) are the only way to change the key-portion of an element without element destruction/re-construction.
handle | A reference to a handle to an element, previously received with Extract. |
Definition at line 1048 of file hashtable.hpp.
|
inline |
Moves the given value into this table.
Existing iterators remain valid.
value | An rvalue reference of contained type T to insert. |
Definition at line 996 of file hashtable.hpp.
|
inline |
Overloaded version of method Insert(T&&) which accepts the hashCode of the given value as a second parameter.
See alib_ns_monomem_hashtable_hashprecalc for use cases of this method.
value | An rvalue reference of contained type T to insert. |
hashCode | Pre-calculated hash code of value . |
Definition at line 1013 of file hashtable.hpp.
|
inline |
See InsertIfNotExistent(const KeyType&, MappedType&&) which is invoked with a copy of mapped .
TEnableIf | Used to disable this method for instantiations of this template type with hash set mode. |
key | The key to use for search and insertion. |
mapped | The mapped object to copy and insert if key is not existing. |
true
if the insertion took place and false
if nothing was changed. Definition at line 1269 of file hashtable.hpp.
|
inline |
Inserts a new mapped object only if no other object is contained that is associated already with the same key as given key .
TEnableIf | Used to disable this method for instantiations of this template type with hash set mode. |
key | The key to use for search and insertion. |
mapped | The mapped value to insert if key is not existing. |
true
if the insertion took place and false
if nothing was changed. Definition at line 1334 of file hashtable.hpp.
|
inline |
Overloaded version of method InsertIfNotExistent(const KeyType&,MappedType&&) which accepts the hashCode of the given key as a third parameter.
See alib_ns_monomem_hashtable_hashprecalc for use cases of this method.
TEnableIf | Used to disable this method for instantiations of this template type with hash set mode. |
key | The key to use for search and insertion. |
hashCode | Pre-calculated hash code of key . |
mapped | The mapped value to insert if key is not existing. |
true
if the insertion took place and false
if nothing was changed. Definition at line 1292 of file hashtable.hpp.
|
inline |
See InsertIfNotExistent(T&&) which is invoked with a copy of value .
value | The value to copy and insert. |
true
if the insertion took place and false
if nothing was changed. Definition at line 1347 of file hashtable.hpp.
|
inline |
Inserts the element contained in the given ElementHandle into this table, if no equal element exists. In the unsuccessful case, the given ElementHandle remains set and can be reused.
Existing iterators remain valid.
handle | A reference to a handle to an element, previously received with Extract. |
Definition at line 1429 of file hashtable.hpp.
|
inline |
Inserts a new mapped object only if no other object is contained that is associated already with the same key as given key .
value | A rvalue reference of a T to insert. |
true
if the insertion took place and false
if nothing was changed. Definition at line 1368 of file hashtable.hpp.
|
inline |
Overloaded version of method InsertIfNotExistent(T&&) which accepts the hashCode of the given key as a second parameter.
See alib_ns_monomem_hashtable_hashprecalc for use cases of this method.
value | A rvalue reference of a T to insert. |
hashCode | Pre-calculated hash code of value . |
true
if the insertion took place and false
if nothing was changed. Definition at line 1387 of file hashtable.hpp.
|
inline |
See InsertOrAssign(const KeyType&, MappedType&&) which is invoked with a copy of mapped .
TEnableIf | Used to disable this method for instantiations of this template type with hash set mode. |
key | The key to use for search and insertion. |
mapped | The mapped value to copy and then insert or assign. |
true
if the insertion took place and false
if the assignment took place. Definition at line 1178 of file hashtable.hpp.
|
inline |
Replaces an existing, respectively inserts a new element into this hash table.
TEnableIf | Used to disable this method for instantiations of this template type with hash set mode. |
key | The key to use for search and insertion. |
mapped | The mapped value to insert or assign. |
true
if the insertion took place and false
if the assignment took place. Definition at line 1206 of file hashtable.hpp.
|
inline |
Overloaded version of method alib::monomem::HashTable::InsertOrAssign(const KeyType& " MappedType&&)" which accepts the hashCode of the given key as a third parameter.
See alib_ns_monomem_hashtable_hashprecalc for use cases of this method.
TEnableIf | Used to disable this method for instantiations of this template type with hash set mode. |
key | The key to use for search and insertion. |
mapped | The mapped value to insert or assign. |
hashCode | Pre-calculated hash code of key . |
true
if the insertion took place and false
if the assignment took place. Definition at line 1233 of file hashtable.hpp.
|
inline |
See InsertUnique(T&&) which is invoked with a copy of value .
value | An element to insert whose key-portion has to be different to all currently contained elements. |
Definition at line 1069 of file hashtable.hpp.
|
inline |
Overloaded version of method InsertUnique(const T&) which accepts the hashCode of the given key as a second parameter.
See alib_ns_monomem_hashtable_hashprecalc for use cases of this method.
value | An element to insert whose key-portion has to be different to all currently contained elements. |
hashCode | Pre-calculated hash code of value . |
Definition at line 1085 of file hashtable.hpp.
|
inline |
Moves the given value into this table without checking to place it in the right position in respect to existing elements with the same key-portion.
value | An element to insert whose key-portion has to be different to all currently contained elements. |
Definition at line 1116 of file hashtable.hpp.
|
inline |
Overloaded version of method InsertUnique(T&&) which accepts the hashCode of the given key as a second parameter.
See alib_ns_monomem_hashtable_hashprecalc for use cases of this method.
value | An element to insert whose key-portion has to be different to all currently contained elements. |
hashCode | Pre-calculated hash code of value . |
Definition at line 1133 of file hashtable.hpp.
|
inline |
Invokes Size and compares result with 0
.
true
if this list is empty, false
otherwise. Definition at line 756 of file hashtable.hpp.
|
inline |
Returns the actual maximum load factor.
Definition at line 908 of file hashtable.hpp.
|
inline |
Sets a new value for the "maximum load factor" which is the average number of elements per bucket.
The default value for this factor is defined as 2.0
by the default value of parameter pMaxLoadFactor of the constructor.
std::numeric_limits<float>::max()
.newMaxLoadFactor | The maximum load factor used to determine the need of re-hashing. |
Definition at line 894 of file hashtable.hpp.
|
inline |
Counts the number of currently allocated but unused (not contained) element nodes that will be recycled with upcoming insertions.
Definition at line 824 of file hashtable.hpp.
|
inline |
Reserves space for at least the given number of elements. This might re-hash this table.
expected | The expected number or increase of elements to be stored in the hash table. |
reference | Denotes whether expected is meant as an absolute size or an increase . |
Definition at line 768 of file hashtable.hpp.
|
inline |
Same as Reserve but in addition also already allocates the required space for the number of additional elements expected.
expected | The expected number or increase of elements to be stored in the hash table. |
reference | Denotes whether expected is meant as an absolute size or an increase . |
Definition at line 793 of file hashtable.hpp.
|
inline |
Resets this container. Invokes Clear to destruct all keys and values and in case of private recycling disposes all previously allocated recyclable instances of the internal element type.
This method has to be called prior to resetting the associated monotonic allocator given in the constructor.
Definition at line 737 of file hashtable.hpp.
|
inline |
In some situations, the allocator object to use might not be available with construction of an instance. This method may be used to attach an external allocator at a later point in time - but prior to this instance's first use.
pAllocator | The allocator that was omitted in the constructor. |
Definition at line 695 of file hashtable.hpp.
|
inline |
Returns the number of stored elements. Note that this method runs in constant time, as the number of elements is kept counted during operation.
Definition at line 747 of file hashtable.hpp.