57 template <
typename K_TYPE,
59 typename HASH = hash<K_TYPE>,
60 typename ALLOC = allocator<couple<const K_TYPE, V_TYPE>>>
62 :
public hashTable<K_TYPE, V_TYPE, ALLOC, HASH>,
63 public map<K_TYPE, V_TYPE, ALLOC>,
64 public iterable<couple<const K_TYPE, V_TYPE>>,
104 u_integer bucket = 0, hashNode* node =
nullptr);
139 [[nodiscard]] std::string
className()
const override;
164 [[nodiscard]]
bool hasNext()
const override;
170 [[nodiscard]]
bool hasPrev()
const override;
189 void next()
const override;
195 void prev()
const override;
225 [[nodiscard]]
bool isValid()
const override;
235 explicit hashMap(HASH
hash = HASH{}, ALLOC alloc = ALLOC{});
243 hashMap(
const hashMap& other);
252 hashMap&
operator=(
const hashMap& other);
260 hashMap(hashMap&& other)
noexcept;
270 hashMap&
operator=(hashMap&& other)
noexcept;
283 bool contains(
const couple<const K_TYPE, V_TYPE> &e)
const override;
291 bool add(
const K_TYPE &k,
const V_TYPE &v)
override;
298 bool remove(
const K_TYPE &k)
override;
305 [[nodiscard]]
bool containsKey(
const K_TYPE &k)
const override;
313 V_TYPE
get(
const K_TYPE &k)
const override;
321 bool update(
const K_TYPE &key,
const V_TYPE &value)
override;
329 const V_TYPE &
operator[](
const K_TYPE &k)
const override;
337 V_TYPE &
operator[](
const K_TYPE &k)
override;
343 Iterator*
begins()
const override;
349 Iterator*
ends()
const override;
355 [[nodiscard]] std::string
className()
const override;
362 [[nodiscard]] std::string
toString(
bool enter)
const override;
393 template <
typename K_TYPE,
395 typename Compare = increaseComparator<K_TYPE>,
396 typename ALLOC = allocator<couple<const K_TYPE, V_TYPE>>>
398 public map<K_TYPE, V_TYPE, ALLOC>,
399 public iterable<couple<const K_TYPE, V_TYPE>>,
471 [[nodiscard]] std::string
className()
const override;
494 [[nodiscard]]
bool hasNext()
const override;
500 [[nodiscard]]
bool hasPrev()
const override;
519 void next()
const override;
524 void prev()
const override;
554 [[nodiscard]]
bool isValid()
const override;
574 treeMap(
const treeMap& other);
583 treeMap&
operator=(
const treeMap& other);
591 treeMap(treeMap&& other)
noexcept;
601 treeMap&
operator=(treeMap&& other)
noexcept;
614 bool contains(
const couple<const K_TYPE, V_TYPE> &e)
const override;
622 bool add(
const K_TYPE &k,
const V_TYPE &v)
override;
629 bool remove(
const K_TYPE &k)
override;
636 [[nodiscard]]
bool containsKey(
const K_TYPE &k)
const override;
644 V_TYPE
get(
const K_TYPE &k)
const override;
652 bool update(
const K_TYPE &key,
const V_TYPE &value)
override;
660 const V_TYPE &
operator[](
const K_TYPE &k)
const override;
668 V_TYPE &
operator[](
const K_TYPE &k)
override;
674 Iterator*
begins()
const override;
680 Iterator*
ends()
const override;
686 [[nodiscard]] std::string
className()
const override;
693 [[nodiscard]] std::string
toString(
bool enter)
const override;
703template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
705 vector<hashNode *, rebind_alloc_pointer> *buckets, u_integer bucket, hashNode *node)
706 : hashTable<K_TYPE, V_TYPE, ALLOC, HASH>::Iterator(
707 const_cast<vector<hashNode*, rebind_alloc_pointer>*>(buckets), bucket, node) {}
709template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
711 const iterator<couple<const K_TYPE, V_TYPE>>* other)
const {
712 auto other_it =
dynamic_cast<const Iterator*
>(other);
714 this->p_buckets == other_it->p_buckets &&
715 this->cur_bucket == other_it->cur_bucket &&
716 this->p_node == other_it->p_node;
719template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
724template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
734template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
740template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
742 return "hashMap::Iterator";
745template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
750template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
755template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
761template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
766template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
771template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
774 auto other_it =
dynamic_cast<const Iterator*
>(other);
778 auto next =
ownerPtr(this->clone());
779 if (!next->isValid()){
784 return next->equalPtr(other_it);
787template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
790 return other->atPrev(*
this);
793template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
798template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
803template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
809template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
815template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
821template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
826template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
831template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
834 map<K_TYPE, V_TYPE, ALLOC>(std::move(alloc)) {}
836template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
841template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
844 if (
this == &other) {
848 this->buckets = this->bucketsCopy(other.buckets);
849 this->size_ = other.size_;
850 if constexpr(ALLOC::propagate_on_container_copy_assignment::value) {
852 this->rebind_alloc = other.rebind_alloc;
857template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
859 this->operator=(std::move(other));
862template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
865 if (
this == &other) {
869 this->buckets = std::move(other.buckets);
870 this->size_ = other.size_;
872 if constexpr(ALLOC::propagate_on_container_move_assignment::value) {
873 this->
allocator = std::move(other.allocator);
874 this->rebind_alloc = std::move(other.rebind_alloc);
879template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
885template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
891template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
893 return this->insert(k, v);
896template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
898 return this->erase(k);
901template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
903 return this->find(k);
906template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
908 auto node = this->find(k);
911 return node->getValue();
914template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
916 return this->modify(key, value);
919template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
921 auto node = this->find(k);
924 return node->getValue();
927template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
929 auto node = this->find(k);
931 this->insert(k, V_TYPE{});
932 node = this->find(k);
934 return node->getValue();
937template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
941 if (this->buckets[0]) {
942 return new Iterator(p_buckets, 0, this->buckets[0]);
944 auto bucket = Iterator::findNextValidBucket(p_buckets, 0);
945 return new Iterator(p_buckets, bucket, p_buckets->get(bucket));
948template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
952 auto bucket = Iterator::findPrevValidBucket(p_buckets, this->buckets.size());
953 auto node = this->buckets[bucket];
954 while (node && node->getPNext()) {
955 node = node->getPNext();
957 return new Iterator(p_buckets, bucket, node);
960template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
965template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
967 std::stringstream ss;
968 ss << this->className();
971 for (
auto it = this->begin(); it != this->end(); it.next()){
985template<
typename K_TYPE,
typename V_TYPE,
typename HASH,
typename ALLOC>
988template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
990 : RBTreeType::Iterator(tree, cur) {}
992template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
995 const iterator<couple<const K_TYPE, V_TYPE>>* other)
const
997 auto other_it =
dynamic_cast<const Iterator*
>(other);
999 this->tree_ == other_it->tree_ &&
1000 this->cur_ == other_it->cur_;
1003template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1009template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1013 if (
this == &other) {
1017 this->tree_ = other.
tree_;
1018 this->cur_ = other.
cur_;
1022template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1029template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1032 return "treeMap::Iterator";
1035template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1038 RBTreeType::Iterator::operator+=(steps);
1041template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1044 RBTreeType::Iterator::operator-=(steps);
1047template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1055template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1058 return RBTreeType::Iterator::hasNext();
1061template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1064 return RBTreeType::Iterator::hasPrev();
1067template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1071 auto other_it =
dynamic_cast<const Iterator*
>(other);
1075 auto next =
ownerPtr(this->clone());
1076 if (!next->isValid()){
1081 return next->equalPtr(other_it);
1084template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1088 return other->atNext(*
this);
1091template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1094 RBTreeType::Iterator::next();
1097template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1100 RBTreeType::Iterator::prev();
1103template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1107 auto it = this->clone();
1112template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1115 return RBTreeType::Iterator::get();
1118template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1121 return RBTreeType::Iterator::get();
1124template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1130template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1133 return RBTreeType::Iterator::isValid();
1137template<
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1140 map<K_TYPE, V_TYPE, ALLOC>(std::move(alloc)) {}
1142template<
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1147template<
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1150 if (
this == &other){
1154 this->destroyTree();
1155 this->root_ = other.treeCopy();
1156 this->size_ = other.size_;
1157 if constexpr(ALLOC::propagate_on_container_copy_assignment::value) {
1159 this->rebind_alloc = other.rebind_alloc;
1164template<
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1166 this->operator=(std::move(other));
1169template<
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1172 if (
this == &other){
1176 this->root_ = other.root_;
1177 other.root_ =
nullptr;
1178 this->size_ = other.size_;
1180 if constexpr(ALLOC::propagate_on_container_move_assignment::value) {
1181 this->
allocator = std::move(other.allocator);
1182 this->rebind_alloc = std::move(other.rebind_alloc);
1187template<
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1192template<
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1198template<
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1200 return this->insert(k, v);
1203template<
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1205 return this->erase(k);
1208template<
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1210 return this->find(k);
1213template<
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1215 auto node = this->find(k);
1218 return node->getValue();
1221template<
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1223 return this->modify(key, value);
1226template<
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1228 auto node = this->find(k);
1231 return node->getValue();
1234template<
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1236 auto node = this->find(k);
1238 this->insert(k, V_TYPE{});
1239 node = this->find(k);
1241 return node->getValue();
1244template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1251template <
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1258template<
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1263template<
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
1265 std::stringstream ss;
1266 ss << this->className();
1269 for (
auto it = this->begin(); it != this->end(); it.next()){
1283template<
typename K_TYPE,
typename V_TYPE,
typename Compare,
typename ALLOC>
Red-Black Tree implementation header.
Memory allocation interface and implementations.
Bidirectional iterator for RBTree.
Definition RBTree.h:219
RBNode * cur_
Current node.
Definition RBTree.h:222
RBTree * tree_
Owning tree.
Definition RBTree.h:221
Internal node class for Red-Black Tree.
Definition RBTree.h:51
Red-Black Tree container implementation.
Definition RBTree.h:40
Default memory allocator using allocators utilities.
Definition allocator.h:154
A base class for basic iterators.
Definition iterator.h:296
Container for two heterogeneous elements.
Definition couple.h:37
F_TYPE & first()
Access first element.
Definition couple.h:323
S_TYPE & second()
Access second element.
Definition couple.h:329
Bidirectional iterator for hashMap.
Definition maps.h:94
void next() const override
Moves to next element.
Definition maps.h:794
bool atNext(const iterator< couple< const K_TYPE, V_TYPE > > *other) const override
Checks if other is next to this.
Definition maps.h:788
Iterator * getPrev() const override
Not supported.
Definition maps.h:805
Iterator & operator=(const Iterator &other)
Copy assignment operator.
Definition maps.h:726
bool hasNext() const override
Checks if more elements exist.
Definition maps.h:762
bool atPrev(const iterator< couple< const K_TYPE, V_TYPE > > *other) const override
Checks if other is previous to this.
Definition maps.h:772
std::string className() const override
Gets iterator class name.
Definition maps.h:741
void prev() const override
Not supported.
Definition maps.h:799
void operator+=(integer steps) const override
Advances iterator by steps.
Definition maps.h:746
void operator-=(integer steps) const override
Not supported.
Definition maps.h:751
bool isValid() const override
Checks if iterator is valid.
Definition maps.h:827
void set(const couple< const K_TYPE, V_TYPE > &data) override
Not supported.
Definition maps.h:822
Iterator * clone() const override
Creates a copy of this iterator.
Definition maps.h:736
couple< const K_TYPE, V_TYPE > & get() override
Gets current element (non-const)
Definition maps.h:811
bool hasPrev() const override
Not supported.
Definition maps.h:767
Hash table based implementation of the map interface.
Definition maps.h:65
hashMap(HASH hash=HASH{}, ALLOC alloc=ALLOC{})
Constructs empty hashMap.
Definition maps.h:832
u_integer size() const override
Gets number of elements.
Definition maps.h:881
bool add(const K_TYPE &k, const V_TYPE &v) override
Adds new key-value pair.
Definition maps.h:892
bool remove(const K_TYPE &k) override
Removes key-value pair.
Definition maps.h:897
Iterator * ends() const override
Gets end iterator.
Definition maps.h:950
bool contains(const couple< const K_TYPE, V_TYPE > &e) const override
Checks if key-value pair exists.
Definition maps.h:887
bool containsKey(const K_TYPE &k) const override
Checks if key exists.
Definition maps.h:902
std::string className() const override
Gets class name.
Definition maps.h:961
const V_TYPE & operator[](const K_TYPE &k) const override
Const element access.
Definition maps.h:920
bool update(const K_TYPE &key, const V_TYPE &value) override
Updates value for existing key.
Definition maps.h:915
Iterator * begins() const override
Gets begin iterator.
Definition maps.h:939
std::string toString(bool enter) const override
Converts to string representation.
Definition maps.h:966
hashMap & operator=(const hashMap &other)
Copy assignment operator.
Definition maps.h:843
V_TYPE get(const K_TYPE &k) const override
Gets value for key.
Definition maps.h:907
void next() const
Advances to the next element.
Definition hashTable.h:634
couple< const K_TYPE, V_TYPE > & get()
Gets current key-value pair (non-const)
Definition hashTable.h:668
Iterator & operator=(const Iterator &other)
Copy assignment operator.
Definition hashTable.h:615
void operator+=(integer steps) const
Advances iterator by steps positions.
Definition hashTable.h:656
bool isValid() const
Checks if iterator points to valid element.
Definition hashTable.h:687
bool hasNext() const
Checks if more elements are available.
Definition hashTable.h:625
Internal node type for hash table storage.
Definition hashTable.h:71
Hash table implementation with separate chaining.
Definition hashTable.h:55
typename ALLOC::template rebind_alloc< hashNode * > rebind_alloc_pointer
Rebound allocator type for pointer storage.
Definition hashTable.h:174
Forward declaration of hash class template.
Definition hash.h:80
A base class for iterable containers that support multiple iteration patterns.
Definition iterable.h:59
Base iterator interface that supports common operations for iteration.
Definition iterator.h:37
friend iterator< T > * operator-(const iterator< T > &it, integer steps)
Subtracts a number of steps from the iterator's current position and returns a new iterator.
Abstract base class for key-value mapping containers.
Definition map.h:49
Exception for missing element requests.
Definition error.h:136
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:30
Base class providing polymorphic string conversion capabilities.
Definition printable.h:29
static std::string formatString(const TYPE &t)
Universal value-to-string conversion.
Abstract base class for unique element containers.
Definition set.h:44
Bidirectional iterator for treeMap.
Definition maps.h:429
couple< const K_TYPE, V_TYPE > & get() override
Gets current element (non-const)
Definition maps.h:1113
bool hasNext() const override
Checks if more elements exist in forward direction.
Definition maps.h:1056
void next() const override
Moves to next element.
Definition maps.h:1092
bool atNext(const iterator< couple< const K_TYPE, V_TYPE > > *other) const override
Checks if other is next to this.
Definition maps.h:1085
bool atPrev(const iterator< couple< const K_TYPE, V_TYPE > > *other) const override
Checks if other is previous to this.
Definition maps.h:1068
void operator-=(integer steps) const override
Rewinds iterator by steps.
Definition maps.h:1042
Iterator * getPrev() const override
Gets previous iterator.
Definition maps.h:1105
std::string className() const override
Gets iterator class name.
Definition maps.h:1030
Iterator * clone() const override
Creates a copy of this iterator.
Definition maps.h:1024
bool isValid() const override
Checks if iterator is valid.
Definition maps.h:1131
void prev() const override
Moves to previous element.
Definition maps.h:1098
Iterator & operator=(const Iterator &other)
Copy assignment operator.
Definition maps.h:1011
void operator+=(integer steps) const override
Advances iterator by steps.
Definition maps.h:1036
bool hasPrev() const override
Checks if more elements exist in backward direction.
Definition maps.h:1062
void set(const couple< const K_TYPE, V_TYPE > &data) override
Not supported.
Definition maps.h:1125
Red-Black Tree based implementation of the map interface.
Definition maps.h:400
Iterator * begins() const override
Gets begin iterator.
Definition maps.h:1246
treeMap & operator=(const treeMap &other)
Copy assignment operator.
Definition maps.h:1149
std::string className() const override
Gets class name.
Definition maps.h:1259
Iterator * ends() const override
Gets end iterator.
Definition maps.h:1253
bool containsKey(const K_TYPE &k) const override
Checks if key exists.
Definition maps.h:1209
V_TYPE get(const K_TYPE &k) const override
Gets value for key.
Definition maps.h:1214
~treeMap() override
Destructor.
std::string toString(bool enter) const override
Converts to string representation.
Definition maps.h:1264
bool contains(const couple< const K_TYPE, V_TYPE > &e) const override
Checks if key-value pair exists.
Definition maps.h:1194
bool remove(const K_TYPE &k) override
Removes key-value pair.
Definition maps.h:1204
bool add(const K_TYPE &k, const V_TYPE &v) override
Adds new key-value pair.
Definition maps.h:1199
const V_TYPE & operator[](const K_TYPE &k) const override
Const element access.
Definition maps.h:1227
bool update(const K_TYPE &key, const V_TYPE &value) override
Updates value for existing key.
Definition maps.h:1222
treeMap(Compare comp=Compare{}, ALLOC alloc=ALLOC{})
Constructs empty treeMap.
Definition maps.h:1138
u_integer size() const override
Gets number of elements.
Definition maps.h:1188
Exception for unimplemented method calls.
Definition error.h:123
Dynamic array container with amortized constant time operations.
Definition vector.h:43
Comparator base class and concrete comparator classes.
Combines Comparable and CallbackOf for comparison callbacks.
Definition types.h:92
Generic pair container implementation.
Implementation of hashTable container.
Provides a generic hashing utility and a base interface for hashable types.
Abstract base class for map-like container implementations.
Main namespace for the project Original.
Definition algorithms.h:21
std::uint32_t u_integer
32-bit unsigned integer type for sizes and indexes
Definition config.h:43
std::int64_t integer
64-bit signed integer type for arithmetic operations
Definition config.h:35
Exclusive-ownership smart pointer implementation.