30 # include <type_traits> 34 # include <ahFunction.H> 35 # include <ahFunctional.H> 36 # include <ah-args-ctor.H> 37 # include <ah-iterator.H> 39 # define NEXT(p) (p->get_next()) 41 using namespace Aleph;
66 bool is_empty() const noexcept {
return next ==
nullptr; }
119 assert(p !=
nullptr);
138 next = ret_val->next;
148 template <
typename T>
inline 151 template <typename T> inline T & to_data() noexcept;
153 template <typename T> inline
156 template <typename T> inline const T & to_data() const noexcept;
176 curr = head->
is_empty() ? nullptr : head->next;
181 Iterator() noexcept : head(
nullptr), curr(
nullptr)
206 : head(_head), curr(_curr)
219 return curr !=
nullptr;
234 throw std::overflow_error(
"Iterator is at the end of the list");
243 void next_ne() noexcept { curr = curr->next; }
257 throw std::overflow_error(
"Iterator is at the end of the list");
284 template <
typename T>
299 const T &
get_data() const noexcept {
return data; }
301 Snodenc() noexcept(std::is_nothrow_constructible<T>::value)
303 static_assert(std::is_default_constructible<T>::value,
304 "No default constructor for T");
310 Snodenc(
const T & item) noexcept(noexcept(T(item))) : data(item)
312 static_assert(std::is_copy_constructible<T>::value,
313 "No copy constructor for T");
319 Snodenc(T && item) noexcept(noexcept(std::swap(data, item)))
320 : data(
std::forward<T>(item))
322 static_assert(std::is_move_constructible<T>::value,
323 "No move constructor for T");
376 template <
typename T>
inline 382 template <
typename T>
inline 388 template <
typename T> T & Slinknc::to_data() noexcept
390 return this->to_snodenc<T>()->get_data();
393 template <
typename T>
const T & Slinknc::to_data()
const noexcept
395 return this->to_snodenc<T>()->get_data();
457 HTList() noexcept : head(
nullptr), tail(
nullptr) { }
461 head = tail =
nullptr;
466 bool is_empty() const noexcept {
return head ==
nullptr; }
473 return head !=
nullptr and head == tail;
516 std::swap(head, l.head);
517 std::swap(tail, l.tail);
533 assert(NEXT(link) ==
nullptr);
537 assert(tail ==
nullptr);
558 assert(link !=
nullptr and NEXT(link) ==
nullptr);
562 assert(tail ==
nullptr);
594 l.head = l.tail =
nullptr;
682 NEXT(link) =
list.head;
694 head = tail =
nullptr;
710 throw std::underflow_error(
"HTList is empty");
711 return remove_head_ne();
731 Slinknc * remove_first_ne() noexcept {
return remove_head_ne(); }
733 Slinknc * remove_first() {
return remove_head(); }
765 throw std::underflow_error(
"Removing from a empty list");
774 for (
Slinknc * prev = head, * p = NEXT(head); p !=
nullptr;
775 prev = p, p = NEXT(p))
778 NEXT(prev) = NEXT(p);
817 throw std::underflow_error(
"HTList as stack is empty");
818 return remove_head();
824 throw std::underflow_error(
"HTList as stack is empty");
860 assert(l.is_empty() and r.is_empty());
874 while (q != tail and q !=
nullptr)
876 q = NEXT(q); ++count;
877 if (q == tail or q ==
nullptr)
881 q = NEXT(q); ++count;
890 head = tail =
nullptr;
897 return split_list(l, r);
903 return split_list(l, r);
916 tmp.
insert(remove_first_ne());
951 assert(
list.is_empty());
953 list.head = NEXT(link);
957 NEXT(link) =
nullptr;
992 delete remove_head_ne();
1020 : lptr(& (
HTList&)
list), curr(lptr->head), prev(curr)
1027 prev = curr = lptr->head;
1071 bool has_curr() const noexcept {
return curr !=
nullptr; }
1073 bool is_last()
const noexcept
1075 return lptr->
is_empty() ? false : curr == lptr->tail;
1081 return lptr->
is_empty() ? false : curr == lptr->head;
1085 bool is_in_last() const noexcept {
return is_last(); }
1100 if (curr ==
nullptr)
1101 throw std::overflow_error(
"Iterator overflow");
1113 if (curr == lptr->head)
1115 assert(prev == lptr->head);
1118 else if (curr == lptr->tail)
1120 assert(NEXT(prev) == curr);
1125 assert(NEXT(prev) == curr);
1128 assert(NEXT(prev) == curr);
1146 throw std::overflow_error(
"Iterator overflow");
1153 if (curr == lptr->head)
1155 ret_val = lptr->remove_first();
1156 prev = curr = lptr->head;
1158 else if (curr == lptr->tail)
1160 assert(NEXT(prev) == curr);
1162 NEXT(prev) = NEXT(curr);
1168 assert(NEXT(prev) == curr);
1170 NEXT(prev) = NEXT(curr);
1200 throw std::overflow_error(
"Iterator overflow");
1286 throw std::domain_error(
"List is empty");
1288 for (
size_t i = 0; i < n; ++i)
1289 append(remove_first());
1293 # include <ah-dry.H> 1316 template <
typename T =
int>
1323 public StlAlephIterator<DynList<T>>
1327 using CtorBase::CtorBase;
1363 static_assert(std::is_copy_constructible<T>::value or
1364 std::is_move_constructible<T>::value,
1365 "No copy assign for T");
1372 static_assert(std::is_copy_constructible<T>::value or
1373 std::is_move_constructible<T>::value,
1374 "No copy assign for T");
1428 return __insert(
new Snodenc<T> (std::forward<T>(item)));
1441 T &
put(
const T & item) noexcept(noexcept(T(item)))
1447 T &
put(T && item) noexcept(noexcept(std::forward<T>(item)))
1449 return push(std::forward<T>(item));
1471 T & append(
const T & item)
1497 return __append(
new Snodenc<T> (std::forward<T>(item)));
1509 T ret_val = std::move(p->
get_data());
1524 T ret_val = std::move(p->
get_data());
1543 T
pop() {
return remove_first(); }
1546 T
get() {
return remove(); }
1575 throw std::underflow_error(
"List is empty");
1576 return get_last_ne();
1587 throw std::underflow_error(
"List is empty");
1588 return get_first_ne();
1626 using Item_Type = T;
1666 T ret_val = std::move(p->
get_data());
1678 DynList & rev() noexcept {
return reverse(); }
1685 for (
auto it = this->get_it(); it.has_curr(); it.next())
1686 ret.
insert(it.get_curr());
1691 DynList rev()
const {
return reverse(); }
1693 template <
class Equal = std::equal_to<T>>
1694 T remove_ne(Equal eq) noexcept
1698 const T & item = it.get_curr_ne();
1730 template <
class Equal = std::equal_to<T>> T
remove(Equal eq)
1734 const T & item = it.get_curr_ne();
1743 throw std::domain_error(
"DynList::remove(Equal &): item not found");
1783 append(it.get_curr_ne());
1804 return (
DynList&) this->swap(l);
1879 T &
get(
const size_t & i)
1883 for (
size_t __i = 0 ; it.
has_curr() and __i < i; it.
next_ne(), ++__i);
1889 T & operator [] (
const size_t & i)
1895 template <
class Container>
1898 return c.template maps<typename Container::Item_Type>([] (
const auto & d)
1904 template <
typename T>
inline 1905 DynList<T> get_unitarian_DynList(
const T & item)
1912 template <
typename T>
inline Slinknc() noexcept
Definition: htlist.H:71
void next_ne() noexcept
Definition: htlist.H:1111
Definition: htlist.H:1290
Snodenc< T > * to_snodenc() noexcept
Definition: htlist.H:377
size_t size() const noexcept
Definition: htlist.H:1240
T & top() const
Definition: htlist.H:1592
T remove_first()
Definition: htlist.H:1537
Snodenc *& get_next() noexcept
Definition: htlist.H:351
Snodenc(const T &item) noexcept(noexcept(T(item)))
Definition: htlist.H:310
void empty() noexcept
empty the list
Definition: htlist.H:1598
void insert(Slinknc *p) noexcept
Insert p after this
Definition: htlist.H:117
Snodenc(T &&item) noexcept(noexcept(std::swap(data, item)))
Definition: htlist.H:319
void cut_list(Slinknc *link, HTList &list) noexcept
Definition: htlist.H:961
Slinknc * get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Definition: htlist.H:239
bool has_curr() const noexcept
Definition: htlist.H:217
void append(Slinknc *link) noexcept
Definition: htlist.H:556
Slinknc * get_head() const noexcept
Definition: htlist.H:482
void next()
Definition: htlist.H:1143
DynList reverse() const
Definition: htlist.H:1682
Slinknc(const Slinknc &) noexcept
Definition: htlist.H:77
T & get_first() const
Definition: htlist.H:1584
Iterator(Slinknc *_head, Slinknc *_curr) noexcept
Definition: htlist.H:205
DynList & append(const DynList &list) noexcept(noexcept(DynList(list)))
Definition: htlist.H:1855
T & get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Definition: htlist.H:1639
T & insert(T &&item)
Definition: htlist.H:1426
void insert(Slinknc *link, HTList &list) noexcept
Definition: htlist.H:680
size_t reverse_list() noexcept
Definition: htlist.H:926
Slinknc * get_tail() const noexcept
Definition: htlist.H:486
Iterator(const DynList &list) noexcept
Initiliaze an iterator on the first item of list
Definition: htlist.H:1635
T & push(const T &item)
Definition: htlist.H:1432
bool is_empty() const noexcept
Definition: htlist.H:466
T remove_first_ne() noexcept
Definition: htlist.H:1531
bool has_curr() const noexcept
Definition: htlist.H:1071
Iterator() noexcept
The type of container.
Definition: htlist.H:1632
void concat(HTList &l) noexcept
Definition: htlist.H:603
void reset_first() noexcept
Definition: htlist.H:1036
T & put(T &&item) noexcept(noexcept(std::forward< T >(item)))
Definition: htlist.H:1447
void push(Slinknc *link) noexcept
Definition: htlist.H:790
T del()
Definition: htlist.H:1663
Snodenc *& get_first() const noexcept
Definition: htlist.H:373
Slinknc & operator=(const Slinknc &) noexcept
Definition: htlist.H:90
Snodenc * remove_next() noexcept
Definition: htlist.H:343
bool is_unitarian_or_empty() const noexcept
Definition: htlist.H:478
void remove_all_and_delete() noexcept
Definition: htlist.H:989
void rotate_left(size_t n)
Definition: htlist.H:1280
Slinknc *& get_next() noexcept
getter
Definition: htlist.H:97
Slinknc * get_curr() const
Definition: htlist.H:231
T & insert(const T &item)
Definition: htlist.H:1400
T remove_ne() noexcept
Definition: htlist.H:1505
T & push(T &&item)
Definition: htlist.H:1438
Snodenc * remove_first() noexcept
Definition: htlist.H:354
void end() noexcept
Definition: htlist.H:1055
T & get_first_ne() const noexcept
Definition: htlist.H:1562
bool is_empty() const noexcept
Return true if this is empty.
Definition: htlist.H:66
Iterator(Slinknc &list) noexcept
Definition: htlist.H:189
Slinknc * remove_head_ne() noexcept
Definition: htlist.H:690
DynList & append(DynList &&list) noexcept
Definition: htlist.H:1821
void concat_list(HTList &l) noexcept
Definition: htlist.H:606
Slinknc * get_curr() const
Definition: htlist.H:1098
Slinknc * del()
Definition: htlist.H:1197
void put(Slinknc *link) noexcept
Definition: htlist.H:599
void append(HTList &l) noexcept
Definition: htlist.H:581
T & put(const T &item) noexcept(noexcept(T(item)))
Definition: htlist.H:1441
DynList(const DynList &l)
Definition: htlist.H:1357
Slinknc * remove_next() noexcept
Definition: htlist.H:135
void reset_last()
It has O(n) of performance.
Definition: htlist.H:1039
size_t split(HTList &l, HTList &r) noexcept
Definition: htlist.H:901
bool is_in_first() const noexcept
Return true if the iterator is positioned on the first item.
Definition: htlist.H:1079
Slinknc * get_last() const noexcept
Return the last item of the list (nullptr if the list is empty)
Definition: htlist.H:493
Slinknc * get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Definition: htlist.H:1107
void insert(HTList &l) noexcept
Definition: htlist.H:621
void cut(Slinknc *link, HTList &list) noexcept
It makes reference to is_empty(). Referenced by cut_list().
Definition: htlist.H:949
T & get_curr() const
Definition: htlist.H:1649
DynList & insert(DynList &&list) noexcept
Definition: htlist.H:1841
void next_ne() noexcept
Definition: htlist.H:243
T pop()
Definition: htlist.H:1543
const T & get_data() const noexcept
Definition: htlist.H:299
HTList & swap(HTList &l) noexcept
Swap in constant time (very fast) 'this' elements with 'l' list elements Referenced by append()...
Definition: htlist.H:514
Iterator(const HTList &list) noexcept
Definition: htlist.H:1019
long get_pos() const noexcept
Definition: htlist.H:1033
Slinknc * get_first() const noexcept
Definition: htlist.H:490
DynList() noexcept(std::is_nothrow_constructible< T >::value)
Initialize an empty list.
Definition: htlist.H:1352
size_t reverse() noexcept
Definition: htlist.H:909
size_t split_list(HTList &l, HTList &r) noexcept
Definition: htlist.H:858
Slinknc * remove_head()
Definition: htlist.H:707
DynList & swap(DynList &l) noexcept
Definition: htlist.H:1346
HTList() noexcept
Initialize an empty list.
Definition: htlist.H:457
void reset() noexcept
Definition: htlist.H:82
Definition: htlist.H:1622
DynList & insert(const DynList &list) noexcept(noexcept(DynList(list)))
Definition: htlist.H:1870
Definition: htlist.H:1006
void reset_first() noexcept
Definition: htlist.H:264
T & get_data() noexcept
Definition: htlist.H:294
T & append(const T &item)
Definition: htlist.H:1471
void next()
Definition: htlist.H:254
void reset() noexcept
Definition: htlist.H:1025
bool is_unitarian() const noexcept
Definition: htlist.H:471
T & get_last_ne() const noexcept
Definition: htlist.H:1552
void insert(Slinknc *link) noexcept
Definition: htlist.H:531
T & append(T &&item)
Definition: htlist.H:1495
DynList(DynList &&l) noexcept
Definition: htlist.H:1760
T & get_last() const
Definition: htlist.H:1572