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
95{
96 Slinknc * next = nullptr;
97
98public:
99
100 virtual ~Slinknc() = default;
101
103 [[nodiscard]] constexpr bool is_empty() const noexcept { return next == nullptr; }
104
107 Slinknc() noexcept : next(nullptr) { /* empty */ }
108
111 Slinknc(const Slinknc &) noexcept : next(nullptr) { /* empty */ }
112
116 {
117 next = nullptr;
118 }
119
122 Slinknc & operator = (const Slinknc & ) noexcept
123 {
124 next = nullptr;
125 return *this;
126 }
127
128
130 {
131 return next;
132 }
133
134
135
143 void insert(Slinknc * p) noexcept
144 {
145 assert(p != nullptr);
146 p->next = next;
147 next = p;
148 }
149
157 {
158 Slinknc * ret_val = next;
159 next = ret_val->next;
160 ret_val->reset();
161 return ret_val;
162 }
163
169 template <typename T> inline
171
173
176
178
186 {
189
191 {
192 curr = head->is_empty() ? nullptr : head->next;
193 }
194
195 public:
196
197 Iterator() noexcept : head(nullptr), curr(nullptr)
198 {
199 // Empty
200 }
201
204 Iterator(Slinknc & list) noexcept : head(&list)
205 {
206 init();
207 }
208
216 : head(_head), curr(_curr)
217 {
218 // Empty
219 }
220
226 {
227 return curr != nullptr;
228 }
229
236 {
238 << "Iterator is at the end of the list";
239 return curr;
240 }
241
243 Slinknc * get_curr_ne() const noexcept { return curr; }
244
247 void next_ne() noexcept { curr = curr->next; }
248
254 void next()
255 {
257 << "Iterator is at the end of the list";
258 curr = curr->next;
259 }
260
264 {
265 init();
266 }
267 };
268};
269
270
278 template <typename T>
279class Snodenc : public Slinknc
280{
282
283public:
284
287 T & get_data() noexcept { return data; }
288
291 const T & get_data() const noexcept { return data; }
292
294 {
295 static_assert(std::is_default_constructible<T>::value,
296 "No default constructor for T");
297 }
298
301 Snodenc(const T & item) : data(item)
302 {
303 static_assert(std::is_copy_constructible<T>::value,
304 "No copy constructor for T");
305 }
306
309 Snodenc(T && item)
310 : data(std::forward<T>(item))
311 {
312 static_assert(std::is_move_constructible<T>::value,
313 "No move constructor for T");
314 }
315
326 {
327 return static_cast<Snodenc *>(Slinknc::remove_next());
328 }
329
333 {
334 // STRICT ALIASING WARNING: This reinterpret_cast violates C++ strict
335 // aliasing rules. Requires -fno-strict-aliasing compiler flag.
336 return reinterpret_cast<Snodenc *&>(Slinknc::get_next());
337 }
338
341
352};
353
354 template <typename T> inline
356{
357 return static_cast<Snodenc<T>*>(this);
358}
359
360 template <typename T> inline
362{
363 return static_cast<const Snodenc<T>*>(this);
364}
365
366template <typename T> T & Slinknc::to_data() noexcept
367{
368 return this->to_snodenc<T>()->get_data();
369}
370
371template <typename T> const T & Slinknc::to_data() const noexcept
372{
373 return this->to_snodenc<T>()->get_data();
374}
375
403{
406
407public:
408
409
410 HTList() noexcept : head(nullptr), tail(nullptr) { /* empty */ }
411
413 {
414 head = tail = nullptr;
415 }
416
417
418
419 [[nodiscard]] constexpr bool is_empty() const noexcept { return head == nullptr; }
420
422
423
425 {
426 return head != nullptr and head == tail;
427 }
428
430
432
433
434
436
437
438
440
441
442
444
447
448
449
450
459 HTList & swap(HTList & l) noexcept
460 {
461 std::swap(head, l.head);
462 std::swap(tail, l.tail);
463 return *this;
464 }
465
466
467
468
473 void insert(Slinknc * link) noexcept
474 {
475 assert(NEXT(link) == nullptr);
476
477 if (head == nullptr)
478 {
479 assert(tail == nullptr);
480 head = tail = link;
481 return;
482 }
483
484 NEXT(link) = head;
485 head = link;
486 }
487
488
489
490
495 void append(Slinknc * link) noexcept
496 {
497 assert(link != nullptr and NEXT(link) == nullptr);
498
499 if (head == nullptr)
500 {
501 assert(tail == nullptr);
502 head = tail = link;
503 return;
504 }
505
506 NEXT(tail) = link;
507 tail = link;
508 }
509
510
511
512
517 void append(HTList & l) noexcept
518 {
519 if (l.is_empty())
520 return;
521
522 if (this->is_empty())
523 {
524 this->swap(l);
525 return;
526 }
527
528 NEXT(tail) = l.head;
529 tail = l.tail;
530 l.head = l.tail = nullptr;
531 }
532
533
534
535 void put(Slinknc * link) noexcept { append(link); }
536
538
539 void concat(HTList & l) noexcept { append(l); }
540
542 void concat_list(HTList & l) noexcept { append(l); }
543
545
546
547
555 void insert(HTList & l) noexcept
556 {
557 l.append(*this);
558 this->swap(l);
559 }
560
588 void insert(Slinknc * link, HTList & list) noexcept
589 {
590 if (list.is_empty())
591 return;
592
593 Slinknc * link_next = NEXT(link); // save what was after link
594 NEXT(link) = list.head; // link now points to list's head
595 NEXT(list.tail) = link_next; // list's tail points to what was after link
596
597 if (link == tail) // if link was the tail, update tail
598 tail = list.tail;
599
600 list.head = list.tail = nullptr;
601 }
602
604
605
607 {
608 Slinknc * ret_val = head;
609 if (head == tail)
610 head = tail = nullptr;
611 else
612 {
613 head = NEXT(head);
614 if (head == nullptr)
615 tail = nullptr;
616 }
617
618 ret_val->reset();
619
620 return ret_val;
621 }
622
624 {
626 << "HTList is empty";
627 return remove_head_ne();
628 }
629
640
642
657 bool remove(Slinknc * link)
658 {
660 << "Removing from a empty list";
661
662 if (link == head)
663 {
664 head = NEXT(head);
665 if (head == nullptr)
666 tail = nullptr;
667 link->reset();
668 return true;
669 }
670
671 for (Slinknc * prev = head, * p = NEXT(head); p != nullptr;
672 prev = p, p = NEXT(p))
673 if (p == link)
674 {
675 NEXT(prev) = NEXT(p);
676 if (link == tail)
677 tail = prev;
678 link->reset();
679 return true;
680 }
681
682 return false;
683 }
684
685
686
687 void push(Slinknc * link) noexcept { insert(link); }
688
701 {
703 << "HTList as stack is empty";
704 return remove_head();
705 }
706
707 Slinknc * top() const
708 {
710 << "HTList as stack is empty";
711 return get_first();
712 }
713
715
716
717
731 size_t split_list(HTList & l, HTList & r) noexcept
732 {
733 assert(l.is_empty() and r.is_empty()); // l y r deben estar vacías
734
735 if (is_empty())
736 return 0;
737
738 if (is_unitarian())
739 {
740 swap(l);
741 return 1;
742 }
743
744 size_t count = 0;
745 Slinknc * p = head;
746 Slinknc * q = head;
747 while (q != tail and q != nullptr)
748 {
749 q = NEXT(q); ++count;
750 if (q == tail or q == nullptr)
751 break;
752
753 p = NEXT(p);
754 q = NEXT(q); ++count;
755 }
756
757 Slinknc * r_head = NEXT(p);
758
759 l.head = head;
760 l.tail = p;
761
762 r.head = r_head;
763 r.tail = r_head == nullptr ? nullptr : tail;
764
765 NEXT(l.tail) = nullptr;
766
767 head = tail = nullptr;
768
769 return count;
770 }
771
772 size_t split_list_ne(HTList & l, HTList & r) noexcept
773 {
774 return split_list(l, r);
775 }
776
778 size_t split(HTList & l, HTList & r) noexcept
779 {
780 return split_list(l, r);
781 }
782
784
785
787 {
788 HTList tmp;
789
790 size_t count = 0;
791 while (not is_empty())
792 {
794 ++count;
795 }
796
797 swap(tmp);
798
799 return count;
800 }
801
804 {
805 return reverse();
806 }
807
809
810
812
820 void cut(Slinknc * link, HTList & list) noexcept
821 {
822 assert(list.is_empty());
823
824 list.head = NEXT(link);
825 list.tail = list.head == nullptr ? nullptr : tail;
826
827 tail = link;
828 NEXT(link) = nullptr;
829 }
830
832 void cut_list(Slinknc * link, HTList & list) noexcept { cut(link, list); }
833
848 {
849 while (not is_empty())
850 delete remove_head_ne();
851 }
852
860 {
861 HTList * lptr = nullptr;
862 Slinknc * curr = nullptr;
863 Slinknc * prev = nullptr;
864
865 long pos = 0;
866
867 public:
868
870
872
875 : lptr(& const_cast<HTList &>(list)), curr(lptr->head), prev(curr)
876 { /* empty */ }
877
879
881 {
882 prev = curr = lptr->head;
883 pos = 0;
884 }
885
886
887
888 long get_pos() const noexcept { return pos; }
889
892
895 {
896 reset();
897 if (lptr->is_empty())
898 return;
899
900 while (NEXT(curr))
901 {
902 prev = curr;
903 curr = NEXT(curr);
904 ++pos;
905 }
906 }
907
909
911 {
912 curr = nullptr;
913 }
914
915
916 Iterator(const Iterator &) = default;
917
918
919 Iterator & operator = (const Iterator & it) noexcept
920 {
921 lptr = it.lptr;
922 curr = it.curr;
923 prev = it.prev;
924 pos = it.pos;
925 return *this;
926 }
927
928
929
930 bool has_curr() const noexcept { return curr != nullptr; }
931
933 {
934 return lptr->is_empty() ? false : curr == lptr->tail;
935 }
936
939 {
940 return lptr->is_empty() ? false : curr == lptr->head;
941 }
942
944 bool is_in_last() const noexcept { return is_last(); }
945
953 {
954 ah_overflow_error_if(curr == nullptr)
955 << "Iterator overflow";
956
957 return curr;
958 }
959
962
966 {
967 if (curr == lptr->head) // on the first item?
968 {
969 assert(prev == lptr->head);
970 curr = NEXT(curr);
971 }
972 else if (curr == lptr->tail) // on the last item?
973 {
974 assert(NEXT(prev) == curr);
975 curr = nullptr;
976 }
977 else
978 {
979 assert(NEXT(prev) == curr);
980 prev = curr;
981 curr = NEXT(curr);
982 assert(NEXT(prev) == curr);
983 }
984 pos++;
985 }
986
993 void next()
994 {
996 << "Iterator overflow";
997 next_ne();
998 }
999
1001 {
1002 Slinknc * ret_val = nullptr;
1003 if (curr == lptr->head) // first item removal
1004 {
1006 prev = curr = lptr->head;
1007 }
1008 else if (curr == lptr->tail) // last item removal
1009 {
1010 assert(NEXT(prev) == curr);
1011 ret_val = curr;
1012 NEXT(prev) = NEXT(curr);
1013 lptr->tail = prev;
1014 curr = nullptr; // put in overflow
1015 }
1016 else
1017 {
1018 assert(NEXT(prev) == curr);
1019 ret_val = curr;
1020 NEXT(prev) = NEXT(curr);
1021 curr = NEXT(curr);
1022 }
1023
1024 ret_val->reset();
1025 return ret_val;
1026 }
1027
1039 {
1041 << "Iterator overflow";
1042
1043 return del_ne();
1044 }
1045 };
1046
1066 {
1067 size_t count = 0;
1068 for (Iterator it(*this); it.has_curr(); it.next_ne())
1069 ++count;
1070
1071 return count;
1072 }
1073
1090 void rotate_left(size_t n)
1091 {
1092 if (is_empty())
1093 {
1094 if (n == 0)
1095 return;
1096 ah_domain_error() << "List is empty";
1097 return; // unreachable, silences -Wreturn-type
1098 }
1099
1100 for (size_t i = 0; i < n; ++i)
1102 }
1103};
1104
1146 template <typename T = int>
1147class DynList : public HTList,
1148 public GenericTraverse<DynList<T>>,
1149 public LocateFunctions<DynList<T>, T>,
1150 public SpecialCtors<DynList<T>, T>,
1151 public FunctionalMethods<DynList<T>, T>,
1152 public GenericItems<DynList<T>, T>,
1153 public EqualSequenceMethod<DynList<T>>,
1154 public StlAlephIterator<DynList<T>>
1155{
1157
1158 using CtorBase::CtorBase;
1159
1160 public:
1161
1162
1163 using Item_Type = T;
1164
1165
1166 using Key_Type = T;
1167
1170
1177 {
1178 return static_cast<DynList &>(HTList::swap(l));
1179 }
1180
1181
1183 DynList() { /* empty */ }
1184
1186 DynList(const DynList & l) : HTList(), CtorBase(l) {}
1187
1188private:
1189
1190 T & __insert(Snodenc<T> * p) noexcept
1191 {
1192 static_assert(std::is_copy_constructible_v<T> or
1193 std::is_move_constructible_v<T>,
1194 "No copy assign for T");
1195 HTList::insert(p);
1196 return p->get_data();
1197 }
1198
1199 T & __append(Snodenc<T> * p) noexcept
1200 {
1201 static_assert(std::is_copy_constructible_v<T> or
1202 std::is_move_constructible_v<T>,
1203 "No copy assign for T");
1204 HTList::append(p);
1205 return p->get_data();
1206 }
1207
1208public:
1209
1220 T & insert(const T & item)
1221 {
1222 return __insert(new Snodenc<T> (item));
1223 }
1224
1235 T & insert(T && item)
1236 {
1237 return __insert(new Snodenc<T> (std::forward<T>(item)));
1238 }
1239
1241 T & push(const T & item)
1242 {
1243 return insert(item);
1244 }
1245
1247 T & push(T && item) { return insert(std::forward<T>(item)); }
1248
1250 T & put(const T & item)
1251 {
1252 return push(item);
1253 }
1254
1256 T & put(T && item)
1257 {
1258 return push(std::forward<T>(item));
1259 }
1260
1271 T & append(const T & item)
1272 {
1273 return __append(new Snodenc<T> (item));
1274 }
1275
1286 T & append(T && item)
1287 {
1288 return __append(new Snodenc<T> (std::forward<T>(item)));
1289 }
1290
1297 {
1298 Slinknc * l = this->HTList::remove_head_ne();
1299 auto * p = static_cast<Snodenc<T>*> (l);
1300 T ret_val = std::move(p->get_data());
1301 delete p;
1302
1303 return ret_val;
1304 }
1305
1312 {
1313 Slinknc * l = this->HTList::remove_head();
1314 auto * p = static_cast<Snodenc<T>*> (l);
1315 T ret_val = std::move(p->get_data());
1316 delete p;
1317
1318 return ret_val;
1319 }
1320
1323 {
1324 return remove_ne();
1325 }
1326
1329 {
1330 return remove();
1331 }
1332
1334 T pop() { return remove_first(); }
1335
1337 T get() { return remove(); }
1338
1344 {
1345 auto * p = static_cast<Snodenc<T>*> (this->HTList::get_last());
1346 return p->get_data();
1347 }
1348
1354 {
1355 return static_cast<Snodenc<T>*>(this->HTList::get_first())->get_data();
1356 }
1357
1363 T & get_last() const
1364 {
1366 << "List is empty";
1367 return get_last_ne();
1368 }
1369
1375 T & get_first() const
1376 {
1378 << "List is empty";
1379 return get_first_ne();
1380 }
1381
1383 T & top() const
1384 {
1385 return get_first();
1386 }
1387
1390 {
1391 if (is_empty())
1392 return;
1393
1394 // a very fast deletion
1395 auto * last = static_cast<Snodenc<T>*> (this->HTList::get_last());
1396 auto * p = static_cast<Snodenc<T>*> (this->HTList::get_first());
1397 while (p != last)
1398 {
1399 Snodenc<T> * q = p;
1400 p = p->get_next();
1401 delete q;
1402 }
1403 delete p;
1404 reset();
1405 }
1406
1411 void clear() noexcept { empty(); }
1412
1414
1420 {
1421 public:
1422
1423 using Item_Type = T;
1424
1426
1428
1430
1433 : HTList::Iterator(list) { /* empty */ }
1434
1437 {
1438 return static_cast<Snodenc<T> *>(HTList::Iterator::get_curr_ne())->get_data();
1439 }
1440
1446 T & get_curr() const
1447 {
1448 return static_cast<Snodenc<T> *>(HTList::Iterator::get_curr())->get_data();
1449 }
1450
1461 {
1462 auto * p = static_cast<Snodenc<T> *>(this->HTList::Iterator::del());
1463 T ret_val = std::move(p->get_data());
1464 delete p;
1465 return ret_val;
1466 }
1467 };
1468
1470 {
1471 reverse_list();
1472 return *this;
1473 }
1474
1475 DynList & rev() noexcept { return reverse(); }
1476
1480 {
1481 DynList ret;
1482 for (auto it = this->get_it(); it.has_curr(); it.next())
1483 ret.insert(it.get_curr());
1484
1485 return ret;
1486 }
1487
1488 DynList rev() const { return reverse(); }
1489
1490 template <class Equal = std::equal_to<T>>
1491 T remove_ne(Equal eq) noexcept
1492 {
1493 for (Iterator it(*this); it.has_curr(); it.next_ne())
1494 {
1495 const T & item = it.get_curr_ne();
1496 if (not eq(item))
1497 continue;
1498 T ret = item; // performs a copy
1499 auto * removed = static_cast<Snodenc<T> *>(it.del_ne());
1500 delete removed;
1501 return ret;
1502 }
1503 return T(); // not found, return default constructed T
1504 }
1505
1529 template <class Equal = std::equal_to<T>> T remove(Equal eq)
1530 {
1531 for (Iterator it(*this); it.has_curr(); it.next_ne())
1532 if (const T & item = it.get_curr(); eq(item))
1533 {
1534 T ret = item; // performs a copy
1535 auto * removed = static_cast<Snodenc<T> *>(it.HTList::Iterator::del());
1536 delete removed;
1537 return ret;
1538 }
1539
1540 ah_domain_error() << "DynList::remove(Equal &): item not found";
1541 return T(); // unreachable, silences -Wreturn-type
1542 }
1543
1558 DynList(DynList && l) noexcept
1559 {
1560 swap(l);
1561 }
1562
1574 {
1575 if (&l == this)
1576 return *this;
1577
1578 empty();
1579
1580 for (typename DynList::Iterator it(l); it.has_curr(); it.next_ne())
1581 append(it.get_curr());
1582
1583 return *this;
1584 }
1585
1601 {
1602 return static_cast<DynList &>(this->swap(l));
1603 }
1604
1619 DynList & append(DynList && list) noexcept
1620 {
1621 HTList::append(list);
1622 return *this;
1623 }
1624
1639 DynList & insert(DynList && list) noexcept
1640 {
1641 HTList::insert(list);
1642 return *this;
1643 }
1644
1653 DynList & append(const DynList & list)
1654 {
1655 DynList copy = list;
1657 return *this;
1658 }
1659
1668 DynList & insert(const DynList & list)
1669 {
1670 DynList tmp = list;
1672 return *this;
1673 }
1674
1677 T & get(const size_t i)
1678 {
1679 Iterator it(*this);
1680
1681 for (size_t __i = 0 ; it.has_curr() and __i < i; it.next_ne(), ++__i);
1682
1683 return it.get_curr();
1684 }
1685
1687 T & operator [] (const size_t & i)
1688 {
1689 return get(i);
1690 }
1691};
1692
1693template <class Container>
1695{
1696 return c.template maps<typename Container::Item_Type>([] (const auto & d)
1697 {
1698 return d;
1699 });
1700}
1701
1702 template <typename T> inline
1704{
1706 ret.append(item);
1707 return ret;
1708}
1709
1710 template <typename T> inline
1712{
1713 return DynList<T>({item});
1714}
1715
1716# undef NEXT
1717
1718} // end namespace Aleph
1719
1720
1721# 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:1420
Iterator() noexcept=default
The type of container.
T & get_curr() const
Return the current item.
Definition htlist.H:1446
T del()
Remove the current item of the iterator.
Definition htlist.H:1460
T & get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Definition htlist.H:1436
Dynamic singly linked list with functional programming support.
Definition htlist.H:1155
T & top() const
Definition htlist.H:1383
DynList rev() const
Definition htlist.H:1488
T & insert(const T &item)
Definition htlist.H:1220
T remove(Equal eq)
Remove the first element matching an equality criteria.
Definition htlist.H:1529
T & get_last_ne() const noexcept
Return the last item of the list without exception.
Definition htlist.H:1343
T & insert(T &&item)
Insert a new item by movement.
Definition htlist.H:1235
T & append(T &&item)
Definition htlist.H:1286
DynList(DynList &&l) noexcept
Initialize the list with all the items of l moved to this.
Definition htlist.H:1558
T & put(T &&item)
Definition htlist.H:1256
T remove_ne(Equal eq) noexcept
Definition htlist.H:1491
T & append(const T &item)
Definition htlist.H:1271
Slinknc * get_tail() const noexcept=delete
DynList & operator=(const DynList &l)
Assign to this a copy of l
Definition htlist.H:1573
Slinknc * get_head() const noexcept=delete
DynList & append(DynList &&list) noexcept
Append listat the end of this by movement.
Definition htlist.H:1619
T & operator[](const size_t &i)
Array-style access to the i-th item. Equivalent to get(i).
Definition htlist.H:1687
T & get_last() const
Return the last item of the list.
Definition htlist.H:1363
T & get_first() const
Return the first item of the list.
Definition htlist.H:1375
T remove_ne() noexcept
Remove the first item of the list without exception.
Definition htlist.H:1296
DynList reverse() const
Return a reversed copy of this.
Definition htlist.H:1479
T remove()
Remove the first item of the list.
Definition htlist.H:1311
DynList & rev() noexcept
Definition htlist.H:1475
T & __insert(Snodenc< T > *p) noexcept
Definition htlist.H:1190
DynList(const DynList &l)
Initialize a list with a copy of all the items of list l
Definition htlist.H:1186
T & get(const size_t i)
Obtains a modifiable reference to the i-th item of this.
Definition htlist.H:1677
void clear() noexcept
Empties the container.
Definition htlist.H:1411
DynList & insert(const DynList &list)
Insert to this a copy of list.
Definition htlist.H:1668
T & push(T &&item)
Definition htlist.H:1247
DynList & insert(DynList &&list) noexcept
Insert listat the beginning of this by movement.
Definition htlist.H:1639
T & push(const T &item)
Definition htlist.H:1241
T & __append(Snodenc< T > *p) noexcept
Definition htlist.H:1199
T & put(const T &item)
Definition htlist.H:1250
DynList & reverse() noexcept
Definition htlist.H:1469
void empty() noexcept
empty the list
Definition htlist.H:1389
DynList()
Initialize an empty list.
Definition htlist.H:1183
DynList & swap(DynList &l) noexcept
Definition htlist.H:1176
DynList & append(const DynList &list)
Append to this a copy of list.
Definition htlist.H:1653
T remove_first_ne() noexcept
Definition htlist.H:1322
T & get_first_ne() const noexcept
Return the first item of the list without exception.
Definition htlist.H:1353
Slinknc * get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Definition htlist.H:961
long get_pos() const noexcept
Definition htlist.H:888
void reset_last()
It has O(n) of performance.
Definition htlist.H:894
void next_ne() noexcept
Move the iterator one position forward guaranteeing no exception.
Definition htlist.H:965
void reset_first() noexcept
Definition htlist.H:891
bool is_in_last() const noexcept
Return true if the iterator is positioned on the last item.
Definition htlist.H:944
bool is_last() const noexcept
Definition htlist.H:932
Slinknc * get_curr() const
Definition htlist.H:952
Iterator & operator=(const Iterator &it) noexcept
Definition htlist.H:919
bool has_curr() const noexcept
Definition htlist.H:930
bool is_in_first() const noexcept
Return true if the iterator is positioned on the first item.
Definition htlist.H:938
Slinknc * del_ne() noexcept
Definition htlist.H:1000
Iterator() noexcept=default
Iterator(const Iterator &)=default
void end() noexcept
Set the iterator to its end position, which has not.
Definition htlist.H:910
void reset() noexcept
Reset the iterator at the first item.
Definition htlist.H:880
Single linked list of nodes.
Definition htlist.H:403
Slinknc * head
Definition htlist.H:404
Slinknc * get_first() const noexcept
Definition htlist.H:443
void push(Slinknc *link) noexcept
Definition htlist.H:687
void put(Slinknc *link) noexcept
Definition htlist.H:535
size_t reverse_list() noexcept
Definition htlist.H:803
void remove_all_and_delete() noexcept
Definition htlist.H:847
Slinknc * top() const
Definition htlist.H:707
Slinknc * get_tail() const noexcept
Definition htlist.H:439
size_t reverse() noexcept
It inverts all list elements. It returns list size.
Definition htlist.H:786
void insert(HTList &l) noexcept
Insert starting in link (contained in 'this' list) the.
Definition htlist.H:555
void cut_list(Slinknc *link, HTList &list) noexcept
Definition htlist.H:832
constexpr bool is_empty() const noexcept
Definition htlist.H:419
Slinknc * tail
Definition htlist.H:405
void insert(Slinknc *link, HTList &list) noexcept
Insert a list into this after one of its items.
Definition htlist.H:588
Slinknc * get_head() const noexcept
Definition htlist.H:435
Slinknc * remove_head()
Definition htlist.H:623
void rotate_left(size_t n)
Rotate to left the list n positions.
Definition htlist.H:1090
void cut(Slinknc *link, HTList &list) noexcept
It cuts 'this' over 'link' element and it puts all.
Definition htlist.H:820
void concat_list(HTList &l) noexcept
Definition htlist.H:542
HTList & swap(HTList &l) noexcept
Definition htlist.H:459
Slinknc * pop()
Definition htlist.H:700
void append(Slinknc *link) noexcept
Definition htlist.H:495
size_t split_list(HTList &l, HTList &r) noexcept
It divides 'this' into two equal lists without modifying.
Definition htlist.H:731
void append(HTList &l) noexcept
Definition htlist.H:517
HTList() noexcept
Definition htlist.H:410
Slinknc * remove_first()
Definition htlist.H:641
Slinknc * remove_first_ne() noexcept
Definition htlist.H:639
size_t split(HTList &l, HTList &r) noexcept
Definition htlist.H:778
size_t size() const noexcept
Count the number of elements of the list.
Definition htlist.H:1065
bool remove(Slinknc *link)
Definition htlist.H:657
void insert(Slinknc *link) noexcept
Definition htlist.H:473
Slinknc * remove_head_ne() noexcept
It deletes head element (first one). Return deleted.
Definition htlist.H:606
bool is_unitarian() const noexcept
Return true if the list contains exactly just one.
Definition htlist.H:424
Slinknc * get_last() const noexcept
Return the last item of the list (nullptr if the list is empty)
Definition htlist.H:446
size_t split_list_ne(HTList &l, HTList &r) noexcept
Definition htlist.H:772
void concat(HTList &l) noexcept
Concat to 'this' all 'l' list; 'l' becomes empty.
Definition htlist.H:539
void reset() noexcept
Definition htlist.H:412
bool is_unitarian_or_empty() const noexcept
Return true if list contains one element or is empty.
Definition htlist.H:431
void reset_first() noexcept
Reset the iterator to the first link on the list.
Definition htlist.H:263
bool has_curr() const noexcept
Return true if the iterator is positioned on a valid link.
Definition htlist.H:225
Slinknc * get_curr() const
Definition htlist.H:235
Slinknc * get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Definition htlist.H:243
void init() noexcept
Definition htlist.H:190
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:215
void next_ne() noexcept
Move the iterator one position forward guaranteeing no exception.
Definition htlist.H:247
Iterator(Slinknc &list) noexcept
Initialize an iterator on the first node of list
Definition htlist.H:204
Link of a single linked list non-circular and without header node.
Definition htlist.H:95
virtual ~Slinknc()=default
Slinknc * next
Definition htlist.H:96
T & to_data() noexcept
Definition htlist.H:366
Slinknc *& get_next() noexcept
Definition htlist.H:129
void reset() noexcept
Reset the link to nullptr.
Definition htlist.H:115
Slinknc() noexcept
Init to nullptr.
Definition htlist.H:107
constexpr bool is_empty() const noexcept
Return true if this is empty.
Definition htlist.H:103
Slinknc & operator=(const Slinknc &) noexcept
Dummy asignation; link is set to nullptr.
Definition htlist.H:122
Slinknc(const Slinknc &) noexcept
Dummy copy constructor.
Definition htlist.H:111
Snodenc< T > * to_snodenc() noexcept
Convert this to a Snodenc<T>.
Definition htlist.H:355
Slinknc * remove_next() noexcept
Definition htlist.H:156
void insert(Slinknc *p) noexcept
insert(p) inserts the node pointed by p after this.
Definition htlist.H:143
Snodenc(T &&item)
Construct by moving item
Definition htlist.H:309
Snodenc(const T &item)
Construct with copy of item
Definition htlist.H:301
const T & get_data() const noexcept
Return a constant reference to the data.
Definition htlist.H:291
Snodenc *& get_next() noexcept
Return the node following to this
Definition htlist.H:332
Snodenc *& get_first() const noexcept
Definition htlist.H:351
T & get_data() noexcept
Return a modifiable reference to the data.
Definition htlist.H:287
Snodenc * remove_next() noexcept
Definition htlist.H:325
Snodenc * remove_first() noexcept
Definition htlist.H:340
Mixin providing equality comparison for sequence containers.
Definition ah-dry.H:1756
Common methods to the Aleph-w ( ) containers.
Definition ah-dry.H:642
Common sequential searching methods on containers.
Definition ah-dry.H:196
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
Definition ah-dry.H:222
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
and
Check uniqueness with explicit hash + equality functors.
DynList< typename Container::Item_Type > to_dynlist(const Container &c)
Definition htlist.H:1694
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
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:105
DynList< T > unitarian_DynList(const T &item)
Definition htlist.H:1711
bool has_curr() const noexcept
Return true if all underlying iterators are positioned on a valid item.
Definition ah-zip.H:126
DynList< T > get_unitarian_DynList(const T &item)
Definition htlist.H:1703
static std::atomic< bool > init
Definition hash-fct.C:53
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:1714
Generic traversal of the container through its iterator.
Definition ah-dry.H:67
Special constructors common to Aleph-w ( ) containers.
Definition ah-dry.H:586
gsl_rng * r
DynList< int > l