25 # ifndef DSGNODESDEF_H 26 # define DSGNODESDEF_H 42 : item(), next(nullptr)
48 : item(i), next(nullptr)
54 : item(std::forward<T>(i)), next(nullptr)
65 return next ==
nullptr;
107 next = ret_val->next;
120 : next(this), prev(this)
155 return next == prev and next ==
this;
165 return next == prev and next !=
this;
175 return (
const DL *&) next;
185 return (
const DL *&) prev;
190 assert(node !=
nullptr);
200 assert(node !=
nullptr);
238 node->next->prev = node->prev->next =
this;
247 next->prev = prev->next = node;
252 std::swap(next->prev, node->next->prev);
253 std::swap(prev->next, node->prev->next);
254 std::swap(next, node->next);
255 std::swap(prev, node->prev);
270 this->next = l->next;
271 l->next->prev =
this;
272 this->prev = l->prev;
273 l->prev->next =
this;
277 this->prev->next = l->next;
278 l->next->prev = this->prev;
279 l->prev->next =
this;
280 this->prev = l->prev;
291 void split(
DL &,
DL &);
311 : head(nullptr), curr(nullptr)
329 : head(it.head), curr(it.curr)
358 std::swap(head, it.head);
359 std::swap(curr, it.curr);
369 if (not has_current())
370 throw std::overflow_error(
"There is not current element");
377 if (not has_current())
378 throw std::overflow_error(
"There is not current element");
385 if (not has_current())
414 template <
typename T>
433 :
DL(), item(std::forward<T>(i))
502 return static_cast<DLNode *
>(Base::get_current());
507 return static_cast<DLNode *
>(Base::get_current());
512 return static_cast<DLNode *
>(Base::del());
517 return get_current();
522 return get_current();
527 template <
typename Key>
532 unsigned int is_leftmost : 4;
533 unsigned int is_rightmost : 4;
536 : is_leftmost(
true), is_rightmost(
true)
544 SiblingInfo sibling_info;
555 assert(first_child ==
nullptr);
574 :
Base(std::forward<Key>(k))
581 return Base::get_item();
586 return Base::get_item();
596 if (first_child ==
nullptr)
599 return to_treenode(first_child->
get_prev());
604 if (sibling_info.is_rightmost)
607 return to_treenode(const_cast<Base *>(Base::get_next()));
612 if (sibling_info.is_leftmost)
615 return to_treenode(const_cast<Base *>(Base::get_prev()));
620 return first_child ==
nullptr;
625 return not Base::is_empty();
630 return parent !=
nullptr;
635 return first_child !=
nullptr;
640 sibling_info.is_leftmost = sibling_info.is_rightmost =
true;
646 parent = first_child =
nullptr;
647 reset_sibling_info();
652 assert(s !=
nullptr);
655 Base::insert_next(s);
656 s->sibling_info.is_rightmost = sibling_info.is_rightmost;
657 s->sibling_info.is_leftmost =
false;
658 sibling_info.is_rightmost =
false;
664 assert(s !=
nullptr);
667 Base::insert_prev(s);
668 s->sibling_info.is_leftmost = sibling_info.is_leftmost;
669 s->sibling_info.is_rightmost =
false;
670 sibling_info.is_leftmost =
false;
673 if (s->sibling_info.is_leftmost and parent)
674 parent->first_child = s;
679 assert(c !=
nullptr);
683 if (first_child ==
nullptr)
684 insert_first_child(c);
691 assert(c !=
nullptr);
695 if (first_child ==
nullptr)
696 insert_first_child(c);
698 to_treenode(first_child->
get_prev())->add_right_sibling(c);
703 if (first_child ==
nullptr)
708 if (ret_val->sibling_info.is_rightmost)
709 first_child =
nullptr;
712 first_child = to_treenode(ret_val->
get_next());
713 first_child->sibling_info.is_leftmost =
true;
717 ret_val->parent =
nullptr;
724 if (first_child ==
nullptr)
729 if (ret_val->sibling_info.is_leftmost)
730 first_child =
nullptr;
737 ret_val->parent =
nullptr;
759 : first(nullptr), curr(nullptr)
765 : first(const_cast<
MTreeNode *>(&node)->get_first_child()),
772 : first(it.first), curr(it.curr), pos(it.pos)
803 std::swap(first, it.first);
804 std::swap(curr, it.curr);
805 std::swap(pos, it.pos);
815 return curr !=
nullptr;
820 if (not has_current())
821 throw std::overflow_error(
"There is not current element");
828 if (not has_current())
829 throw std::overflow_error(
"There is not current element");
836 if (not has_current())
837 throw std::out_of_range(
"There is not next element");
846 throw std::out_of_range(
"There is not previous element");
851 curr = to_treenode(first->
get_prev());
858 void for_each_child(Op &)
const;
863 for_each_child<Op>(op);
869 template <
typename Key>
875 while (ptr !=
nullptr)
882 template <
typename Key>
901 template <
typename Key,
class DerivedNodeType, BinTreeNodeNullValue NULL_VALUE>
904 static DerivedNodeType sentinel_node;
909 static DerivedNodeType *
const null;
913 DerivedNodeType * lchild;
914 DerivedNodeType * rchild;
918 : key(), lchild(null), rchild(null)
924 : key(k), lchild(null), rchild(null)
930 : key(std::forward<Key>(k)), lchild(null), rchild(null)
967 lchild = rchild = null;
971 template <
typename Key,
class DerivedNodeType, BinTreeNodeNullValue NULL_VALUE>
975 template <
typename Key,
class DerivedNodeType, BinTreeNodeNullValue NULL_VALUE>
976 DerivedNodeType *
const 980 template <
class BinTreeNode>
981 inline typename BinTreeNode::KeyType &
KEY(BinTreeNode * p)
986 template <
class BinTreeNode>
987 inline BinTreeNode *&
L(BinTreeNode * p)
989 return p->get_lchild();
992 template <
class BinTreeNode>
993 inline BinTreeNode *&
R(BinTreeNode * p)
995 return p->get_rchild();
998 template <
typename NodeInfo,
class CommonGraphNodeArc>
1007 : CommonGraphNodeArc(), info(), num_arcs(0), adjacent_arc_list()
1013 : CommonGraphNodeArc(), info(_info), num_arcs(0), adjacent_arc_list()
1019 : CommonGraphNodeArc(), info(std::forward<NodeInfo>(_info)), num_arcs(0),
1026 : CommonGraphNodeArc(), info(ptr->info), num_arcs(0), adjacent_arc_list()
1048 template <
class GraphNode,
typename ArcInfo,
class CommonGraphNodeArc>
1057 : src_node(nullptr), tgt_node(nullptr), info()
1063 : src_node(src), tgt_node(tgt), info()
1069 : src_node(src), tgt_node(tgt), info(_info)
1075 : src_node(src), tgt_node(tgt), info(std::forward<ArcInfo>(_info))
1103 if (node == get_src_node())
1104 return get_tgt_node();
1106 if (node == get_tgt_node())
1107 return get_src_node();
1109 throw std::logic_error(
"Arc is not adjacent to node");
1114 if (node == get_src_node())
1115 return get_tgt_node();
1117 if (node == get_tgt_node())
1118 return get_src_node();
1120 throw std::logic_error(
"Arc is not adjacent to node");
1136 # endif // DSGNODESDEF_H BaseGraphArc(GraphNode *src, GraphNode *tgt, const ArcInfo &_info)
Definition: nodesdef.H:1068
DL * remove_prev()
Definition: nodesdef.H:222
void swap(DL &node)
Definition: nodesdef.H:258
void insert_child(MTreeNode *c)
Definition: nodesdef.H:677
static DerivedNodeType *const null
Definition: nodesdef.H:909
BaseGraphNode(NodeInfo &&_info)
Definition: nodesdef.H:1018
DLNode * remove_next()
Definition: nodesdef.H:484
Key & get_key()
Definition: nodesdef.H:579
BaseGraphNode()
Definition: nodesdef.H:1006
const Key & get_key() const
Definition: nodesdef.H:950
Definition: nodesdef.H:999
ArcInfo info
Definition: nodesdef.H:1054
DL * get_head() const
Definition: nodesdef.H:299
NodeInfo & get_info()
Definition: nodesdef.H:1032
BaseGraphNode(const NodeInfo &_info)
Definition: nodesdef.H:1012
DLNode *& get_prev()
Definition: nodesdef.H:474
BaseBinTreeNode()
Definition: nodesdef.H:917
BaseGraphArc(GraphNode *src, GraphNode *tgt)
Definition: nodesdef.H:1062
Iterator()
Definition: nodesdef.H:310
GraphNode * get_src_node() const
Definition: nodesdef.H:1086
BaseBinTreeNode(Key &&k)
Definition: nodesdef.H:929
bool is_empty() const
Definition: nodesdef.H:153
Iterator(const Iterator &it)
Definition: nodesdef.H:328
DLNode * del()
Definition: nodesdef.H:510
Definition: nodesdef.H:113
MTreeNode * get_left_sibling() const
Definition: nodesdef.H:610
SLNode *& get_next()
Definition: nodesdef.H:83
T & get_item()
Definition: nodesdef.H:454
static void destroy_tree(MTreeNode *&)
Definition: nodesdef.H:883
void next()
Definition: nodesdef.H:383
DerivedNodeType *& get_lchild()
Definition: nodesdef.H:955
DLNode * remove_prev()
Definition: nodesdef.H:489
MTreeNode * get_current()
Definition: nodesdef.H:818
SLNode & operator=(const SLNode &)=delete
void append_child(MTreeNode *c)
Definition: nodesdef.H:689
Arc< GT > * KeyType
Definition: nodesdef.H:907
bool has_current() const
Definition: nodesdef.H:813
void concat(DL &l)
Definition: nodesdef.H:286
void prev()
Definition: nodesdef.H:391
Definition: iterator.H:36
DLNode(const T &i)
Definition: nodesdef.H:426
DL * get_current() const
Definition: nodesdef.H:375
bool is_unitarian_or_empty() const
Definition: nodesdef.H:158
Key & get_key()
Definition: nodesdef.H:945
void insert_next(DL *node)
Definition: nodesdef.H:188
void insert_next(SLNode *p)
Definition: nodesdef.H:93
DL * del()
Definition: nodesdef.H:404
GraphNode * get_tgt_node()
Definition: nodesdef.H:1091
BinTreeNode *& R(BinTreeNode *p)
Definition: nodesdef.H:993
bool is_empty() const
Definition: nodesdef.H:63
BaseBinTreeNode(BinTreeNodeCtor)
Definition: nodesdef.H:935
GraphNode * src_node
Definition: nodesdef.H:1052
BaseGraphArc()
Definition: nodesdef.H:1056
Definition: nodesdef.H:902
GraphNode * get_tgt_node() const
Definition: nodesdef.H:1096
const T & get_item() const
Definition: nodesdef.H:78
const DL *& get_prev() const
Definition: nodesdef.H:183
T & get_item()
Definition: nodesdef.H:73
nat_t num_arcs
Definition: nodesdef.H:1003
const DLNode *& get_prev() const
Definition: nodesdef.H:479
void reset_sibling_info()
Definition: nodesdef.H:638
DL *& get_prev()
Definition: nodesdef.H:178
ChildrenIterator(const ChildrenIterator &it)
Definition: nodesdef.H:771
void del()
Definition: nodesdef.H:208
ArcInfo & get_info()
Definition: nodesdef.H:1123
Definition: nodesdef.H:742
nat_t get_position() const
Definition: nodesdef.H:808
Iterator(DL *h)
Definition: nodesdef.H:316
DL()
Definition: nodesdef.H:119
BaseGraphArc(GraphNode *src, GraphNode *tgt, ArcInfo &&_info)
Definition: nodesdef.H:1074
const ArcInfo & get_info() const
Definition: nodesdef.H:1128
void reset()
Definition: nodesdef.H:643
Key & key(MapKey< Key, Value > &item)
Definition: map.H:53
SLNode()
Definition: nodesdef.H:41
void reset()
Definition: nodesdef.H:965
bool is_unitarian() const
Definition: nodesdef.H:163
bool is_leaf() const
Definition: nodesdef.H:618
void add_left_sibling(MTreeNode *s)
Definition: nodesdef.H:662
BinTreeNodeNullValue
Definition: nodesdef.H:899
MTreeNode * remove_first_child()
Definition: nodesdef.H:701
void for_each_child(Op &&op=Op()) const
Definition: nodesdef.H:861
void for_each_child(Op &) const
Definition: nodesdef.H:871
Key KeyType
Definition: nodesdef.H:561
BinTreeNode *& L(BinTreeNode *p)
Definition: nodesdef.H:987
bool has_current() const
Definition: nodesdef.H:362
SLNode(T &&i)
Definition: nodesdef.H:53
DLNode(DLNode &&n)
Definition: nodesdef.H:440
ChildrenIterator(const MTreeNode &node)
Definition: nodesdef.H:764
DLNode * get_current() const
Definition: nodesdef.H:505
Definition: nodesdef.H:415
GraphNode * get_src_node()
Definition: nodesdef.H:1081
const SLNode *& get_next() const
Definition: nodesdef.H:88
MTreeNode * get_first_child() const
Definition: nodesdef.H:589
void swap(Iterator &it)
Definition: nodesdef.H:356
void reset()
Definition: nodesdef.H:68
GraphNode * get_connected_node(GraphNode *node)
Definition: nodesdef.H:1101
BaseBinTreeNode(const Key &k)
Definition: nodesdef.H:923
Definition: nodesdef.H:494
Key ValueType
Definition: nodesdef.H:562
DLNode * get_current()
Definition: nodesdef.H:500
MTreeNode(Key &&k)
Definition: nodesdef.H:573
MTreeNode * get_last_child() const
Definition: nodesdef.H:594
DL * remove_next()
Definition: nodesdef.H:215
DLNode *& get_next()
Definition: nodesdef.H:464
NodeInfo info
Definition: nodesdef.H:1002
SLNode(const T &i)
Definition: nodesdef.H:47
BinTreeNode::KeyType & KEY(BinTreeNode *p)
Definition: nodesdef.H:981
BinTreeNodeCtor
Definition: nodesdef.H:897
BaseGraphNode(BaseGraphNode *ptr)
Definition: nodesdef.H:1025
Definition: iterator.H:112
DerivedNodeType *& get_rchild()
Definition: nodesdef.H:960
DL * get_location() const
Definition: nodesdef.H:304
DL(const DL &)
Definition: nodesdef.H:125
MTreeNode * get_current() const
Definition: nodesdef.H:826
bool has_parent() const
Definition: nodesdef.H:628
const Key & get_key() const
Definition: nodesdef.H:584
Iterator(Iterator &&it)
Definition: nodesdef.H:334
unsigned long int nat_t
Definition: types.H:50
MTreeNode * get_right_sibling() const
Definition: nodesdef.H:602
Key ItemType
Definition: nodesdef.H:563
const NodeInfo & get_info() const
Definition: nodesdef.H:1037
const DLNode *& get_next() const
Definition: nodesdef.H:469
DLNode(T &&i)
Definition: nodesdef.H:432
void swap(ChildrenIterator &it)
Definition: nodesdef.H:801
bool has_children() const
Definition: nodesdef.H:633
DLNode()
Definition: nodesdef.H:420
DL adjacent_arc_list
Definition: nodesdef.H:1004
Definition: nodesdef.H:35
void add_right_sibling(MTreeNode *s)
Definition: nodesdef.H:650
ChildrenIterator()
Definition: nodesdef.H:758
void reset()
Definition: nodesdef.H:148
MTreeNode(const Key &k)
Definition: nodesdef.H:567
GraphNode * get_connected_node(GraphNode *node) const
Definition: nodesdef.H:1112
DL * get_current()
Definition: nodesdef.H:367
bool has_siblings() const
Definition: nodesdef.H:623
MTreeNode * remove_last_child()
Definition: nodesdef.H:722
Iterator(DL *h, DL *c)
Definition: nodesdef.H:322
MTreeNode * get_location() const
Definition: nodesdef.H:752
Definition: nodesdef.H:1049
Definition: nodesdef.H:528
DL(DL &&l)
Definition: nodesdef.H:131
void concat(DL *l)
Definition: nodesdef.H:263
void next()
Definition: nodesdef.H:834
const T & get_item() const
Definition: nodesdef.H:459
void prev()
Definition: nodesdef.H:843
void reset()
Definition: nodesdef.H:399
DL *& get_next()
Definition: nodesdef.H:168
SLNode * remove_next()
Definition: nodesdef.H:101
void insert_prev(DL *node)
Definition: nodesdef.H:198
Definition: nodesdef.H:293
const DL *& get_next() const
Definition: nodesdef.H:173
nat_t get_num_arcs() const
Definition: nodesdef.H:1042
ChildrenIterator(ChildrenIterator &&it)
Definition: nodesdef.H:777
void swap(DL *node)
Definition: nodesdef.H:229
GraphNode * tgt_node
Definition: nodesdef.H:1053