Base struct of HashTable providing internals.
HashTable to this type in namespace detail has no benefit on compilation speed or other positive "technical" effect, nor is it a matter of software design.HashTable. Definition at line 120 of file hashtablebase.hpp.
#include <hashtablebase.hpp>
Inner Type Index: | |
| class | TIterator |
| class | TLocalIterator |
Public Type Index: | |
| using | base |
| Our base type. | |
| using | Element = typename HTElementSelector<TValueDescriptor, THashCaching>::Type |
The type stored in the bucket of class HashTable. | |
| using | FwdList = lang::SidiListHook<Element> |
| Type of a single linked node list. | |
| using | Node = lang::SidiNodeBase<Element> |
Type of a node in the List. | |
| using | recyclerType |
| Type of a single linked node list. | |
| using | SharedRecyclerType |
| using | T = typename TValueDescriptor::StoredType |
| Type definition publishing template parameter T. | |
| using | TKey = typename TValueDescriptor::KeyType |
| Type definition publishing template parameter TKey. | |
| using | TMapped = typename TValueDescriptor::MappedType |
| Type definition publishing template parameter TKey. | |
Public Static Method Index: | |
| static size_t | getHashCode (Element *elem) |
| static constexpr bool | IsCachingHashes () |
Public Field Index: | |
| float | baseLoadFactor |
| The load factor that is set when the table is rehashed automatically. | |
| uinteger | bucketCount |
| The number of buckets managed by this tree. | |
| FwdList * | buckets |
| The list of buckets. | |
| float | maxLoadFactor |
| integer | size |
| The number of elements stored. | |
| integer | sizeLimitToRehash |
| Calculated once with rehash. Product of maxLoadFactor and bucketCount. | |
Public Method Index: | |
| template<typename TIf = TAllocator> | |
| HashTableBase (float pBaseLoadFactor, float pMaxLoadFactor) | |
| HashTableBase (TAllocator &pAllocator, float pBaseLoadFactor, float pMaxLoadFactor) | |
| template<typename TSharedRecycler = SharedRecyclerType, typename TIf = TAllocator> | |
| HashTableBase (TSharedRecycler &pSharedRecycler, float pBaseLoadFactor=1.0, float pMaxLoadFactor=2.0) | |
| ~HashTableBase () | |
| Element * | allocElement (const size_t hashCode) |
| bool | areEqual (Element *elem, const TKey &key, size_t keyHashCode) const |
| bool | areEqual (Element *lhs, Element *rhs) const |
| void | clear () |
| Destructs and removes all entries from this hash table. | |
| Element * | findElement (uinteger bucketIdx, const TKey &key, size_t keyHashCode) const |
| Node * | findElementBefore (uinteger bucketIdx, size_t keyHashCode, const TKey &key) const |
| std::pair< TIterator< T >, TIterator< T > > | findRange (const TKey &key) |
| size_t | increaseSize (integer increase, const size_t hashCode=0) |
| std::pair< TIterator< T >, bool > | insertIfNotExists (const TKey &key, size_t hashCode) |
| uinteger | insertInBucket (Element *element, const size_t hashCode) |
| std::pair< TIterator< T >, bool > | insertOrGet (const TKey &key, size_t hashCode) |
| void | rehash (uinteger newMinBucketCount) |
| void | setMaxLoadFactor (float pMaxLoadFactor) |
| using alib::containers::detail::HashTableBase< TAllocator, TValueDescriptor, THash, TEqual, THashCaching, TRecycling >::base |
Our base type.
Definition at line 125 of file hashtablebase.hpp.
| using alib::containers::detail::HashTableBase< TAllocator, TValueDescriptor, THash, TEqual, THashCaching, TRecycling >::Element = typename HTElementSelector<TValueDescriptor, THashCaching>::Type |
The type stored in the bucket of class HashTable.
Definition at line 147 of file hashtablebase.hpp.
| using alib::containers::detail::HashTableBase< TAllocator, TValueDescriptor, THash, TEqual, THashCaching, TRecycling >::FwdList = lang::SidiListHook<Element> |
Type of a single linked node list.
Definition at line 170 of file hashtablebase.hpp.
| using alib::containers::detail::HashTableBase< TAllocator, TValueDescriptor, THash, TEqual, THashCaching, TRecycling >::Node = lang::SidiNodeBase<Element> |
Type of a node in the List.
Definition at line 173 of file hashtablebase.hpp.
| using alib::containers::detail::HashTableBase< TAllocator, TValueDescriptor, THash, TEqual, THashCaching, TRecycling >::recyclerType |
Type of a single linked node list.
Definition at line 155 of file hashtablebase.hpp.
| using alib::containers::detail::HashTableBase< TAllocator, TValueDescriptor, THash, TEqual, THashCaching, TRecycling >::SharedRecyclerType |
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 Shared.
Definition at line 164 of file hashtablebase.hpp.
| using alib::containers::detail::HashTableBase< TAllocator, TValueDescriptor, THash, TEqual, THashCaching, TRecycling >::T = typename TValueDescriptor::StoredType |
Type definition publishing template parameter T.
Definition at line 129 of file hashtablebase.hpp.
| using alib::containers::detail::HashTableBase< TAllocator, TValueDescriptor, THash, TEqual, THashCaching, TRecycling >::TKey = typename TValueDescriptor::KeyType |
Type definition publishing template parameter TKey.
Definition at line 132 of file hashtablebase.hpp.
| using alib::containers::detail::HashTableBase< TAllocator, TValueDescriptor, THash, TEqual, THashCaching, TRecycling >::TMapped = typename TValueDescriptor::MappedType |
Type definition publishing template parameter TKey.
Definition at line 135 of file hashtablebase.hpp.
| float alib::containers::detail::HashTableBase< TAllocator, TValueDescriptor, THash, TEqual, THashCaching, TRecycling >::baseLoadFactor |
The load factor that is set when the table is rehashed automatically.
Definition at line 524 of file hashtablebase.hpp.
| uinteger alib::containers::detail::HashTableBase< TAllocator, TValueDescriptor, THash, TEqual, THashCaching, TRecycling >::bucketCount |
The number of buckets managed by this tree.
Definition at line 518 of file hashtablebase.hpp.
| FwdList* alib::containers::detail::HashTableBase< TAllocator, TValueDescriptor, THash, TEqual, THashCaching, TRecycling >::buckets |
The list of buckets.
Definition at line 521 of file hashtablebase.hpp.
| float alib::containers::detail::HashTableBase< TAllocator, TValueDescriptor, THash, TEqual, THashCaching, TRecycling >::maxLoadFactor |
The maximum quotient of size and bucketCount that triggers a rehash.
Definition at line 528 of file hashtablebase.hpp.
| integer alib::containers::detail::HashTableBase< TAllocator, TValueDescriptor, THash, TEqual, THashCaching, TRecycling >::size |
The number of elements stored.
Definition at line 531 of file hashtablebase.hpp.
| integer alib::containers::detail::HashTableBase< TAllocator, TValueDescriptor, THash, TEqual, THashCaching, TRecycling >::sizeLimitToRehash |
Calculated once with rehash. Product of maxLoadFactor and bucketCount.
Definition at line 534 of file hashtablebase.hpp.
|
inline |
Constructor.
| pAllocator | The allocator to use. |
| pBaseLoadFactor | The base load factor. |
| pMaxLoadFactor | The maximum load factor. |
Definition at line 629 of file hashtablebase.hpp.
|
inline |
Constructor omitting an allocator. Only applicable if the allocator type is default-constructible, i.e., with class HeapAllocator.
| pBaseLoadFactor | The base load factor. |
| pMaxLoadFactor | The maximum load factor. |
| TIf | Defaulted, must not be given. |
Definition at line 650 of file hashtablebase.hpp.
|
inline |
Constructor taking a shared recycler.
| pSharedRecycler | The shared recycler hook. |
| pBaseLoadFactor | The base load factor. |
| pMaxLoadFactor | The maximum load factor. |
| TSharedRecycler | Used to select this constructor. Deduced by the compiler. |
Definition at line 668 of file hashtablebase.hpp.
|
inline |
Destructor. Destructs all elements in this object. Deletes recyclables, buckets and bucket array.
Definition at line 683 of file hashtablebase.hpp.
|
inline |
Returns either a recycled or newly allocated element.
| hashCode | The hashCode of the new element. Used only in cached case. |
Definition at line 193 of file hashtablebase.hpp.
|
inline |
Compares a key and a node. If cached mode, the hash codes are compared before the keys.
| elem | The element to compare. |
| key | The key to compare. |
| keyHashCode | The hash code of key. |
Definition at line 557 of file hashtablebase.hpp.
|
inline |
Compares two elements. If cached mode, the hash code is compared before the keys.
| lhs | The first node to compare. |
| rhs | The second node to compare. |
Definition at line 545 of file hashtablebase.hpp.
|
inline |
Destructs and removes all entries from this hash table.
Definition at line 703 of file hashtablebase.hpp.
|
inline |
Searches the first element equal to key in bucket bucketIdx.
| bucketIdx | The bucket number to search in (hash code divided by bucketCount). |
| key | The key-portion of the element to search. |
| keyHashCode | The hash code of key. |
nullptr if not found. Definition at line 568 of file hashtablebase.hpp.
|
inline |
Searches the predecessor of the first element equal to key in bucket bucketIdx.
| bucketIdx | The bucket number to search in (hash code divided by bucketCount). |
| key | The key-portion of the element to search. |
| keyHashCode | The hash code of key. |
nullptr if not found. Definition at line 586 of file hashtablebase.hpp.
|
inline |
Searches the first and last element stored according to given key. Returns a pare of iterators that define a range containing all elements with key key of the container.
Parameter resultStart is set to the first element of the matching range and parameter resultEnd is set to point past the last element of the range.
If no element with key key is found, both iterators are set to end.
| key | The key-portion of the elements to find. |
Definition at line 798 of file hashtablebase.hpp.
|
inlinestatic |
Either returns the cached hash code or calculates it.
| elem | The element to receive the hashcode for. |
Definition at line 183 of file hashtablebase.hpp.
|
inline |
Increases field size and checks for a rehash.
| increase | The amount to increase. |
| hashCode | A hashCode that caller might want to have converted into a new actual bucket index. |
Definition at line 617 of file hashtablebase.hpp.
|
inline |
Searches (a first) element with the given key. If not found, an invalid iterator to the bucket is returned with a nulled element pointer. Before this counter size is increased and, if a load limit is reached, a re-hash is performed.
If otherwise an element was found, its valid iterator is returned.
Note: Used by std::pair< Iterator, bool > EmplaceIfNotExistent(const KeyType&, TArgs&& ...) .
| key | The key to the (first) element to find. |
| hashCode | The hash code of parameter key. |
true if the insertion took place and false nothing was changed. Definition at line 830 of file hashtablebase.hpp.
|
inline |
Inserts the given element into the bucket. If an element of the same key exists, then the element is put in front of that element. Otherwise it is added to the start of the bucket.
| element | The element to insert to its bucket. |
| hashCode | The hash code of parameter element. |
Definition at line 601 of file hashtablebase.hpp.
|
inline |
Inserts the topmost recyclable element if no element with the same key-portion of its value exists.
| key | Pointer to the key to search elements for deletion. |
| hashCode | The hash code of parameter key. |
true if the insertion took place and false if a new element was created. Definition at line 851 of file hashtablebase.hpp.
|
inlinestaticconstexpr |
Determines whether hash codes are stored with the elements. It is done in case the given template parameter THashCashing equals Enabled or if it equals Auto and the key type is an arithmetic type.
true if hash codes are stored for reuse, false if not. Definition at line 143 of file hashtablebase.hpp.
|
inline |
Changes the number of buckets to be at least the higher value of a) the given newMinBucketCount, and
b) the quotient of the current size and the maximum load factor.
The result of the above, is increased to the next higher prime number. Rehash is only performed if bucket size increases. It never is decreased.
| newMinBucketCount | The minimum new bucket count requested. |
Definition at line 735 of file hashtablebase.hpp.
|
inline |
Changes the maximum load factor value and invokes rehash providing the actual bucket count as the minimum bucket count that is to be chosen.
| pMaxLoadFactor | The maximum load factor used to determine the need of re-hashing. |
Definition at line 721 of file hashtablebase.hpp.