53 template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC = allocator<K_TYPE>,
typename HASH = hash<K_TYPE>>
230 389, 769, 1543, 3079, 6151,
231 12289, 24593, 49157, 98317, 196613,
233 393241, 786433, 1572869, 3145739, 6291469,
234 12582917, 25165843, 50331653, 100663319, 201326611,
236 402653189, 805306457, 1610612741, 3221225473, 4294967291
412 hashNode*
getBucket(
const K_TYPE& key)
const;
442 void rehash(u_integer new_bucket_count);
456 explicit hashTable(HASH hash = HASH{});
463 hashNode*
find(
const K_TYPE& key)
const;
471 bool modify(
const K_TYPE& key,
const V_TYPE& value);
480 bool insert(
const K_TYPE& key,
const V_TYPE& value);
488 bool erase(
const K_TYPE& key);
498template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
500 : data_({
key, value}), next_(next) {}
502template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
507template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
512 this->data_ =
other.data_;
513 this->next_ =
other.next_;
517template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
523template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
529template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
531 return this->getVal().first();
534template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
536 return this->getVal().second();
539template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
541 return this->getVal().second();
544template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
549template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
551 this->data_.template
set<1>(value);
554template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
560template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
566template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
571template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
573 if (prev !=
nullptr) prev->
setPNext(next);
576template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
584 return buckets->size();
587template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
591 if (
bucket == 0)
return buckets->size();
599 return buckets->size();
602template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
605 : p_buckets(buckets), cur_bucket(
bucket), p_node(
node) {}
607template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
612template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
618 this->p_buckets =
other.p_buckets;
619 this->p_node =
other.p_node;
623template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
625 if (this->p_node && this->p_node->getPNext()) {
632template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
634 if (!this->isValid()) {
638 if (this->p_node->getPNext()) {
639 this->p_node = this->p_node->getPNext();
650 this->cur_bucket = this->p_buckets->size();
651 this->p_node =
nullptr;
654template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
665template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
668 if (!this->isValid()) {
672 return this->p_node->getVal();
675template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
678 if (!this->isValid()) {
682 return this->p_node->getVal();
685template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
690template <
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
715template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
718 auto node = this->rebind_alloc.allocate(1);
719 this->rebind_alloc.construct(
node,
key, value, next);
723template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
725 this->rebind_alloc.destroy(
node);
726 this->rebind_alloc.deallocate(
node, 1);
729template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
735template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
738 return this->buckets.size();
741template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
745 return this->buckets[
code];
748template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
754template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
764template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
775template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
787 cur->setPNext(
nullptr);
798template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
802 }
else if (this->
loadFactor() >= LOAD_FACTOR_MAX){
807template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
813template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
816 if (this->size_ == 0)
826template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
828 if (
auto cur = this->
find(key)){
829 cur->setValue(value);
835template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
839 auto cur = this->getBucket(
key);
841 this->buckets[this->getHashCode(
key)] = this->createNode(
key, value);
846 for (;
cur->getPNext();
cur =
cur->getPNext()){
850 hashNode::connect(
cur, this->createNode(
key, value));
857template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
859 if (this->size_ == 0)
869 if (
cur->getKey() ==
key) {
871 hashNode::connect(prev,
cur->getPNext());
873 this->buckets[
code] =
cur->getPNext();
875 this->destroyNode(
cur);
886template<
typename K_TYPE,
typename V_TYPE,
typename ALLOC,
typename HASH>
890 auto next =
bucket->getPNext();
891 this->destroyNode(
bucket);
Memory allocation interface and implementations.
const TYPE * get() const
Get managed pointer const version.
Definition autoPtr.h:629
Forward iterator for hashTable.
Definition hashTable.h:260
void next() const
Advances to the next element.
Definition hashTable.h:633
couple< const K_TYPE, V_TYPE > & get()
Gets current key-value pair (non-const)
Definition hashTable.h:667
Iterator & operator=(const Iterator &other)
Copy assignment operator.
Definition hashTable.h:614
static u_integer findPrevValidBucket(vector< hashNode *, rebind_alloc_pointer > *buckets, u_integer bucket)
Finds the previous non-empty bucket.
Definition hashTable.h:589
void operator+=(integer steps) const
Advances iterator by steps positions.
Definition hashTable.h:655
bool isValid() const
Checks if iterator points to valid element.
Definition hashTable.h:686
bool hasNext() const
Checks if more elements are available.
Definition hashTable.h:624
Iterator(vector< hashNode *, rebind_alloc_pointer > *buckets=nullptr, u_integer bucket=0, hashNode *node=nullptr)
Constructs an iterator pointing to specific position.
Definition hashTable.h:603
static u_integer findNextValidBucket(vector< hashNode *, rebind_alloc_pointer > *buckets, u_integer bucket)
Finds the next non-empty bucket.
Definition hashTable.h:578
Internal node type for hash table storage.
Definition hashTable.h:70
hashNode * getPNext() const override
Gets next node in chain.
Definition hashTable.h:562
couple< const K_TYPE, V_TYPE > & getVal() override
Gets key-value pair (non-const)
Definition hashTable.h:519
const V_TYPE & getValue() const
Gets the value (const)
Definition hashTable.h:535
hashNode * getPPrev() const override
Not supported (throws unSupportedMethodError)
Definition hashTable.h:556
void setPNext(hashNode *new_next)
Sets next node in chain.
Definition hashTable.h:567
const K_TYPE & getKey() const
Gets the key (const)
Definition hashTable.h:530
hashNode(const K_TYPE &key=K_TYPE{}, const V_TYPE &value=V_TYPE{}, hashNode *next=nullptr)
Constructs a new hash node.
Definition hashTable.h:499
void setValue(const V_TYPE &value)
Sets a new value.
Definition hashTable.h:550
static void connect(hashNode *prev, hashNode *next)
Connects two nodes in chain.
Definition hashTable.h:572
void setVal(couple< const K_TYPE, V_TYPE > data) override
Not supported (throws unSupportedMethodError)
Definition hashTable.h:545
hashNode & operator=(const hashNode &other)
Copy assignment operator.
Definition hashTable.h:509
Hash table implementation with separate chaining.
Definition hashTable.h:54
hashNode * createNode(const K_TYPE &key=K_TYPE{}, const V_TYPE &value=V_TYPE{}, hashNode *next=nullptr) const
Creates a new hash node.
Definition hashTable.h:717
bool modify(const K_TYPE &key, const V_TYPE &value)
Modifies value for existing key.
Definition hashTable.h:827
virtual ~hashTable()
Destroys hashTable.
Definition hashTable.h:887
u_integer getPrevSize() const
Gets previous appropriate bucket size for shrinking.
Definition hashTable.h:765
static constexpr floating LOAD_FACTOR_MAX
Maximum load factor before expanding.
Definition hashTable.h:189
u_integer getHashCode(const K_TYPE &key) const
Computes hash code for a key.
Definition hashTable.h:731
static constexpr u_integer BUCKETS_SIZES_COUNT
Size of BUCKETS_SIZES BUCKETS_SIZES.
Definition hashTable.h:195
static constexpr floating LOAD_FACTOR_MIN
Minimum load factor before shrinking.
Definition hashTable.h:184
void rehash(u_integer new_bucket_count)
Rehashes table to new bucket count.
Definition hashTable.h:776
u_integer getNextSize() const
Gets next appropriate bucket size for expansion.
Definition hashTable.h:755
buckets_type bucketsCopy(const buckets_type &old_buckets) const
Creates a deep copy of the hash table's bucket array.
Definition hashTable.h:692
bool insert(const K_TYPE &key, const V_TYPE &value)
Inserts new key-value pair.
Definition hashTable.h:836
hashNode * find(const K_TYPE &key) const
Finds node for given key.
Definition hashTable.h:815
ALLOC::template rebind_alloc< hashNode * > rebind_alloc_pointer
Rebound allocator type for pointer storage.
Definition hashTable.h:173
hashTable(HASH hash=HASH{})
Constructs empty hashTable.
Definition hashTable.h:808
hashNode * getBucket(const K_TYPE &key) const
Gets bucket head for a key.
Definition hashTable.h:743
void destroyNode(hashNode *node) noexcept
Destroys a hash node.
Definition hashTable.h:724
void adjust()
Adjusts table size based on load factor.
Definition hashTable.h:799
floating loadFactor() const
Calculates current load factor.
Definition hashTable.h:750
vector< hashNode *, rebind_alloc_pointer > buckets_type
Type representing the hash table buckets container.
Definition hashTable.h:179
bool erase(const K_TYPE &key)
Removes key-value pair.
Definition hashTable.h:858
u_integer getBucketCount() const
Gets current number of buckets.
Definition hashTable.h:737
ALLOC::template rebind_alloc< hashNode > rebind_alloc_node
Rebound allocator type for node storage.
Definition hashTable.h:167
static constexpr u_integer BUCKETS_SIZES[]
Predefined bucket sizes for hash table resizing.
Definition hashTable.h:228
Generic hash function object supporting multiple types.
Definition hash.h:62
Exception for container index out-of-range errors.
Definition error.h:192
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37
Exception for unimplemented method calls.
Definition error.h:271
Base class for linked value containers with formatted output.
Definition wrapper.h:28
Generic pair container implementation.
double floating
Double-precision floating-point type.
Definition config.h:331
Provides a generic hashing utility and interface for hashable types.
Main namespace for the project Original.
Definition algorithms.h:21
TYPE find(coroutine::generator< TYPE > gen, Callback &&c)
Finds the first element satisfying a predicate.
Definition generators.h:856
Standard namespace extensions for original::alternative.
Definition allocator.h:351
Dynamic array container with automatic resizing.
Abstract polymorphic container with value encapsulation and navigation support.