33 using namespace Aleph;
37 template <
typename T>
class Dnode;
57 template <
typename T>
inline Dnode<T> * to_dnode() noexcept;
58 template <
typename T>
inline const Dnode<T> * to_dnode()
const noexcept;
59 template <
typename T>
inline T& to_data() noexcept;
60 template <
typename T>
inline const T& to_data()
const noexcept;
68 : prev(l.prev), next(l.next)
89 link->next->prev =
this;
90 link->prev->next =
this;
107 std::swap(prev->next, link->prev->next);
108 std::swap(next->prev, link->next->prev);
109 std::swap(prev, link->prev);
110 std::swap(next, link->next);
192 bool is_empty() const noexcept {
return this == next and
this == prev; }
195 bool is_unitarian() const noexcept {
return this != next and next == prev; }
207 assert(next !=
nullptr and prev !=
nullptr);
208 assert(node !=
nullptr);
209 assert(node->is_empty());
230 assert(next !=
nullptr and prev !=
nullptr);
231 assert(node !=
nullptr);
232 assert(node->is_empty());
243 assert(next !=
nullptr and prev !=
nullptr);
250 assert(next !=
nullptr and prev !=
nullptr);
309 if (head->is_empty())
312 head->prev->next = next;
313 head->next->prev =
this;
314 next->prev = head->prev;
331 if (head->is_empty())
334 head->next->prev = prev;
335 head->prev->next =
this;
336 prev->next = head->next;
364 assert(head !=
nullptr);
366 if (head->is_empty())
375 prev->next = head->next;
376 head->next->prev = prev;
378 head->prev->next =
this;
391 assert(next !=
nullptr and prev !=
nullptr);
417 Dlink* retValue = prev;
438 Dlink* retValue = next;
468 throw std::underflow_error(
"Dlink as stack is not empty");
475 throw std::underflow_error(
"Dlink as stack is not empty");
516 assert(l.is_empty() and r.is_empty());
532 size_t split_list(
Dlink & l,
Dlink & r) noexcept
558 assert(not
is_empty() and not link->is_empty() and link !=
this);
561 if (link == this->prev)
568 if (link == this->next)
575 list.prev = this->prev;
577 this->prev = link->prev;
578 link->prev->next =
this;
580 list.prev->next = &list;
593 mutable Dlink * head =
nullptr;
594 mutable Dlink * curr =
nullptr;
610 : head(head_ptr), curr(head->
get_next()) { }
617 : head(&const_cast<Dlink&>(
list)), curr(head->
get_next())
631 assert(curr !=
nullptr and head !=
nullptr);
635 Iterator() noexcept : head(
nullptr), curr(
nullptr) { }
640 assert(curr !=
nullptr and head !=
nullptr);
647 assert(curr !=
nullptr and head !=
nullptr);
654 put_itor_at_the_end(*
this);
660 assert(curr !=
nullptr and head !=
nullptr);
664 bool is_last()
const noexcept
666 return head->
is_empty() ? false : curr == head->prev;
672 assert(curr !=
nullptr and head !=
nullptr);
684 throw std::overflow_error(
"Not element in list");
692 return head->
is_empty() ? false : curr == head->next;
709 throw std::underflow_error(
"Not previous element in list");
724 throw std::overflow_error(
"Not next element in list");
730 {
return curr == it.curr; }
734 {
return curr != it.curr; }
743 assert(curr !=
nullptr and head !=
nullptr);
752 Dlink * del_ne() noexcept
754 assert(curr !=
nullptr and head !=
nullptr);
807 throw std::domain_error(
"List is empty");
809 for (
size_t i = 0; i < n; ++i)
820 throw std::domain_error(
"List is empty");
822 for (
size_t i = 0; i < n; ++i)
887 # define DLINK_TO_TYPE(type_name, link_name) \ 888 inline static type_name * dlink_to_##type_name(Dlink * link) noexcept \ 890 type_name * ptr_zero = 0; \ 891 size_t offset_link = reinterpret_cast<size_t>(&(ptr_zero->link_name)); \ 892 char * address_type = reinterpret_cast<char*>(link) - offset_link; \ 893 return reinterpret_cast<type_name *>(address_type); \ 937 # define LINKNAME_TO_TYPE(type_name, link_name) \ 938 inline static type_name * link_name##_to_##type_name(Dlink * link) noexcept \ 940 type_name * ptr_zero = 0; \ 941 size_t offset_link = reinterpret_cast<size_t>(&(ptr_zero->link_name)); \ 942 char * address_type = reinterpret_cast<char*>(link) - offset_link; \ 943 return reinterpret_cast<type_name *>(address_type); \ 973 # define DLINK_TO_BASE(type_name, link_name) \ 974 inline static type_name * dlink_to_base(Dlink * link) noexcept \ 976 type_name * ptr_zero = 0; \ 977 size_t offset_link = reinterpret_cast<size_t>(&(ptr_zero->link_name)); \ 978 char * address_type = reinterpret_cast<char*>(link) - offset_link; \ 979 return reinterpret_cast<type_name *>(address_type); \ void prev_ne() noexcept
Definition: dlink.H:700
bool is_in_last() const noexcept
Return true if the iterator is positiones on the last item.
Definition: dlink.H:696
void init() noexcept
Definition: dlink.H:186
bool has_curr() const noexcept
Return true if the iterator has current item.
Definition: dlink.H:658
void next_ne() noexcept
Definition: dlink.H:715
bool is_unitarian_or_empty() const noexcept
Return true if this (as header node) has zeor or one element.
Definition: dlink.H:198
Dlink * remove_last() noexcept
Definition: dlink.H:454
Dlink * remove_prev() noexcept
Definition: dlink.H:413
void reset_last() noexcept
Reset the iterator to the last item of list.
Definition: dlink.H:645
Dlink *& get_first_ne() const noexcept
If this is a header node, it return the first node of this
Definition: dlink.H:255
Dlink * get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Definition: dlink.H:670
bool verify(const Iterator &it) const
Return true if this and it are on the same list.
Definition: dlink.H:767
void swap(list &c)
Definition: List.H:512
Dlink cut_list(Dlink *link) noexcept
Definition: dlink.H:556
bool operator!=(const Iterator &it) const noexcept
Return true if this and it hace different states.
Definition: dlink.H:733
Dlink() noexcept
Initialize a node or an empty list.
Definition: dlink.H:63
Dlink * remove_first_ne() noexcept
Definition: dlink.H:449
void splice(Dlink *l) noexcept
Definition: dlink.H:345
Dlink * remove_next() noexcept
Definition: dlink.H:434
void rotate_left(size_t n)
Definition: dlink.H:801
Dlink *& get_last() const noexcept
If this is a header node, it return the last node of this
Definition: dlink.H:264
size_t reverse() noexcept
Definition: dlink.H:499
void swap(Dlink *link) noexcept
Definition: dlink.H:82
bool check()
Return true if the list is consistent.
Definition: dlink.H:827
void rotate_right(size_t n)
Definition: dlink.H:814
void end() noexcept
Put the iterator out of range.
Definition: dlink.H:652
Dlink(Dlink &&l) noexcept
Definition: dlink.H:133
Dlink * pop()
Definition: dlink.H:472
bool operator==(const Iterator &it) const noexcept
Return true if this and it are positioned on the same item.
Definition: dlink.H:729
Dlink * remove_last_ne() noexcept
Definition: dlink.H:444
bool verify(Dlink *l) const
Return true if the iterator is on the list pointed by l
Definition: dlink.H:764
void insert(Dlink *node) noexcept
Definition: dlink.H:205
bool is_in_first() const noexcept
Return true if the iterator is positiones on the first item.
Definition: dlink.H:690
Dlink *& get_prev() const noexcept
Return the link that is before this
Definition: dlink.H:248
void append_list(Dlink *head) noexcept
Definition: dlink.H:329
size_t split_list_ne(Dlink &l, Dlink &r) noexcept
Definition: dlink.H:514
bool is_unitarian() const noexcept
Return true if this (as header node) has exactly one element.
Definition: dlink.H:195
void wrap_header(Dlink *l) noexcept
Definition: dlink.H:291
Dlink * get_curr() const
Definition: dlink.H:681
void concat_list(Dlink &head) noexcept
Definition: dlink.H:383
bool is_empty() const noexcept
Return true if this (as header node) is empty.
Definition: dlink.H:192
Dlink *& get_first() const noexcept
If this is a header node, it return the first node of this
Definition: dlink.H:261
Iterator(const Dlink &list) noexcept
Definition: dlink.H:616
Dlink * top()
Definition: dlink.H:465
Dlink * del() noexcept
Remove this from the list. this must not be a header node.
Definition: dlink.H:389
void prev()
Definition: dlink.H:706
void remove_all_and_delete() noexcept
Definition: dlink.H:781
void insert_list(Dlink *head) noexcept
Definition: dlink.H:307
void append(Dlink *node) noexcept
Definition: dlink.H:228
Iterator(Dlink *head_ptr) noexcept
Definition: dlink.H:609
void swap(Dlink &l) noexcept
Definition: dlink.H:121
Dlink *& get_next() const noexcept
Return the link that is after this
Definition: dlink.H:241
void concat_list(Dlink *head) noexcept
Definition: dlink.H:362
Dlink *& get_last_ne() const noexcept
If this is a header node, it return the last node of this
Definition: dlink.H:258
void reset() noexcept
Definition: dlink.H:180
size_t reverse_list() noexcept
Definition: dlink.H:483
void erase() noexcept
Definition: dlink.H:400
void push(Dlink *node) noexcept
Definition: dlink.H:218
Dlink * remove_first() noexcept
Definition: dlink.H:459
Dlink & operator=(const Dlink &l) noexcept
Definition: dlink.H:145
void reset_first() noexcept
Reset the iterator to the first item of list.
Definition: dlink.H:638
void next()
Definition: dlink.H:721
Dlink(const Dlink &l) noexcept
Definition: dlink.H:67
Dlink * del()
Definition: dlink.H:741