ORIGINAL
Loading...
Searching...
No Matches
maps.h
Go to the documentation of this file.
1#ifndef MAPS_H
2#define MAPS_H
3
4#include "allocator.h"
5#include "couple.h"
6#include "hash.h"
7#include "hashTable.h"
8#include "map.h"
9#include "ownerPtr.h"
10#include "comparator.h"
11#include "RBTree.h"
12
13
31namespace original {
32
57 template <typename K_TYPE,
58 typename V_TYPE,
59 typename HASH = hash<K_TYPE>,
60 typename ALLOC = allocator<couple<const K_TYPE, V_TYPE>>>
61 class hashMap final
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>>,
65 public printable{
66
72
77 using rebind_alloc_pointer = typename hashTable<K_TYPE, V_TYPE, ALLOC, HASH>::rebind_alloc_pointer;
78 public:
79
93 class Iterator final : public hashTable<K_TYPE, V_TYPE, ALLOC, HASH>::Iterator,
94 public baseIterator<couple<const K_TYPE, V_TYPE>> {
95
103 explicit Iterator(vector<hashNode*, rebind_alloc_pointer>* buckets = nullptr,
104 u_integer bucket = 0, hashNode* node = nullptr);
105
112 bool equalPtr(const iterator<couple<const K_TYPE, V_TYPE>>* other) const override;
113 public:
114 friend class hashMap;
115
120 Iterator(const Iterator& other);
121
127 Iterator& operator=(const Iterator& other);
128
133 Iterator* clone() const override;
134
139 [[nodiscard]] std::string className() const override;
140
146 void operator+=(integer steps) const override;
147
152 void operator-=(integer steps) const override;
153
158 integer operator-(const iterator<couple<const K_TYPE, V_TYPE>> &other) const override;
159
164 [[nodiscard]] bool hasNext() const override;
165
170 [[nodiscard]] bool hasPrev() const override;
171
177 bool atPrev(const iterator<couple<const K_TYPE, V_TYPE>>* other) const override;
178
184 bool atNext(const iterator<couple<const K_TYPE, V_TYPE>>* other) const override;
185
189 void next() const override;
190
195 void prev() const override;
196
201 Iterator* getPrev() const override;
202
208
213 couple<const K_TYPE, V_TYPE> get() const override;
214
219 void set(const couple<const K_TYPE, V_TYPE> &data) override;
220
225 [[nodiscard]] bool isValid() const override;
226
227 ~Iterator() override = default;
228 };
229
235 explicit hashMap(HASH hash = HASH{}, ALLOC alloc = ALLOC{});
236
243 hashMap(const hashMap& other);
244
252 hashMap& operator=(const hashMap& other);
253
260 hashMap(hashMap&& other) noexcept;
261
270 hashMap& operator=(hashMap&& other) noexcept;
271
276 [[nodiscard]] u_integer size() const override;
277
283 bool contains(const couple<const K_TYPE, V_TYPE> &e) const override;
284
291 bool add(const K_TYPE &k, const V_TYPE &v) override;
292
298 bool remove(const K_TYPE &k) override;
299
305 [[nodiscard]] bool containsKey(const K_TYPE &k) const override;
306
313 V_TYPE get(const K_TYPE &k) const override;
314
321 bool update(const K_TYPE &key, const V_TYPE &value) override;
322
329 const V_TYPE & operator[](const K_TYPE &k) const override;
330
337 V_TYPE & operator[](const K_TYPE &k) override;
338
343 Iterator* begins() const override;
344
349 Iterator* ends() const override;
350
355 [[nodiscard]] std::string className() const override;
356
362 [[nodiscard]] std::string toString(bool enter) const override;
363
364 ~hashMap() override;
365 };
366
393 template <typename K_TYPE,
394 typename V_TYPE,
395 typename Compare = increaseComparator<K_TYPE>,
396 typename ALLOC = allocator<couple<const K_TYPE, V_TYPE>>>
397 class treeMap final : public RBTree<K_TYPE, V_TYPE, ALLOC, Compare>,
398 public map<K_TYPE, V_TYPE, ALLOC>,
399 public iterable<couple<const K_TYPE, V_TYPE>>,
400 public printable {
401
407
412 using RBNode = typename RBTreeType::RBNode;
413 public:
414
428 class Iterator final : public RBTreeType::Iterator,
429 public baseIterator<couple<const K_TYPE, V_TYPE>> {
436 explicit Iterator(RBTreeType* tree, RBNode* cur);
437
444 bool equalPtr(const iterator<couple<const K_TYPE, V_TYPE>>* other) const override;
445 public:
446 friend class treeMap;
447
452 Iterator(const Iterator& other);
453
459 Iterator& operator=(const Iterator& other);
460
465 Iterator* clone() const override;
466
471 [[nodiscard]] std::string className() const override;
472
477 void operator+=(integer steps) const override;
478
483 void operator-=(integer steps) const override;
484
488 integer operator-(const iterator<couple<const K_TYPE, V_TYPE>> &other) const override;
489
494 [[nodiscard]] bool hasNext() const override;
495
500 [[nodiscard]] bool hasPrev() const override;
501
507 bool atPrev(const iterator<couple<const K_TYPE, V_TYPE>>* other) const override;
508
514 bool atNext(const iterator<couple<const K_TYPE, V_TYPE>>* other) const override;
515
519 void next() const override;
520
524 void prev() const override;
525
530 Iterator* getPrev() const override;
531
537
542 couple<const K_TYPE, V_TYPE> get() const override;
543
548 void set(const couple<const K_TYPE, V_TYPE> &data) override;
549
554 [[nodiscard]] bool isValid() const override;
555
556 ~Iterator() override = default;
557 };
558
559 friend class Iterator;
560
566 explicit treeMap(Compare comp = Compare{}, ALLOC alloc = ALLOC{});
567
574 treeMap(const treeMap& other);
575
583 treeMap& operator=(const treeMap& other);
584
591 treeMap(treeMap&& other) noexcept;
592
601 treeMap& operator=(treeMap&& other) noexcept;
602
607 [[nodiscard]] u_integer size() const override;
608
614 bool contains(const couple<const K_TYPE, V_TYPE> &e) const override;
615
622 bool add(const K_TYPE &k, const V_TYPE &v) override;
623
629 bool remove(const K_TYPE &k) override;
630
636 [[nodiscard]] bool containsKey(const K_TYPE &k) const override;
637
644 V_TYPE get(const K_TYPE &k) const override;
645
652 bool update(const K_TYPE &key, const V_TYPE &value) override;
653
660 const V_TYPE & operator[](const K_TYPE &k) const override;
661
668 V_TYPE & operator[](const K_TYPE &k) override;
669
674 Iterator* begins() const override;
675
680 Iterator* ends() const override;
681
686 [[nodiscard]] std::string className() const override;
687
693 [[nodiscard]] std::string toString(bool enter) const override;
694
699 ~treeMap() override;
700 };
701}
702
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) {}
708
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);
713 return other_it &&
714 this->p_buckets == other_it->p_buckets &&
715 this->cur_bucket == other_it->cur_bucket &&
716 this->p_node == other_it->p_node;
717}
718
719template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
723
724template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
727 if (this == &other)
728 return *this;
729
731 return *this;
732}
733
734template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
739
740template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
742 return "hashMap::Iterator";
743}
744
745template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
749
750template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
754
755template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
760
761template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
765
766template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
770
771template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
773 const iterator<couple<const K_TYPE, V_TYPE>> *other) const {
774 auto other_it = dynamic_cast<const Iterator*>(other);
775 if (!other_it) {
776 return false;
777 }
778 auto next = ownerPtr(this->clone());
779 if (!next->isValid()){
780 return false;
781 }
782
783 next->next();
784 return next->equalPtr(other_it);
785}
786
787template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
789 const iterator<couple<const K_TYPE, V_TYPE>> *other) const {
790 return other->atPrev(*this);
791}
792
793template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
797
798template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
802
803template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
808
809template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
814
815template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
820
821template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
825
826template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
830
831template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
833 : hashTable<K_TYPE, V_TYPE, ALLOC, HASH>(std::move(hash)),
834 map<K_TYPE, V_TYPE, ALLOC>(std::move(alloc)) {}
835
836template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
840
841template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
844 if (this == &other) {
845 return *this;
846 }
847
848 this->buckets = this->bucketsCopy(other.buckets);
849 this->size_ = other.size_;
850 if constexpr(ALLOC::propagate_on_container_copy_assignment::value) {
851 this->allocator = other.allocator;
852 this->rebind_alloc = other.rebind_alloc;
853 }
854 return *this;
855}
856
857template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
859 this->operator=(std::move(other));
860}
861
862template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
865 if (this == &other) {
866 return *this;
867 }
868
869 this->buckets = std::move(other.buckets);
870 this->size_ = other.size_;
871 other.size_ = 0;
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);
875 }
876 return *this;
877}
878
879template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
882 return this->size_;
883}
884
885template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
886bool
888 return this->containsKey(e.first()) && this->get(e.first()) == e.second();
889}
890
891template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
892bool original::hashMap<K_TYPE, V_TYPE, HASH, ALLOC>::add(const K_TYPE &k, const V_TYPE &v) {
893 return this->insert(k, v);
894}
895
896template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
898 return this->erase(k);
899}
900
901template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
903 return this->find(k);
904}
905
906template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
908 auto node = this->find(k);
909 if (!node)
910 throw noElementError();
911 return node->getValue();
912}
913
914template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
915bool original::hashMap<K_TYPE, V_TYPE, HASH, ALLOC>::update(const K_TYPE &key, const V_TYPE &value) {
916 return this->modify(key, value);
917}
918
919template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
921 auto node = this->find(k);
922 if (!node)
923 throw noElementError();
924 return node->getValue();
925}
926
927template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
929 auto node = this->find(k);
930 if (!node) {
931 this->insert(k, V_TYPE{});
932 node = this->find(k);
933 }
934 return node->getValue();
935}
936
937template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
940 auto p_buckets = const_cast<vector<hashNode*, rebind_alloc_pointer>*>(&this->buckets);
941 if (this->buckets[0]) {
942 return new Iterator(p_buckets, 0, this->buckets[0]);
943 }
944 auto bucket = Iterator::findNextValidBucket(p_buckets, 0);
945 return new Iterator(p_buckets, bucket, p_buckets->get(bucket));
946}
947
948template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
951 auto p_buckets = const_cast<vector<hashNode*, rebind_alloc_pointer>*>(&this->buckets);
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();
956 }
957 return new Iterator(p_buckets, bucket, node);
958}
959
960template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
962 return "hashMap";
963}
964
965template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
967 std::stringstream ss;
968 ss << this->className();
969 ss << "(";
970 bool first = true;
971 for (auto it = this->begin(); it != this->end(); it.next()){
972 if (!first){
973 ss << ", ";
974 }
975 ss << "{" << printable::formatString(it.get().template get<0>()) << ": "
976 << printable::formatString(it.get().template get<1>()) << "}";
977 first = false;
978 }
979 ss << ")";
980 if (enter)
981 ss << "\n";
982 return ss.str();
983}
984
985template<typename K_TYPE, typename V_TYPE, typename HASH, typename ALLOC>
987
988template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
990 : RBTreeType::Iterator(tree, cur) {}
991
992template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
993bool
995 const iterator<couple<const K_TYPE, V_TYPE>>* other) const
996{
997 auto other_it = dynamic_cast<const Iterator*>(other);
998 return other_it &&
999 this->tree_ == other_it->tree_ &&
1000 this->cur_ == other_it->cur_;
1001}
1002
1003template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1005{
1006 this->operator=(other);
1007}
1008
1009template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1012{
1013 if (this == &other) {
1014 return *this;
1015 }
1016
1017 this->tree_ = other.tree_;
1018 this->cur_ = other.cur_;
1019 return *this;
1020}
1021
1022template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1028
1029template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1031{
1032 return "treeMap::Iterator";
1033}
1034
1035template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1037{
1038 RBTreeType::Iterator::operator+=(steps);
1039}
1040
1041template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1043{
1044 RBTreeType::Iterator::operator-=(steps);
1045}
1046
1047template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1054
1055template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1057{
1058 return RBTreeType::Iterator::hasNext();
1059}
1060
1061template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1063{
1064 return RBTreeType::Iterator::hasPrev();
1065}
1066
1067template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1069 const iterator<couple<const K_TYPE, V_TYPE>>* other) const
1070{
1071 auto other_it = dynamic_cast<const Iterator*>(other);
1072 if (!other_it) {
1073 return false;
1074 }
1075 auto next = ownerPtr(this->clone());
1076 if (!next->isValid()){
1077 return false;
1078 }
1079
1080 next->next();
1081 return next->equalPtr(other_it);
1082}
1083
1084template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1086 const iterator<couple<const K_TYPE, V_TYPE>>* other) const
1087{
1088 return other->atNext(*this);
1089}
1090
1091template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1093{
1094 RBTreeType::Iterator::next();
1095}
1096
1097template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1099{
1100 RBTreeType::Iterator::prev();
1101}
1102
1103template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1106{
1107 auto it = this->clone();
1108 it->prev();
1109 return it;
1110}
1111
1112template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1117
1118template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1123
1124template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1129
1130template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1132{
1133 return RBTreeType::Iterator::isValid();
1134}
1135
1136
1137template<typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1139 : RBTreeType(std::move(comp)),
1140 map<K_TYPE, V_TYPE, ALLOC>(std::move(alloc)) {}
1141
1142template<typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1146
1147template<typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1150 if (this == &other){
1151 return *this;
1152 }
1153
1154 this->destroyTree();
1155 this->root_ = other.treeCopy();
1156 this->size_ = other.size_;
1157 if constexpr(ALLOC::propagate_on_container_copy_assignment::value) {
1158 this->allocator = other.allocator;
1159 this->rebind_alloc = other.rebind_alloc;
1160 }
1161 return *this;
1162}
1163
1164template<typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1166 this->operator=(std::move(other));
1167}
1168
1169template<typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1172 if (this == &other){
1173 return *this;
1174 }
1175
1176 this->root_ = other.root_;
1177 other.root_ = nullptr;
1178 this->size_ = other.size_;
1179 other.size_ = 0;
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);
1183 }
1184 return *this;
1185}
1186
1187template<typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1191
1192template<typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1193bool
1195 return this->containsKey(e.first()) && this->get(e.first()) == e.second();
1196}
1197
1198template<typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1199bool original::treeMap<K_TYPE, V_TYPE, Compare, ALLOC>::add(const K_TYPE &k, const V_TYPE &v) {
1200 return this->insert(k, v);
1201}
1202
1203template<typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1205 return this->erase(k);
1206}
1207
1208template<typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1210 return this->find(k);
1211}
1212
1213template<typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1215 auto node = this->find(k);
1216 if (!node)
1217 throw noElementError();
1218 return node->getValue();
1219}
1220
1221template<typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1222bool original::treeMap<K_TYPE, V_TYPE, Compare, ALLOC>::update(const K_TYPE &key, const V_TYPE &value) {
1223 return this->modify(key, value);
1224}
1225
1226template<typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1228 auto node = this->find(k);
1229 if (!node)
1230 throw noElementError();
1231 return node->getValue();
1232}
1233
1234template<typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1236 auto node = this->find(k);
1237 if (!node) {
1238 this->insert(k, V_TYPE{});
1239 node = this->find(k);
1240 }
1241 return node->getValue();
1242}
1243
1244template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1247{
1248 return new Iterator(const_cast<treeMap*>(this), this->getMinNode());
1249}
1250
1251template <typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1254{
1255 return new Iterator(const_cast<treeMap*>(this), this->getMaxNode());
1256}
1257
1258template<typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1260 return "treeMap";
1261}
1262
1263template<typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1265 std::stringstream ss;
1266 ss << this->className();
1267 ss << "(";
1268 bool first = true;
1269 for (auto it = this->begin(); it != this->end(); it.next()){
1270 if (!first){
1271 ss << ", ";
1272 }
1273 ss << "{" << printable::formatString(it.get().template get<0>()) << ": "
1274 << printable::formatString(it.get().template get<1>()) << "}";
1275 first = false;
1276 }
1277 ss << ")";
1278 if (enter)
1279 ss << "\n";
1280 return ss.str();
1281}
1282
1283template<typename K_TYPE, typename V_TYPE, typename Compare, typename ALLOC>
1285
1286#endif //MAPS_H
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.