ORIGINAL
Loading...
Searching...
No Matches
sets.h
Go to the documentation of this file.
1#ifndef SETS_H
2#define SETS_H
3
4#include "allocator.h"
5#include "couple.h"
6#include "hash.h"
7#include "hashTable.h"
8#include "set.h"
9#include "ownerPtr.h"
10#include "comparator.h"
11#include "RBTree.h"
12#include "skipList.h"
13
14
62namespace original {
86 template <typename TYPE,
87 typename HASH = hash<TYPE>,
88 typename ALLOC = allocator<couple<const TYPE, const bool>>>
89 class hashSet final : public hashTable<TYPE, const bool, ALLOC, HASH>,
90 public set<TYPE, ALLOC>,
91 public iterable<const TYPE>,
92 public printable{
93
99
105
106 public:
120 class Iterator final : public hashTable<TYPE, const bool, ALLOC, HASH>::Iterator,
121 public baseIterator<const TYPE> {
122
130 explicit Iterator(vector<hashNode*, rebind_alloc_pointer>* buckets = nullptr,
131 u_integer bucket = 0, hashNode* node = nullptr);
132
139 bool equalPtr(const iterator<const TYPE>* other) const override;
140
141 public:
142 friend class hashSet;
143
148 Iterator(const Iterator& other);
149
156
161 Iterator* clone() const override;
162
167 [[nodiscard]] std::string className() const override;
168
174 void operator+=(integer steps) const override;
175
179 void operator-=(integer steps) const override;
180
184 integer operator-(const iterator<const TYPE>& other) const override;
185
190 [[nodiscard]] bool hasNext() const override;
191
195 [[nodiscard]] bool hasPrev() const override;
196
202 bool atPrev(const iterator<const TYPE>* other) const override;
203
209 bool atNext(const iterator<const TYPE>* other) const override;
210
214 void next() const override;
215
219 void prev() const override;
220
224 Iterator* getPrev() const override;
225
230 const TYPE& get() override;
231
236 const TYPE get() const override;
237
241 void set(const TYPE& data) override;
242
247 [[nodiscard]] bool isValid() const override;
248
249 ~Iterator() override = default;
250 };
251
257 explicit hashSet(HASH hash = HASH{}, ALLOC alloc = ALLOC{});
258
265 hashSet(const hashSet& other);
266
274 hashSet& operator=(const hashSet& other);
275
282 hashSet(hashSet&& other) noexcept;
283
292 hashSet& operator=(hashSet&& other) noexcept;
293
315 void swap(hashSet& other) noexcept;
316
321 [[nodiscard]] u_integer size() const override;
322
328 bool contains(const TYPE &e) const override;
329
335 bool add(const TYPE &e) override;
336
342 bool remove(const TYPE &e) override;
343
348 Iterator* begins() const override;
349
354 Iterator* ends() const override;
355
360 [[nodiscard]] std::string className() const override;
361
367 [[nodiscard]] std::string toString(bool enter) const override;
368
369 ~hashSet() override;
370 };
371
397 template <typename TYPE,
398 typename Compare = increaseComparator<TYPE>,
399 typename ALLOC = allocator<couple<const TYPE, const bool>>>
400 class treeSet final : public RBTree<TYPE, const bool, ALLOC, Compare>,
401 public set<TYPE, ALLOC>,
402 public iterable<const TYPE>,
403 public printable {
405
411 public:
426 public baseIterator<const TYPE>
427 {
434 explicit Iterator(RBTreeType* tree, RBNode* cur);
435
442 bool equalPtr(const iterator<const TYPE>* other) const override;
443 public:
444 friend class treeSet;
445
450 Iterator(const Iterator& other);
451
458
463 Iterator* clone() const override;
464
469 [[nodiscard]] std::string className() const override;
470
475 void operator+=(integer steps) const override;
476
481 void operator-=(integer steps) const override;
482
486 integer operator-(const iterator<const TYPE> &other) const override;
487
492 [[nodiscard]] bool hasNext() const override;
493
498 [[nodiscard]] bool hasPrev() const override;
499
505 bool atPrev(const iterator<const TYPE>* other) const override;
506
512 bool atNext(const iterator<const TYPE>* other) const override;
513
517 void next() const override;
518
522 void prev() const override;
523
528 Iterator* getPrev() const override;
529
534 const TYPE& get() override;
535
540 const TYPE get() const override;
541
546 void set(const TYPE& data) override;
547
552 [[nodiscard]] bool isValid() const override;
553
554 ~Iterator() override = default;
555 };
556
557 friend class Iterator;
558
564 explicit treeSet(Compare comp = Compare{}, ALLOC alloc = ALLOC{});
565
572 treeSet(const treeSet& other);
573
581 treeSet& operator=(const treeSet& other);
582
589 treeSet(treeSet&& other) noexcept;
590
599 treeSet& operator=(treeSet&& other) noexcept;
600
622 void swap(treeSet& other) noexcept;
623
628 [[nodiscard]] u_integer size() const override;
629
635 bool contains(const TYPE &e) const override;
636
642 bool add(const TYPE &e) override;
643
649 bool remove(const TYPE &e) override;
650
655 Iterator* begins() const override;
656
661 Iterator* ends() const override;
662
667 [[nodiscard]] std::string className() const override;
668
674 [[nodiscard]] std::string toString(bool enter) const override;
675
680 ~treeSet() override;
681 };
682
683
708 template <typename TYPE,
711 class JSet final : public skipList<const TYPE, const bool, ALLOC, Compare>,
712 public set<TYPE, ALLOC>,
713 public iterable<const TYPE>,
714 public printable {
716
722
723 public:
738 public baseIterator<const TYPE> {
739
746 bool equalPtr(const iterator<const TYPE>* other) const override;
747
748 public:
749 friend class JSet;
750
756 explicit Iterator(skipListNode* cur);
757
762 Iterator(const Iterator& other);
763
770
775 Iterator* clone() const override;
776
781 [[nodiscard]] std::string className() const override;
782
787 void operator+=(integer steps) const override;
788
792 void operator-=(integer steps) const override;
793
800 integer operator-(const iterator<const TYPE>& other) const override;
801
806 [[nodiscard]] bool hasNext() const override;
807
811 [[nodiscard]] bool hasPrev() const override;
812
818 bool atPrev(const iterator<const TYPE>* other) const override;
819
825 bool atNext(const iterator<const TYPE>* other) const override;
826
830 void next() const override;
831
835 void prev() const override;
836
840 Iterator* getPrev() const override;
841
846 const TYPE& get() override;
847
852 const TYPE get() const override;
853
857 void set(const TYPE& data) override;
858
863 [[nodiscard]] bool isValid() const override;
864
865 ~Iterator() override = default;
866 };
867
868 friend class Iterator;
869
875 explicit JSet(Compare comp = Compare{}, ALLOC alloc = ALLOC{});
876
883 JSet(const JSet& other);
884
892 JSet& operator=(const JSet& other);
893
900 JSet(JSet&& other) noexcept;
901
910 JSet& operator=(JSet&& other) noexcept;
911
933 void swap(JSet& other) noexcept;
934
939 [[nodiscard]] u_integer size() const override;
940
946 bool contains(const TYPE &e) const override;
947
953 bool add(const TYPE &e) override;
954
961 bool remove(const TYPE &e) override;
962
968 Iterator* begins() const override;
969
975 Iterator* ends() const override;
976
981 [[nodiscard]] std::string className() const override;
982
989 [[nodiscard]] std::string toString(bool enter) const override;
990
996 ~JSet() override;
997 };
998}
999
1000namespace std {
1021 template <typename TYPE, typename HASH, typename ALLOC>
1022 void swap(original::hashSet<TYPE, HASH, ALLOC>& lhs, // NOLINT
1024
1045 template <typename TYPE, typename COMPARE, typename ALLOC>
1048
1069 template <typename TYPE, typename COMPARE, typename ALLOC>
1070 void swap(original::JSet<TYPE, COMPARE, ALLOC>& lhs, // NOLINT
1072}
1073
1074template<typename TYPE, typename HASH, typename ALLOC>
1075original::hashSet<TYPE, HASH, ALLOC>::Iterator::Iterator(vector<hashNode*, rebind_alloc_pointer> *buckets,
1076u_integer bucket, hashNode *node) : hashTable<TYPE, const bool, ALLOC, HASH>::Iterator(
1077 const_cast<vector<hashNode*, rebind_alloc_pointer>*>(buckets), bucket, node) {}
1078
1079template<typename TYPE, typename HASH, typename ALLOC>
1080bool original::hashSet<TYPE, HASH, ALLOC>::Iterator::equalPtr(const iterator<const TYPE> *other) const {
1081 auto other_it = dynamic_cast<const Iterator*>(other);
1082 return other_it &&
1083 this->p_buckets == other_it->p_buckets &&
1084 this->cur_bucket == other_it->cur_bucket &&
1085 this->p_node == other_it->p_node;
1086}
1087
1088template<typename TYPE, typename HASH, typename ALLOC>
1092
1093template<typename TYPE, typename HASH, typename ALLOC>
1096 if (this == &other) {
1097 return *this;
1098 }
1099
1101 return *this;
1102}
1103
1104template<typename TYPE, typename HASH, typename ALLOC>
1109
1110template<typename TYPE, typename HASH, typename ALLOC>
1112 return "hashSet::Iterator";
1113}
1114
1115template<typename TYPE, typename HASH, typename ALLOC>
1119
1120template<typename TYPE, typename HASH, typename ALLOC>
1124
1125template<typename TYPE, typename HASH, typename ALLOC>
1130
1131template<typename TYPE, typename HASH, typename ALLOC>
1135
1136template<typename TYPE, typename HASH, typename ALLOC>
1140
1141template<typename TYPE, typename HASH, typename ALLOC>
1143 auto other_it = dynamic_cast<const Iterator*>(other);
1144 if (!other_it) {
1145 return false;
1146 }
1147 auto next = ownerPtr(this->clone());
1148 if (!next->isValid()){
1149 return false;
1150 }
1151
1152 next->next();
1153 return next->equalPtr(other_it);
1154}
1155
1156template<typename TYPE, typename HASH, typename ALLOC>
1160
1161template<typename TYPE, typename HASH, typename ALLOC>
1165
1166template<typename TYPE, typename HASH, typename ALLOC>
1170
1171template<typename TYPE, typename HASH, typename ALLOC>
1176
1177template<typename TYPE, typename HASH, typename ALLOC>
1181
1182template<typename TYPE, typename HASH, typename ALLOC>
1186
1187template<typename TYPE, typename HASH, typename ALLOC>
1191
1192template<typename TYPE, typename HASH, typename ALLOC>
1196
1197template<typename TYPE, typename HASH, typename ALLOC>
1201
1202template<typename TYPE, typename HASH, typename ALLOC>
1206
1207template<typename TYPE, typename HASH, typename ALLOC>
1210 if (this == &other) {
1211 return *this;
1212 }
1213
1214 this->buckets = this->bucketsCopy(other.buckets);
1215 this->size_ = other.size_;
1216 this->hash_ = other.hash_;
1217 if constexpr(ALLOC::propagate_on_container_copy_assignment::value) {
1218 this->allocator = other.allocator;
1219 this->rebind_alloc = other.rebind_alloc;
1220 }
1221 return *this;
1222}
1223
1224template<typename TYPE, typename HASH, typename ALLOC>
1226 this->operator=(std::move(other));
1227}
1228
1229template<typename TYPE, typename HASH, typename ALLOC>
1232 if (this == &other) {
1233 return *this;
1234 }
1235
1236 this->buckets = std::move(other.buckets);
1237 this->size_ = other.size_;
1238 other.size_ = 0;
1239 this->hash_ = std::move(other.hash_);
1240 if constexpr(ALLOC::propagate_on_container_move_assignment::value) {
1241 this->allocator = std::move(other.allocator);
1242 this->rebind_alloc = std::move(other.rebind_alloc);
1243 }
1244 return *this;
1245}
1246
1247template<typename TYPE, typename HASH, typename ALLOC>
1249{
1250 if (this == &other)
1251 return;
1252
1253 std::swap(this->size_, other.size_);
1254 std::swap(this->buckets, other.buckets);
1255 std::swap(this->hash_, other.hash_);
1256 if constexpr (ALLOC::propagate_on_container_swap::value) {
1257 std::swap(this->allocator, other.allocator);
1258 std::swap(this->rebind_alloc, other.rebind_alloc);
1259 }
1260}
1261
1262template<typename TYPE, typename HASH, typename ALLOC>
1266
1267template<typename TYPE, typename HASH, typename ALLOC>
1269 return this->find(e);
1270}
1271
1272template<typename TYPE, typename HASH, typename ALLOC>
1274 return this->insert(e, true);
1275}
1276
1277template<typename TYPE, typename HASH, typename ALLOC>
1279 return this->erase(e);
1280}
1281
1282template<typename TYPE, typename HASH, typename ALLOC>
1285 auto p_buckets = const_cast<vector<hashNode*, rebind_alloc_pointer>*>(&this->buckets);
1286 if (this->buckets[0]) {
1287 return new Iterator(p_buckets, 0, this->buckets[0]);
1288 }
1289 auto bucket = Iterator::findNextValidBucket(p_buckets, 0);
1290 return new Iterator(p_buckets, bucket, p_buckets->get(bucket));
1291}
1292
1293template<typename TYPE, typename HASH, typename ALLOC>
1296 auto p_buckets = const_cast<vector<hashNode*, rebind_alloc_pointer>*>(&this->buckets);
1297 auto bucket = Iterator::findPrevValidBucket(p_buckets, this->buckets.size());
1298 auto node = this->buckets[bucket];
1299 while (node && node->getPNext()) {
1300 node = node->getPNext();
1301 }
1302 return new Iterator(p_buckets, bucket, node);
1303}
1304
1305template<typename TYPE, typename HASH, typename ALLOC>
1307 return "hashSet";
1308}
1309
1310template<typename TYPE, typename HASH, typename ALLOC>
1312 std::stringstream ss;
1313 ss << this->className();
1314 ss << "(";
1315 bool first = true;
1316 for (auto it = this->begin(); it != this->end(); it.next()){
1317 if (!first){
1318 ss << ", ";
1319 }
1321 first = false;
1322 }
1323 ss << ")";
1324 if (enter)
1325 ss << "\n";
1326 return ss.str();
1327}
1328
1329template<typename TYPE, typename HASH, typename ALLOC>
1331
1332template <typename TYPE, typename Compare, typename ALLOC>
1334 : RBTreeType::Iterator(tree, cur) {}
1335
1336template <typename TYPE, typename Compare, typename ALLOC>
1337bool original::treeSet<TYPE, Compare, ALLOC>::Iterator::equalPtr(const iterator<const TYPE>* other) const
1338{
1339 auto other_it = dynamic_cast<const Iterator*>(other);
1340 return other_it &&
1341 this->tree_ == other_it->tree_ &&
1342 this->cur_ == other_it->cur_;
1343}
1344
1345template <typename TYPE, typename Compare, typename ALLOC>
1351
1352template <typename TYPE, typename Compare, typename ALLOC>
1355{
1356 if (this == &other) {
1357 return *this;
1358 }
1359
1360 this->tree_ = other.tree_;
1361 this->cur_ = other.cur_;
1362 return *this;
1363}
1364
1365template <typename TYPE, typename Compare, typename ALLOC>
1368{
1369 return new Iterator(*this);
1370}
1371
1372template <typename TYPE, typename Compare, typename ALLOC>
1374{
1375 return "treeSet::Iterator";
1376}
1377
1378template <typename TYPE, typename Compare, typename ALLOC>
1380{
1381 RBTreeType::Iterator::operator+=(steps);
1382}
1383
1384template <typename TYPE, typename Compare, typename ALLOC>
1386{
1387 RBTreeType::Iterator::operator-=(steps);
1388}
1389
1390template <typename TYPE, typename Compare, typename ALLOC>
1396
1397template <typename TYPE, typename Compare, typename ALLOC>
1399{
1400 return RBTreeType::Iterator::hasNext();
1401}
1402
1403template <typename TYPE, typename Compare, typename ALLOC>
1405{
1406 return RBTreeType::Iterator::hasPrev();
1407}
1408
1409template <typename TYPE, typename Compare, typename ALLOC>
1411{
1412 auto other_it = dynamic_cast<const Iterator*>(other);
1413 if (!other_it) {
1414 return false;
1415 }
1416 auto next = ownerPtr(this->clone());
1417 if (!next->isValid()){
1418 return false;
1419 }
1420
1421 next->next();
1422 return next->equalPtr(other_it);
1423}
1424
1425template <typename TYPE, typename Compare, typename ALLOC>
1427{
1428 return other->atNext(*this);
1429}
1430
1431template <typename TYPE, typename Compare, typename ALLOC>
1433{
1434 RBTreeType::Iterator::next();
1435}
1436
1437template <typename TYPE, typename Compare, typename ALLOC>
1439{
1440 RBTreeType::Iterator::prev();
1441}
1442
1443template <typename TYPE, typename Compare, typename ALLOC>
1446{
1447 auto it = this->clone();
1448 it->prev();
1449 return it;
1450}
1451
1452template <typename TYPE, typename Compare, typename ALLOC>
1454{
1455 return RBTreeType::Iterator::get().template get<0>();
1456}
1457
1458template <typename TYPE, typename Compare, typename ALLOC>
1460{
1461 return RBTreeType::Iterator::get().template get<0>();
1462}
1463
1464template <typename TYPE, typename Compare, typename ALLOC>
1469
1470template <typename TYPE, typename Compare, typename ALLOC>
1472{
1473 return RBTreeType::Iterator::isValid();
1474}
1475
1476template<typename TYPE, typename Compare, typename ALLOC>
1480
1481template<typename TYPE, typename Compare, typename ALLOC>
1485
1486template<typename TYPE, typename Compare, typename ALLOC>
1489 if (this == &other){
1490 return *this;
1491 }
1492
1493 this->destroyTree();
1494 this->root_ = other.treeCopy();
1495 this->size_ = other.size_;
1496 this->compare_ = other.compare_;
1497 if constexpr(ALLOC::propagate_on_container_copy_assignment::value) {
1498 this->allocator = other.allocator;
1499 this->rebind_alloc = other.rebind_alloc;
1500 }
1501 return *this;
1502}
1503
1504template<typename TYPE, typename Compare, typename ALLOC>
1508
1509template<typename TYPE, typename Compare, typename ALLOC>
1512 if (this == &other){
1513 return *this;
1514 }
1515
1516 this->destroyTree();
1517 this->root_ = other.root_;
1518 other.root_ = nullptr;
1519 this->size_ = other.size_;
1520 other.size_ = 0;
1521 this->compare_ = std::move(other.compare_);
1522 if constexpr(ALLOC::propagate_on_container_move_assignment::value) {
1523 this->allocator = std::move(other.allocator);
1524 this->rebind_alloc = std::move(other.rebind_alloc);
1525 }
1526 return *this;
1527}
1528
1529template<typename TYPE, typename Compare, typename ALLOC>
1531{
1532 if (this == &other)
1533 return;
1534
1535 std::swap(this->root_, other.root_);
1536 std::swap(this->size_, other.size_);
1537 std::swap(this->compare_, other.compare_);
1538 if constexpr (ALLOC::propagate_on_container_swap::value) {
1539 std::swap(this->allocator, other.allocator);
1540 std::swap(this->rebind_alloc, other.rebind_alloc);
1541 }
1542}
1543
1544template<typename TYPE, typename Compare, typename ALLOC>
1548
1549template<typename TYPE, typename Compare, typename ALLOC>
1551 return this->find(e);
1552}
1553
1554template<typename TYPE, typename Compare, typename ALLOC>
1556 return this->insert(e, true);
1557}
1558
1559template<typename TYPE, typename Compare, typename ALLOC>
1561 return this->erase(e);
1562}
1563
1564template <typename TYPE, typename Compare, typename ALLOC>
1567{
1568 return new Iterator(const_cast<treeSet*>(this), this->getMinNode());
1569}
1570
1571template <typename TYPE, typename Compare, typename ALLOC>
1574{
1575 return new Iterator(const_cast<treeSet*>(this), this->getMaxNode());
1576}
1577
1578template<typename TYPE, typename Compare, typename ALLOC>
1580 return "treeSet";
1581}
1582
1583template<typename TYPE, typename Compare, typename ALLOC>
1585 std::stringstream ss;
1586 ss << this->className();
1587 ss << "(";
1588 bool first = true;
1589 for (auto it = this->begin(); it != this->end(); it.next()){
1590 if (!first){
1591 ss << ", ";
1592 }
1594 first = false;
1595 }
1596 ss << ")";
1597 if (enter)
1598 ss << "\n";
1599 return ss.str();
1600}
1601
1602template<typename TYPE, typename Compare, typename ALLOC>
1604
1605template<typename TYPE, typename Compare, typename ALLOC>
1607 const iterator<const TYPE>* other) const {
1608 auto other_it = dynamic_cast<const Iterator*>(other);
1609 return other_it && this->cur_ == other_it->cur_;
1610}
1611
1612template<typename TYPE, typename Compare, typename ALLOC>
1615
1616template<typename TYPE, typename Compare, typename ALLOC>
1619
1620template<typename TYPE, typename Compare, typename ALLOC>
1623 skipListType::Iterator::operator=(other);
1624 return *this;
1625}
1626
1627template<typename TYPE, typename Compare, typename ALLOC>
1632
1633template<typename TYPE, typename Compare, typename ALLOC>
1634std::string
1636 return "JSet::Iterator";
1637}
1638
1639template<typename TYPE, typename Compare, typename ALLOC>
1641 skipListType::Iterator::operator+=(steps);
1642}
1643
1644template<typename TYPE, typename Compare, typename ALLOC>
1648
1649template<typename TYPE, typename Compare, typename ALLOC>
1652 const iterator<const TYPE>& other) const {
1653 auto other_it = dynamic_cast<const Iterator*>(&other);
1654 if (other_it == nullptr)
1655 return this > &other ?
1656 std::numeric_limits<integer>::max() :
1657 std::numeric_limits<integer>::min();
1658 return skipListType::Iterator::operator-(*other_it);
1659}
1660
1661template<typename TYPE, typename Compare, typename ALLOC>
1663 return skipListType::Iterator::hasNext();
1664}
1665
1666template<typename TYPE, typename Compare, typename ALLOC>
1670
1671template<typename TYPE, typename Compare, typename ALLOC>
1673 const iterator<const TYPE>* other) const {
1674 const auto other_it = dynamic_cast<const Iterator*>(other);
1675 if (!other_it){
1676 return false;
1677 }
1678 auto cloned_it = ownerPtr(other_it->clone());
1679 return this->equalPtr(cloned_it.get());
1680}
1681
1682template<typename TYPE, typename Compare, typename ALLOC>
1687
1688template<typename TYPE, typename Compare, typename ALLOC>
1690 skipListType::Iterator::next();
1691}
1692
1693template<typename TYPE, typename Compare, typename ALLOC>
1697
1698template<typename TYPE, typename Compare, typename ALLOC>
1703
1704template<typename TYPE, typename Compare, typename ALLOC>
1706 return skipListType::Iterator::get().template get<0>();
1707}
1708
1709template<typename TYPE, typename Compare, typename ALLOC>
1711 return skipListType::Iterator::get().template get<0>();
1712}
1713
1714template<typename TYPE, typename Compare, typename ALLOC>
1718
1719template<typename TYPE, typename Compare, typename ALLOC>
1721 return skipListType::Iterator::isValid();
1722}
1723
1724template<typename TYPE, typename Compare, typename ALLOC>
1728
1729template<typename TYPE, typename Compare, typename ALLOC>
1733
1734template<typename TYPE, typename Compare, typename ALLOC>
1737 if (this == &other){
1738 return *this;
1739 }
1740
1741 this->listDestroy();
1742 this->head_ = other.listCopy();
1743 this->size_ = other.size_;
1744 this->compare_ = other.compare_;
1745 if constexpr(ALLOC::propagate_on_container_copy_assignment::value) {
1746 this->allocator = other.allocator;
1747 this->rebind_alloc = other.rebind_alloc;
1748 }
1749 return *this;
1750}
1751
1752template<typename TYPE, typename Compare, typename ALLOC>
1754 this->operator=(std::move(other));
1755}
1756
1757template<typename TYPE, typename Compare, typename ALLOC>
1760 if (this == &other){
1761 return *this;
1762 }
1763
1764 this->listDestroy();
1765 this->head_ = other.head_;
1766 other.head_ = other.createNode();
1767 this->size_ = other.size_;
1768 other.size_ = 0;
1769 this->compare_ = std::move(other.compare_);
1770 if constexpr(ALLOC::propagate_on_container_move_assignment::value) {
1771 this->allocator = std::move(other.allocator);
1772 this->rebind_alloc = std::move(other.rebind_alloc);
1773 }
1774 return *this;
1775}
1776
1777template<typename TYPE, typename Compare, typename ALLOC>
1779{
1780 if (this == &other)
1781 return;
1782
1783 std::swap(this->size_, other.size_);
1784 std::swap(this->head_, other.head_);
1785 std::swap(this->compare_, other.compare_);
1786 if constexpr (ALLOC::propagate_on_container_swap::value) {
1787 std::swap(this->allocator, other.allocator);
1788 std::swap(this->rebind_alloc, other.rebind_alloc);
1789 }
1790}
1791
1792template<typename TYPE, typename Compare, typename ALLOC>
1796
1797template<typename TYPE, typename Compare, typename ALLOC>
1799 return this->find(e);
1800}
1801
1802template<typename TYPE, typename Compare, typename ALLOC>
1804 return this->insert(e, true);
1805}
1806
1807template<typename TYPE, typename Compare, typename ALLOC>
1809 return this->erase(e);
1810}
1811
1812template<typename TYPE, typename Compare, typename ALLOC>
1815 return new Iterator(this->head_->getPNext(1));
1816}
1817
1818template<typename TYPE, typename Compare, typename ALLOC>
1821 return new Iterator(this->findLastNode());
1822}
1823
1824template<typename TYPE, typename Compare, typename ALLOC>
1826 return "JSet";
1827}
1828
1829template<typename TYPE, typename Compare, typename ALLOC>
1831 std::stringstream ss;
1832 ss << this->className();
1833 ss << "(";
1834 bool first = true;
1835 for (auto it = this->begin(); it != this->end(); it.next()){
1836 if (!first){
1837 ss << ", ";
1838 }
1840 first = false;
1841 }
1842 ss << ")";
1843 if (enter)
1844 ss << "\n";
1845 return ss.str();
1846}
1847
1848template<typename TYPE, typename Compare, typename ALLOC>
1850
1851template <typename TYPE, typename HASH, typename ALLOC>
1854{
1855 lhs.swap(rhs);
1856}
1857
1858template <typename TYPE, typename COMPARE, typename ALLOC>
1861{
1862 lhs.swap(rhs);
1863}
1864
1865template <typename TYPE, typename COMPARE, typename ALLOC>
1868{
1869 lhs.swap(rhs);
1870}
1871
1872#endif //SETS_H
Red-Black Tree implementation header.
Memory allocation interface and implementations.
Forward iterator for JSet.
Definition sets.h:738
void prev() const override
Not supported (throws unSupportedMethodError)
Definition sets.h:1694
bool hasNext() const override
Checks if more elements exist in forward direction.
Definition sets.h:1662
bool atNext(const iterator< const TYPE > *other) const override
Checks if other is next to this.
Definition sets.h:1683
Iterator & operator=(const Iterator &other)
Copy assignment operator.
Definition sets.h:1622
Iterator(skipListNode *cur)
Constructs iterator pointing to specific skip list node.
Definition sets.h:1613
Iterator * getPrev() const override
Not supported (throws unSupportedMethodError)
Definition sets.h:1700
void next() const override
Moves to next element.
Definition sets.h:1689
void operator-=(integer steps) const override
Not supported (throws unSupportedMethodError)
Definition sets.h:1645
std::string className() const override
Gets iterator class name.
Definition sets.h:1635
void operator+=(integer steps) const override
Advances iterator by steps.
Definition sets.h:1640
bool hasPrev() const override
Not supported (throws unSupportedMethodError)
Definition sets.h:1667
const TYPE & get() override
Gets current element (non-const)
Definition sets.h:1705
bool atPrev(const iterator< const TYPE > *other) const override
Checks if other is previous to this.
Definition sets.h:1672
void set(const TYPE &data) override
Not supported (throws unSupportedMethodError)
Definition sets.h:1715
Iterator * clone() const override
Creates a copy of this iterator.
Definition sets.h:1629
bool isValid() const override
Checks if iterator is valid.
Definition sets.h:1720
Skip List based implementation of the set interface.
Definition sets.h:714
void swap(JSet &other) noexcept
Swaps contents with another JSet.
Definition sets.h:1778
JSet(Compare comp=Compare{}, ALLOC alloc=ALLOC{})
Constructs empty JSet.
Definition sets.h:1725
std::string className() const override
Gets class name.
Definition sets.h:1825
~JSet() override
Destructor.
JSet & operator=(const JSet &other)
Copy assignment operator.
Definition sets.h:1736
Iterator * begins() const override
Gets begin iterator.
Definition sets.h:1814
std::string toString(bool enter) const override
Converts to string representation.
Definition sets.h:1830
bool add(const TYPE &e) override
Adds new element.
Definition sets.h:1803
bool remove(const TYPE &e) override
Removes element.
Definition sets.h:1808
u_integer size() const override
Gets number of elements.
Definition sets.h:1793
bool contains(const TYPE &e) const override
Checks if element exists.
Definition sets.h:1798
Iterator * ends() const override
Gets end iterator.
Definition sets.h:1820
Bidirectional iterator for RBTree.
Definition RBTree.h:219
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:153
void swap(autoPtr &other) noexcept
Swaps the reference counters between two autoPtr instances.
Definition autoPtr.h:703
const TYPE * get() const
Get managed pointer const version.
Definition autoPtr.h:629
A base class for basic iterators.
Definition iterator.h:296
Forward iterator for hashSet.
Definition sets.h:121
bool atNext(const iterator< const TYPE > *other) const override
Checks if other is next to this.
Definition sets.h:1157
bool hasNext() const override
Checks if more elements exist.
Definition sets.h:1132
void operator-=(integer steps) const override
Not supported (throws unSupportedMethodError)
Definition sets.h:1121
void next() const override
Moves to next element.
Definition sets.h:1162
bool atPrev(const iterator< const TYPE > *other) const override
Checks if other is previous to this.
Definition sets.h:1142
Iterator * clone() const override
Creates a copy of this iterator.
Definition sets.h:1106
bool hasPrev() const override
Not supported (throws unSupportedMethodError)
Definition sets.h:1137
void set(const TYPE &data) override
Not supported (throws unSupportedMethodError)
Definition sets.h:1188
Iterator * getPrev() const override
Not supported (throws unSupportedMethodError)
Definition sets.h:1173
Iterator & operator=(const Iterator &other)
Copy assignment operator.
Definition sets.h:1095
bool isValid() const override
Checks if iterator is valid.
Definition sets.h:1193
const TYPE & get() override
Gets current element (non-const)
Definition sets.h:1178
std::string className() const override
Gets iterator class name.
Definition sets.h:1111
void prev() const override
Not supported (throws unSupportedMethodError)
Definition sets.h:1167
void operator+=(integer steps) const override
Advances iterator by steps.
Definition sets.h:1116
Hash table based implementation of the set interface.
Definition sets.h:92
std::string className() const override
Gets class name.
Definition sets.h:1306
void swap(hashSet &other) noexcept
Swaps contents with another hashSet.
Definition sets.h:1248
u_integer size() const override
Gets number of elements.
Definition sets.h:1263
hashSet(HASH hash=HASH{}, ALLOC alloc=ALLOC{})
Constructs empty hashSet.
Definition sets.h:1198
bool add(const TYPE &e) override
Adds new element.
Definition sets.h:1273
std::string toString(bool enter) const override
Converts to string representation.
Definition sets.h:1311
bool remove(const TYPE &e) override
Removes element.
Definition sets.h:1278
bool contains(const TYPE &e) const override
Checks if element exists.
Definition sets.h:1268
hashSet & operator=(const hashSet &other)
Copy assignment operator.
Definition sets.h:1209
Iterator * ends() const override
Gets end iterator.
Definition sets.h:1295
Iterator * begins() const override
Gets begin iterator.
Definition sets.h:1284
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
Generic hash function object supporting multiple types.
Definition hash.h:62
A base class for iterable containers that support multiple iteration patterns.
Definition iterable.h:70
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.
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37
Base class providing polymorphic string conversion capabilities.
Definition printable.h:39
static std::string formatString(const TYPE &t)
Universal value-to-string conversion with type-specific formatting.
Definition printable.h:339
Abstract base class for unique element containers.
Definition set.h:44
Forward iterator for skipList.
Definition skipList.h:164
Internal node class for Skip List.
Definition skipList.h:54
Skip List container implementation.
Definition skipList.h:45
Bidirectional iterator for treeSet.
Definition sets.h:427
bool isValid() const override
Checks if iterator is valid.
Definition sets.h:1471
void next() const override
Moves to next element.
Definition sets.h:1432
bool atPrev(const iterator< const TYPE > *other) const override
Checks if other is previous to this.
Definition sets.h:1410
void operator-=(integer steps) const override
Rewinds iterator by steps.
Definition sets.h:1385
const TYPE & get() override
Gets current element (non-const)
Definition sets.h:1453
void set(const TYPE &data) override
Not supported.
Definition sets.h:1465
std::string className() const override
Gets iterator class name.
Definition sets.h:1373
bool atNext(const iterator< const TYPE > *other) const override
Checks if other is next to this.
Definition sets.h:1426
void operator+=(integer steps) const override
Advances iterator by steps.
Definition sets.h:1379
Iterator & operator=(const Iterator &other)
Copy assignment operator.
Definition sets.h:1354
void prev() const override
Moves to previous element.
Definition sets.h:1438
bool hasNext() const override
Checks if more elements exist in forward direction.
Definition sets.h:1398
bool hasPrev() const override
Checks if more elements exist in backward direction.
Definition sets.h:1404
Iterator * getPrev() const override
Gets previous iterator.
Definition sets.h:1445
Iterator * clone() const override
Creates a copy of this iterator.
Definition sets.h:1367
Red-Black Tree based implementation of the set interface.
Definition sets.h:403
bool contains(const TYPE &e) const override
Checks if element exists.
Definition sets.h:1550
bool remove(const TYPE &e) override
Removes element.
Definition sets.h:1560
void swap(treeSet &other) noexcept
Swaps contents with another treeSet.
Definition sets.h:1530
treeSet(Compare comp=Compare{}, ALLOC alloc=ALLOC{})
Constructs empty treeSet.
Definition sets.h:1477
treeSet & operator=(const treeSet &other)
Copy assignment operator.
Definition sets.h:1488
Iterator * ends() const override
Gets end iterator.
Definition sets.h:1573
~treeSet() override
Destructor.
std::string className() const override
Gets class name.
Definition sets.h:1579
Iterator * begins() const override
Gets begin iterator.
Definition sets.h:1566
bool add(const TYPE &e) override
Adds new element.
Definition sets.h:1555
u_integer size() const override
Gets number of elements.
Definition sets.h:1545
std::string toString(bool enter) const override
Converts to string representation.
Definition sets.h:1584
Exception for unimplemented method calls.
Definition error.h:271
Comparator base class and concrete comparator classes.
Combines Comparable and CallbackOf for comparison callbacks.
Definition types.h:377
Generic pair container implementation.
std::uint32_t u_integer
32-bit unsigned integer type for sizes and indexes
Definition config.h:263
std::int64_t integer
64-bit signed integer type for arithmetic operations
Definition config.h:254
Implementation of hashTable container.
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:863
Standard namespace extensions for original::alternative.
Definition allocator.h:351
void swap(original::objPoolAllocator< TYPE > &lhs, original::objPoolAllocator< TYPE > &rhs) noexcept
Specialization of std::swap for objPoolAllocator.
Definition allocator.h:635
Exclusive-ownership smart pointer implementation.
Abstract base class for set container implementations.
Skip List container implementation.