Base struct of HashTable providing internals.
Definition at line 135 of file hashtablebase.inl.
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 |
The maximum quotient of size and bucketCount that triggers a rehash. | |
integer | size |
The number of elements stored. | |
integer | sizeLimitToRehash |
Calculated once with rehash. Product of maxLoadFactor and bucketCount. | |
Public Method Index: | |
HashTableBase (float pBaseLoadFactor, float pMaxLoadFactor) | |
HashTableBase (TAllocator &pAllocator, float pBaseLoadFactor, float pMaxLoadFactor) | |
template<typename TSharedRecycler = SharedRecyclerType, ATMP_T_IF(int, !ATMP_EQ(TSharedRecycler, void)) = 0> | |
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 base |
Our base type.
Definition at line 140 of file hashtablebase.inl.
using Element = typename HTElementSelector<TValueDescriptor, THashCaching>::Type |
The type stored in the bucket of class HashTable.
Definition at line 162 of file hashtablebase.inl.
using FwdList = lang::SidiListHook<Element> |
Type of a single linked node list.
Definition at line 185 of file hashtablebase.inl.
using Node = lang::SidiNodeBase<Element> |
Type of a node in the List.
Definition at line 188 of file hashtablebase.inl.
using recyclerType |
Type of a single linked node list.
Definition at line 170 of file hashtablebase.inl.
using 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 179 of file hashtablebase.inl.
using T = typename TValueDescriptor::StoredType |
Type definition publishing template parameter T.
Definition at line 144 of file hashtablebase.inl.
using TKey = typename TValueDescriptor::KeyType |
Type definition publishing template parameter TKey.
Definition at line 147 of file hashtablebase.inl.
using TMapped = typename TValueDescriptor::MappedType |
Type definition publishing template parameter TKey.
Definition at line 150 of file hashtablebase.inl.
float baseLoadFactor |
The load factor that is set when the table is rehashed automatically.
Definition at line 597 of file hashtablebase.inl.
uinteger bucketCount |
The number of buckets managed by this tree.
Definition at line 591 of file hashtablebase.inl.
FwdList* buckets |
The list of buckets.
Definition at line 594 of file hashtablebase.inl.
float maxLoadFactor |
The maximum quotient of size and bucketCount that triggers a rehash.
Definition at line 600 of file hashtablebase.inl.
integer size |
The number of elements stored.
Definition at line 603 of file hashtablebase.inl.
integer sizeLimitToRehash |
Calculated once with rehash. Product of maxLoadFactor and bucketCount.
Definition at line 606 of file hashtablebase.inl.
|
inline |
Constructor.
pAllocator | The allocator to use. |
pBaseLoadFactor | The base load factor. |
pMaxLoadFactor | The maximum load factor. |
Definition at line 716 of file hashtablebase.inl.
|
inline |
Constructor using HeapAllocator.
pBaseLoadFactor | The base load factor. |
pMaxLoadFactor | The maximum load factor. |
Definition at line 735 of file hashtablebase.inl.
|
inline |
Constructor taking a shared recycler.
pSharedRecycler | The shared recycler hook. |
pBaseLoadFactor | The base load factor. |
pMaxLoadFactor | The maximum load factor. |
Definition at line 755 of file hashtablebase.inl.
|
inline |
Destructor. Destructs all elements in this object. Deletes recyclables, buckets and bucket array.
Definition at line 773 of file hashtablebase.inl.
|
inline |
Returns either a recycled or newly allocated element.
hashCode | The hashCode of the new element. Used only in cached case. |
Definition at line 209 of file hashtablebase.inl.
|
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 630 of file hashtablebase.inl.
|
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 617 of file hashtablebase.inl.
|
inline |
Destructs and removes all entries from this hash table.
Definition at line 799 of file hashtablebase.inl.
|
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 642 of file hashtablebase.inl.
|
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 664 of file hashtablebase.inl.
|
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 911 of file hashtablebase.inl.
|
inlinestatic |
Either returns the cached hash code or calculates it.
elem | The element to receive the hashcode for. |
Definition at line 198 of file hashtablebase.inl.
|
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 701 of file hashtablebase.inl.
|
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 HashMap::EmplaceIfNotExistent.
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 947 of file hashtablebase.inl.
|
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 682 of file hashtablebase.inl.
|
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 973 of file hashtablebase.inl.
|
inlinestaticconstexpr |
Determines whether hash codes are stored with the elements. It is done in case the given template parameter THashCashing equals Caching::Enabled or if it equals Caching::Auto and the key type is an arithmetic type.
true
if hash codes are stored for reuse, false
if not. Definition at line 158 of file hashtablebase.inl.
|
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 838 of file hashtablebase.inl.
|
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 821 of file hashtablebase.inl.