Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
htlist.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
45# ifndef HTLIST_H
46# define HTLIST_H
47
48# include <type_traits>
49# include <cassert>
50# include <stdexcept>
51# include <utility>
52# include <ahFunction.H>
53# include <ahFunctional.H>
54# include <ah-args-ctor.H>
55# include <ah-iterator.H>
56# include <ah-errors.H>
57# include <ah-dry.H>
58
59# define NEXT(p) (p->get_next())
60
61namespace Aleph {
62
63template <typename T> class Snodenc; // forward declaration
64
100{
101 Slinknc * next = nullptr;
102
103public:
104
105 virtual ~Slinknc() = default;
106
108 [[nodiscard]] constexpr bool is_empty() const noexcept { return next == nullptr; }
109
113 Slinknc() noexcept : next(nullptr) { /* empty */ }
114
119 Slinknc(const Slinknc &) noexcept : next(nullptr) { /* empty */ }
120
125 {
126 next = nullptr;
127 }
128
132 Slinknc & operator = (const Slinknc & ) noexcept
133 {
134 next = nullptr;
135 return *this;
136 }
137
140 {
141 return next;
142 }
143
145
159 void insert(Slinknc * p) noexcept
160 {
161 assert(p != nullptr);
162 p->next = next;
163 next = p;
164 }
165
178 {
179 Slinknc * ret_val = next;
180 next = ret_val->next;
181 ret_val->reset();
182 return ret_val;
183 }
184
190 template <typename T> inline
192
194
197
199
212 {
215
217 {
218 curr = head->is_empty() ? nullptr : head->next;
219 }
220
221 public:
222
223 Iterator() noexcept : head(nullptr), curr(nullptr)
224 {
225 // Empty
226 }
227
231 Iterator(Slinknc & list) noexcept : head(&list)
232 {
233 init();
234 }
235
248 : head(_head), curr(_curr)
249 {
250 // Empty
251 }
252
260 {
261 return curr != nullptr;
262 }
263
274 {
276 << "Iterator is at the end of the list";
277 return curr;
278 }
279
281 Slinknc * get_curr_ne() const noexcept { return curr; }
282
285 void next_ne() noexcept { curr = curr->next; }
286
296 void next()
297 {
299 << "Iterator is at the end of the list";
300 curr = curr->next;
301 }
302
307 {
308 init();
309 }
310 };
311};
312
313
326 template <typename T>
327class Snodenc : public Slinknc
328{
330
331public:
332
336 T & get_data() noexcept { return data; }
337
341 const T & get_data() const noexcept { return data; }
342
344 {
345 static_assert(std::is_default_constructible<T>::value,
346 "No default constructor for T");
347 }
348
352 Snodenc(const T & item) : data(item)
353 {
354 static_assert(std::is_copy_constructible<T>::value,
355 "No copy constructor for T");
356 }
357
361 Snodenc(T && item)
362 : data(std::forward<T>(item))
363 {
364 static_assert(std::is_move_constructible<T>::value,
365 "No move constructor for T");
366 }
367
386 {
387 return static_cast<Snodenc *>(Slinknc::remove_next());
388 }
389
404 {
405 // STRICT ALIASING WARNING: This reinterpret_cast violates C++ strict
406 // aliasing rules. Requires -fno-strict-aliasing compiler flag.
407 return reinterpret_cast<Snodenc *&>(Slinknc::get_next());
408 }
409
412
431};
432
433 template <typename T> inline
435{
436 return static_cast<Snodenc<T>*>(this);
437}
438
439 template <typename T> inline
441{
442 return static_cast<const Snodenc<T>*>(this);
443}
444
445template <typename T> T & Slinknc::to_data() noexcept
446{
447 return this->to_snodenc<T>()->get_data();
448}
449
450template <typename T> const T & Slinknc::to_data() const noexcept
451{
452 return this->to_snodenc<T>()->get_data();
453}
454
507{
510
511public:
512
514 HTList() noexcept : head(nullptr), tail(nullptr) { /* empty */ }
515
517 {
518 head = tail = nullptr;
519 }
520
523 [[nodiscard]] constexpr bool is_empty() const noexcept { return head == nullptr; }
524
529 {
530 return head != nullptr and head == tail;
531 }
532
536
540
544
548
551
554
571 HTList & swap(HTList & l) noexcept
572 {
573 std::swap(head, l.head);
574 std::swap(tail, l.tail);
575 return *this;
576 }
577
580
588 void insert(Slinknc * link) noexcept
589 {
590 assert(NEXT(link) == nullptr);
591
592 if (head == nullptr)
593 {
594 assert(tail == nullptr);
595 head = tail = link;
596 return;
597 }
598
599 NEXT(link) = head;
600 head = link;
601 }
602
605
613 void append(Slinknc * link) noexcept
614 {
615 assert(link != nullptr and NEXT(link) == nullptr);
616
617 if (head == nullptr)
618 {
619 assert(tail == nullptr);
620 head = tail = link;
621 return;
622 }
623
624 NEXT(tail) = link;
625 tail = link;
626 }
627
630
638 void append(HTList & l) noexcept
639 {
640 if (l.is_empty())
641 return;
642
643 if (this->is_empty())
644 {
645 this->swap(l);
646 return;
647 }
648
649 NEXT(tail) = l.head;
650 tail = l.tail;
651 l.head = l.tail = nullptr;
652 }
653
656 void put(Slinknc * link) noexcept { append(link); }
657
660 void concat(HTList & l) noexcept { append(l); }
661
663 void concat_list(HTList & l) noexcept { append(l); }
664
668
683 void insert(HTList & l) noexcept
684 {
685 l.append(*this);
686 this->swap(l);
687 }
688
742 void insert(Slinknc * link, HTList & list) noexcept
743 {
744 if (list.is_empty())
745 return;
746
747 Slinknc * link_next = NEXT(link); // save what was after link
748 NEXT(link) = list.head; // link now points to list's head
749 NEXT(list.tail) = link_next; // list's tail points to what was after link
750
751 if (link == tail) // if link was the tail, update tail
752 tail = list.tail;
753
754 list.head = list.tail = nullptr;
755 }
756
761 {
762 Slinknc * ret_val = head;
763 if (head == tail)
764 head = tail = nullptr;
765 else
766 {
767 head = NEXT(head);
768 if (head == nullptr)
769 tail = nullptr;
770 }
771
772 ret_val->reset();
773
774 return ret_val;
775 }
776
778 {
780 << "HTList is empty";
781 return remove_head_ne();
782 }
783
802
804
832 bool remove(Slinknc * link)
833 {
835 << "Removing from a empty list";
836
837 if (link == head)
838 {
839 head = NEXT(head);
840 if (head == nullptr)
841 tail = nullptr;
842 link->reset();
843 return true;
844 }
845
846 for (Slinknc * prev = head, * p = NEXT(head); p != nullptr;
847 prev = p, p = NEXT(p))
848 if (p == link)
849 {
850 NEXT(prev) = NEXT(p);
851 if (link == tail)
852 tail = prev;
853 link->reset();
854 return true;
855 }
856
857 return false;
858 }
859
862 void push(Slinknc * link) noexcept { insert(link); }
863
887 {
889 << "HTList as stack is empty";
890 return remove_head();
891 }
892
893 Slinknc * top() const
894 {
896 << "HTList as stack is empty";
897 return get_first();
898 }
899
903
930 size_t split_list(HTList & l, HTList & r) noexcept
931 {
932 assert(l.is_empty() and r.is_empty()); // l y r deben estar vacías
933
934 if (is_empty())
935 return 0;
936
937 if (is_unitarian())
938 {
939 swap(l);
940 return 1;
941 }
942
943 size_t count = 0;
944 Slinknc * p = head;
945 Slinknc * q = head;
946 while (q != tail and q != nullptr)
947 {
948 q = NEXT(q); ++count;
949 if (q == tail or q == nullptr)
950 break;
951
952 p = NEXT(p);
953 q = NEXT(q); ++count;
954 }
955
956 Slinknc * r_head = NEXT(p);
957
958 l.head = head;
959 l.tail = p;
960
961 r.head = r_head;
962 r.tail = r_head == nullptr ? nullptr : tail;
963
964 NEXT(l.tail) = nullptr;
965
966 head = tail = nullptr;
967
968 return count;
969 }
970
971 size_t split_list_ne(HTList & l, HTList & r) noexcept
972 {
973 return split_list(l, r);
974 }
975
977 size_t split(HTList & l, HTList & r) noexcept
978 {
979 return split_list(l, r);
980 }
981
986 {
987 HTList tmp;
988
989 size_t count = 0;
990 while (not is_empty())
991 {
993 ++count;
994 }
995
996 swap(tmp);
997
998 return count;
999 }
1000
1003 {
1004 return reverse();
1005 }
1006
1011
1025 void cut(Slinknc * link, HTList & list) noexcept
1026 {
1027 assert(list.is_empty());
1028
1029 list.head = NEXT(link);
1030 list.tail = list.head == nullptr ? nullptr : tail;
1031
1032 tail = link;
1033 NEXT(link) = nullptr;
1034 }
1035
1037 void cut_list(Slinknc * link, HTList & list) noexcept { cut(link, list); }
1038
1066 {
1067 while (not is_empty())
1068 delete remove_head_ne();
1069 }
1070
1083 {
1084 HTList * lptr = nullptr;
1085 Slinknc * curr = nullptr;
1086 Slinknc * prev = nullptr;
1087
1088 long pos = 0;
1089
1090 public:
1091
1093
1098 : lptr(& const_cast<HTList &>(list)), curr(lptr->head), prev(curr)
1099 { /* empty */ }
1100
1104 {
1105 prev = curr = lptr->head;
1106 pos = 0;
1107 }
1108
1111 long get_pos() const noexcept { return pos; }
1112
1115
1118 {
1119 reset();
1120 if (lptr->is_empty())
1121 return;
1122
1123 while (NEXT(curr))
1124 {
1125 prev = curr;
1126 curr = NEXT(curr);
1127 ++pos;
1128 }
1129 }
1130
1134 {
1135 curr = nullptr;
1136 }
1137
1139 Iterator & operator = (const Iterator & it) noexcept
1140 {
1141 lptr = it.lptr;
1142 curr = it.curr;
1143 prev = it.prev;
1144 pos = it.pos;
1145 return *this;
1146 }
1147
1150 bool has_curr() const noexcept { return curr != nullptr; }
1151
1153 {
1154 return lptr->is_empty() ? false : curr == lptr->tail;
1155 }
1156
1159 {
1160 return lptr->is_empty() ? false : curr == lptr->head;
1161 }
1162
1164 bool is_in_last() const noexcept { return is_last(); }
1165
1178 {
1179 ah_overflow_error_if(curr == nullptr)
1180 << "Iterator overflow";
1181
1182 return curr;
1183 }
1184
1187
1191 {
1192 if (curr == lptr->head) // on the first item?
1193 {
1194 assert(prev == lptr->head);
1195 curr = NEXT(curr);
1196 }
1197 else if (curr == lptr->tail) // on the last item?
1198 {
1199 assert(NEXT(prev) == curr);
1200 curr = nullptr;
1201 }
1202 else
1203 {
1204 assert(NEXT(prev) == curr);
1205 prev = curr;
1206 curr = NEXT(curr);
1207 assert(NEXT(prev) == curr);
1208 }
1209 pos++;
1210 }
1211
1222 void next()
1223 {
1225 << "Iterator overflow";
1226 next_ne();
1227 }
1228
1230 {
1231 Slinknc * ret_val = nullptr;
1232 if (curr == lptr->head) // first item removal
1233 {
1235 prev = curr = lptr->head;
1236 }
1237 else if (curr == lptr->tail) // last item removal
1238 {
1239 assert(NEXT(prev) == curr);
1240 ret_val = curr;
1241 NEXT(prev) = NEXT(curr);
1242 lptr->tail = prev;
1243 curr = nullptr; // put in overflow
1244 }
1245 else
1246 {
1247 assert(NEXT(prev) == curr);
1248 ret_val = curr;
1249 NEXT(prev) = NEXT(curr);
1250 curr = NEXT(curr);
1251 }
1252
1253 ret_val->reset();
1254 return ret_val;
1255 }
1256
1277 {
1279 << "Iterator overflow";
1280
1281 return del_ne();
1282 }
1283 };
1284
1320 {
1321 size_t count = 0;
1322 for (Iterator it(*this); it.has_curr(); it.next_ne())
1323 ++count;
1324
1325 return count;
1326 }
1327
1359 void rotate_left(size_t n)
1360 {
1361 if (is_empty())
1362 {
1363 if (n == 0)
1364 return;
1365 ah_domain_error() << "List is empty";
1366 return; // unreachable, silences -Wreturn-type
1367 }
1368
1369 for (size_t i = 0; i < n; ++i)
1371 }
1372};
1373
1415 template <typename T = int>
1416class DynList : public HTList,
1417 public GenericTraverse<DynList<T>>,
1418 public LocateFunctions<DynList<T>, T>,
1419 public SpecialCtors<DynList<T>, T>,
1420 public FunctionalMethods<DynList<T>, T>,
1421 public GenericItems<DynList<T>, T>,
1422 public StlAlephIterator<DynList<T>>
1423{
1425
1426 using CtorBase::CtorBase;
1427
1428 public:
1429
1431 using Item_Type = T;
1432
1434 using Key_Type = T;
1435
1438
1449 {
1450 return static_cast<DynList &>(HTList::swap(l));
1451 }
1452
1454 DynList() { /* empty */ }
1455
1459 DynList(const DynList & l) : HTList(), CtorBase(l) {}
1460
1461private:
1462
1463 T & __insert(Snodenc<T> * p) noexcept
1464 {
1465 static_assert(std::is_copy_constructible_v<T> or
1466 std::is_move_constructible_v<T>,
1467 "No copy assign for T");
1468 HTList::insert(p);
1469 return p->get_data();
1470 }
1471
1472 T & __append(Snodenc<T> * p) noexcept
1473 {
1474 static_assert(std::is_copy_constructible_v<T> or
1475 std::is_move_constructible_v<T>,
1476 "No copy assign for T");
1477 HTList::append(p);
1478 return p->get_data();
1479 }
1480
1481public:
1482
1502 T & insert(const T & item)
1503 {
1504 return __insert(new Snodenc<T> (item));
1505 }
1506
1517 T & insert(T && item)
1518 {
1519 return __insert(new Snodenc<T> (std::forward<T>(item)));
1520 }
1521
1523 T & push(const T & item)
1524 {
1525 return insert(item);
1526 }
1527
1529 T & push(T && item) { return insert(std::forward<T>(item)); }
1530
1532 T & put(const T & item)
1533 {
1534 return push(item);
1535 }
1536
1538 T & put(T && item)
1539 {
1540 return push(std::forward<T>(item));
1541 }
1542
1562 T & append(const T & item)
1563 {
1564 return __append(new Snodenc<T> (item));
1565 }
1566
1586 T & append(T && item)
1587 {
1588 return __append(new Snodenc<T> (std::forward<T>(item)));
1589 }
1590
1597 {
1598 Slinknc * l = this->HTList::remove_head_ne();
1599 auto * p = static_cast<Snodenc<T>*> (l);
1600 T ret_val = std::move(p->get_data());
1601 delete p;
1602
1603 return ret_val;
1604 }
1605
1612 {
1613 Slinknc * l = this->HTList::remove_head();
1614 auto * p = static_cast<Snodenc<T>*> (l);
1615 T ret_val = std::move(p->get_data());
1616 delete p;
1617
1618 return ret_val;
1619 }
1620
1623 {
1624 return remove_ne();
1625 }
1626
1629 {
1630 return remove();
1631 }
1632
1634 T pop() { return remove_first(); }
1635
1637 T get() { return remove(); }
1638
1644 {
1645 auto * p = static_cast<Snodenc<T>*> (this->HTList::get_last());
1646 return p->get_data();
1647 }
1648
1654 {
1655 return static_cast<Snodenc<T>*>(this->HTList::get_first())->get_data();
1656 }
1657
1663 T & get_last() const
1664 {
1666 << "List is empty";
1667 return get_last_ne();
1668 }
1669
1675 T & get_first() const
1676 {
1678 << "List is empty";
1679 return get_first_ne();
1680 }
1681
1683 T & top() const
1684 {
1685 return get_first();
1686 }
1687
1690 {
1691 if (is_empty())
1692 return;
1693
1694 // a very fast deletion
1695 auto * last = static_cast<Snodenc<T>*> (this->HTList::get_last());
1696 auto * p = static_cast<Snodenc<T>*> (this->HTList::get_first());
1697 while (p != last)
1698 {
1699 Snodenc<T> * q = p;
1700 p = p->get_next();
1701 delete q;
1702 }
1703 delete p;
1704 reset();
1705 }
1706
1708
1714 {
1715 public:
1716
1717 using Item_Type = T;
1718
1720
1722
1724
1727 : HTList::Iterator(list) { /* empty */ }
1728
1731 {
1732 return static_cast<Snodenc<T> *>(HTList::Iterator::get_curr_ne())->get_data();
1733 }
1734
1740 T & get_curr() const
1741 {
1742 return static_cast<Snodenc<T> *>(HTList::Iterator::get_curr())->get_data();
1743 }
1744
1755 {
1756 auto * p = static_cast<Snodenc<T> *>(this->HTList::Iterator::del());
1757 T ret_val = std::move(p->get_data());
1758 delete p;
1759 return ret_val;
1760 }
1761 };
1762
1764 {
1765 reverse_list();
1766 return *this;
1767 }
1768
1769 DynList & rev() noexcept { return reverse(); }
1770
1774 {
1775 DynList ret;
1776 for (auto it = this->get_it(); it.has_curr(); it.next())
1777 ret.insert(it.get_curr());
1778
1779 return ret;
1780 }
1781
1782 DynList rev() const { return reverse(); }
1783
1784 template <class Equal = std::equal_to<T>>
1785 T remove_ne(Equal eq) noexcept
1786 {
1787 for (Iterator it(*this); it.has_curr(); it.next_ne())
1788 {
1789 const T & item = it.get_curr_ne();
1790 if (not eq(item))
1791 continue;
1792 T ret = item; // performs a copy
1793 auto * removed = static_cast<Snodenc<T> *>(it.del_ne());
1794 delete removed;
1795 return ret;
1796 }
1797 return T(); // not found, return default constructed T
1798 }
1799
1823 template <class Equal = std::equal_to<T>> T remove(Equal eq)
1824 {
1825 for (Iterator it(*this); it.has_curr(); it.next_ne())
1826 if (const T & item = it.get_curr(); eq(item))
1827 {
1828 T ret = item; // performs a copy
1829 auto * removed = static_cast<Snodenc<T> *>(it.HTList::Iterator::del());
1830 delete removed;
1831 return ret;
1832 }
1833
1834 ah_domain_error() << "DynList::remove(Equal &): item not found";
1835 return T(); // unreachable, silences -Wreturn-type
1836 }
1837
1852 DynList(DynList && l) noexcept
1853 {
1854 swap(l);
1855 }
1856
1868 {
1869 if (&l == this)
1870 return *this;
1871
1872 empty();
1873
1874 for (typename DynList::Iterator it(l); it.has_curr(); it.next_ne())
1875 append(it.get_curr());
1876
1877 return *this;
1878 }
1879
1895 {
1896 return static_cast<DynList &>(this->swap(l));
1897 }
1898
1913 DynList & append(DynList && list) noexcept
1914 {
1915 HTList::append(list);
1916 return *this;
1917 }
1918
1933 DynList & insert(DynList && list) noexcept
1934 {
1935 HTList::insert(list);
1936 return *this;
1937 }
1938
1947 DynList & append(const DynList & list)
1948 {
1949 DynList copy = list;
1951 return *this;
1952 }
1953
1962 DynList & insert(const DynList & list)
1963 {
1964 DynList tmp = list;
1966 return *this;
1967 }
1968
1971 T & get(const size_t i)
1972 {
1973 Iterator it(*this);
1974
1975 for (size_t __i = 0 ; it.has_curr() and __i < i; it.next_ne(), ++__i);
1976
1977 return it.get_curr();
1978 }
1979
1981 T & operator [] (const size_t & i)
1982 {
1983 return get(i);
1984 }
1985};
1986
1987template <class Container>
1989{
1990 return c.template maps<typename Container::Item_Type>([] (const auto & d)
1991 {
1992 return d;
1993 });
1994}
1995
1996 template <typename T> inline
1998{
2000 ret.append(item);
2001 return ret;
2002}
2003
2004 template <typename T> inline
2006{
2007 return DynList<T>({item});
2008}
2009
2010# undef NEXT
2011
2012} // end namespace Aleph
2013
2014
2015# endif // HTLIST_H
Variadic constructor macros for containers.
Container traversal and functional operation mixins.
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error()
Throws std::domain_error unconditionally.
Definition ah-errors.H:554
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
Definition ah-errors.H:368
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
Definition ah-errors.H:463
STL-compatible iterator adapters for Aleph containers.
Standard functor implementations and comparison objects.
Functional programming utilities for Aleph-w containers.
Iterator on the items of list.
Definition htlist.H:1714
Iterator() noexcept=default
The type of container.
T & get_curr() const
Return the current item.
Definition htlist.H:1740
T del()
Remove the current item of the iterator.
Definition htlist.H:1754
T & get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Definition htlist.H:1730
Dynamic singly linked list with functional programming support.
Definition htlist.H:1423
T & top() const
Definition htlist.H:1683
DynList rev() const
Definition htlist.H:1782
T & insert(const T &item)
Insert a new item by copy.
Definition htlist.H:1502
T remove(Equal eq)
Remove the first element matching an equality criteria.
Definition htlist.H:1823
T & get_last_ne() const noexcept
Return the last item of the list without exception.
Definition htlist.H:1643
T & insert(T &&item)
Insert a new item by movement.
Definition htlist.H:1517
T & append(T &&item)
Append a new item by movement.
Definition htlist.H:1586
DynList(DynList &&l) noexcept
Initialize the list with all the items of l moved to this.
Definition htlist.H:1852
T & put(T &&item)
Definition htlist.H:1538
T remove_ne(Equal eq) noexcept
Definition htlist.H:1785
T & append(const T &item)
Append a new item by copy.
Definition htlist.H:1562
T Item_Type
The type of item.
Definition htlist.H:1431
Slinknc * get_tail() const noexcept=delete
T Key_Type
The type of item.
Definition htlist.H:1434
DynList & operator=(const DynList &l)
Assign to this a copy of l
Definition htlist.H:1867
Slinknc * get_head() const noexcept=delete
DynList & append(DynList &&list) noexcept
Append listat the end of this by movement.
Definition htlist.H:1913
T & operator[](const size_t &i)
Array-style access to the i-th item. Equivalent to get(i).
Definition htlist.H:1981
T & get_last() const
Return the last item of the list.
Definition htlist.H:1663
T & get_first() const
Return the first item of the list.
Definition htlist.H:1675
T remove_ne() noexcept
Remove the first item of the list without exception.
Definition htlist.H:1596
DynList reverse() const
Return a reversed copy of this.
Definition htlist.H:1773
T remove()
Remove the first item of the list.
Definition htlist.H:1611
DynList & rev() noexcept
Definition htlist.H:1769
T & __insert(Snodenc< T > *p) noexcept
Definition htlist.H:1463
DynList(const DynList &l)
Initialize a list with a copy of all the items of list l
Definition htlist.H:1459
T & get(const size_t i)
Obtains a modifiable reference to the i-th item of this.
Definition htlist.H:1971
DynList & insert(const DynList &list)
Insert to this a copy of list.
Definition htlist.H:1962
T & push(T &&item)
Definition htlist.H:1529
DynList & insert(DynList &&list) noexcept
Insert listat the beginning of this by movement.
Definition htlist.H:1933
T & push(const T &item)
Definition htlist.H:1523
T & __append(Snodenc< T > *p) noexcept
Definition htlist.H:1472
T & put(const T &item)
Definition htlist.H:1532
DynList & reverse() noexcept
Definition htlist.H:1763
void empty() noexcept
empty the list
Definition htlist.H:1689
DynList()
Initialize an empty list.
Definition htlist.H:1454
DynList & swap(DynList &l) noexcept
Swap this with l.
Definition htlist.H:1448
DynList & append(const DynList &list)
Append to this a copy of list.
Definition htlist.H:1947
T remove_first_ne() noexcept
Definition htlist.H:1622
T & get_first_ne() const noexcept
Return the first item of the list without exception.
Definition htlist.H:1653
Iterator on HTList.
Definition htlist.H:1083
Slinknc * get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Definition htlist.H:1186
long get_pos() const noexcept
Return the current position.
Definition htlist.H:1111
void reset_last()
It has O(n) of performance.
Definition htlist.H:1117
void next_ne() noexcept
Move the iterator one position forward guaranteeing no exception.
Definition htlist.H:1190
void reset_first() noexcept
Definition htlist.H:1114
bool is_in_last() const noexcept
Return true if the iterator is positioned on the last item.
Definition htlist.H:1164
bool is_last() const noexcept
Definition htlist.H:1152
void next()
Move the iterator one item forward.
Definition htlist.H:1222
Slinknc * get_curr() const
Return the current node on which the iterator is positioned.
Definition htlist.H:1177
Iterator & operator=(const Iterator &it) noexcept
Assignation.
Definition htlist.H:1139
bool has_curr() const noexcept
Return true if iterator has current item.
Definition htlist.H:1150
bool is_in_first() const noexcept
Return true if the iterator is positioned on the first item.
Definition htlist.H:1158
Slinknc * del_ne() noexcept
Definition htlist.H:1229
Iterator() noexcept=default
void end() noexcept
Set the iterator to its end position, which has not current item.
Definition htlist.H:1133
void reset() noexcept
Reset the iterator at the first item.
Definition htlist.H:1103
Slinknc * del()
Remove the current item.
Definition htlist.H:1276
Single linked list of nodes.
Definition htlist.H:507
Slinknc * head
Definition htlist.H:508
Slinknc * get_first() const noexcept
Return list first element.
Definition htlist.H:547
void push(Slinknc *link) noexcept
Insert link as first element.
Definition htlist.H:862
void put(Slinknc *link) noexcept
Insert link as last element.
Definition htlist.H:656
size_t reverse_list() noexcept
Definition htlist.H:1002
void remove_all_and_delete() noexcept
Remove and free memory for all the items of list.
Definition htlist.H:1065
Slinknc * top() const
Definition htlist.H:893
Slinknc * get_tail() const noexcept
Return list tail (last element)
Definition htlist.H:543
size_t reverse() noexcept
It inverts all list elements.
Definition htlist.H:985
void insert(HTList &l) noexcept
Insert starting in link (contained in 'this' list) the 'list' list.
Definition htlist.H:683
void cut_list(Slinknc *link, HTList &list) noexcept
Definition htlist.H:1037
constexpr bool is_empty() const noexcept
Return true if list is empty.
Definition htlist.H:523
Slinknc * tail
Definition htlist.H:509
void insert(Slinknc *link, HTList &list) noexcept
Insert a list into this after one of its items.
Definition htlist.H:742
Slinknc * get_head() const noexcept
Return list head (first element)
Definition htlist.H:539
Slinknc * remove_head()
Definition htlist.H:777
void rotate_left(size_t n)
Rotate to left the list n positions.
Definition htlist.H:1359
void cut(Slinknc *link, HTList &list) noexcept
It cuts 'this' over 'link' element and it puts all remaining elements.
Definition htlist.H:1025
void concat_list(HTList &l) noexcept
Definition htlist.H:663
HTList & swap(HTList &l) noexcept
Exchange 'this' values with another list.
Definition htlist.H:571
Slinknc * pop()
Definition htlist.H:886
void append(Slinknc *link) noexcept
Insert link as last element.
Definition htlist.H:613
size_t split_list(HTList &l, HTList &r) noexcept
It divides 'this' into two equal lists without modifying elements order.
Definition htlist.H:930
void append(HTList &l) noexcept
Join 'this' with 'l' through list end.
Definition htlist.H:638
HTList() noexcept
Initialize an empty list.
Definition htlist.H:514
Slinknc * remove_first()
Definition htlist.H:803
Slinknc * remove_first_ne() noexcept
Definition htlist.H:801
size_t split(HTList &l, HTList &r) noexcept
Definition htlist.H:977
size_t size() const noexcept
Count the number of elements of the list.
Definition htlist.H:1319
bool remove(Slinknc *link)
Remove from the list the item pointed by link
Definition htlist.H:832
void insert(Slinknc *link) noexcept
Insert link as first element.
Definition htlist.H:588
Slinknc * remove_head_ne() noexcept
It deletes head element (first one).
Definition htlist.H:760
bool is_unitarian() const noexcept
Return true if the list contains exactly just one element.
Definition htlist.H:528
Slinknc * get_last() const noexcept
Return the last item of the list (nullptr if the list is empty)
Definition htlist.H:550
size_t split_list_ne(HTList &l, HTList &r) noexcept
Definition htlist.H:971
void concat(HTList &l) noexcept
Concat to 'this' all 'l' list; 'l' becomes empty.
Definition htlist.H:660
void reset() noexcept
Definition htlist.H:516
bool is_unitarian_or_empty() const noexcept
Return true if list contains one element or is empty.
Definition htlist.H:535
Iterator on single links.
Definition htlist.H:212
void reset_first() noexcept
Reset the iterator to the first link on the list.
Definition htlist.H:306
void next()
Move the iterator one position forward.
Definition htlist.H:296
bool has_curr() const noexcept
Return true if the iterator is positioned on a valid link.
Definition htlist.H:259
Slinknc * get_curr() const
Return the current link on which the iterator is positioned.
Definition htlist.H:273
Slinknc * get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Definition htlist.H:281
void init() noexcept
Definition htlist.H:216
Iterator(Slinknc *_head, Slinknc *_curr) noexcept
Initialize an iterator on the list pointed by _head, but on a node pointed by curr
Definition htlist.H:247
void next_ne() noexcept
Move the iterator one position forward guaranteeing no exception.
Definition htlist.H:285
Iterator(Slinknc &list) noexcept
Initialize an iterator on the first node of list
Definition htlist.H:231
Link of a single linked list non-circular and without header node.
Definition htlist.H:100
virtual ~Slinknc()=default
Slinknc * next
Definition htlist.H:101
T & to_data() noexcept
Definition htlist.H:445
Slinknc *& get_next() noexcept
getter
Definition htlist.H:139
void reset() noexcept
Reset the link to nullptr.
Definition htlist.H:124
Slinknc() noexcept
Init to nullptr.
Definition htlist.H:113
constexpr bool is_empty() const noexcept
Return true if this is empty.
Definition htlist.H:108
Slinknc & operator=(const Slinknc &) noexcept
Dummy asignation; link is set to nullptr.
Definition htlist.H:132
Slinknc(const Slinknc &) noexcept
Dummy copy constructor.
Definition htlist.H:119
Snodenc< T > * to_snodenc() noexcept
Convert this to a Snodenc<T>.
Definition htlist.H:434
Slinknc * remove_next() noexcept
Remove for linked list the node pointed by this
Definition htlist.H:177
void insert(Slinknc *p) noexcept
Insert p after this
Definition htlist.H:159
Node belonging to a single non-circular linked list without header node.
Definition htlist.H:328
Snodenc(T &&item)
Construct by moving item
Definition htlist.H:361
Snodenc(const T &item)
Construct with copy of item
Definition htlist.H:352
const T & get_data() const noexcept
Return a constant reference to the data.
Definition htlist.H:341
Snodenc *& get_next() noexcept
Return the node following to this
Definition htlist.H:403
Snodenc *& get_first() const noexcept
Return the node following to this.
Definition htlist.H:430
T & get_data() noexcept
Return a modifiable reference to the data.
Definition htlist.H:336
Snodenc * remove_next() noexcept
Remove the node following to this.
Definition htlist.H:385
Snodenc * remove_first() noexcept
Definition htlist.H:411
Common methods to the Aleph-w ( ) containers.
Definition ah-dry.H:548
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
Definition ah-dry.H:904
Common sequential searching methods on containers.
Definition ah-dry.H:164
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
Definition ah-dry.H:190
Mixin that adds STL begin()/end() and cbegin()/cend() to Aleph containers.
#define NEXT(p)
Definition htlist.H:59
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
DynList< typename Container::Item_Type > to_dynlist(const Container &c)
Definition htlist.H:1988
bool eq(const C1 &c1, const C2 &c2, Eq e=Eq())
Check equality of two containers using a predicate.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
Definition ahAlgo.H:584
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:107
DynList< T > unitarian_DynList(const T &item)
Definition htlist.H:2005
bool has_curr() const noexcept
Return true if all underlying iterators are positioned on a valid item.
Definition ah-zip.H:130
static bool init
Definition hash-fct.C:47
DynList< T > get_unitarian_DynList(const T &item)
Definition htlist.H:1997
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Definition ahAlgo.H:127
STL namespace.
Generic list of items stored in a container.
Definition ah-dry.H:1501
Generic traversal of the container through its iterator.
Definition ah-dry.H:65
Special constructors common to Aleph-w ( ) containers.
Definition ah-dry.H:492
DynList< int > l