5 #include "size_holder.hpp" 6 #include "tree_iterator.hpp" 12 #include <type_traits> 14 #ifdef YGG_STORE_SEQUENCE 15 #include "benchmark_sequence.hpp" 25 #ifdef YGG_STORE_SEQUENCE 26 class DummySequenceInterface {
38 Node * get_parent()
const noexcept;
39 Node *& get_parent() noexcept;
40 void set_parent(Node * parent) noexcept;
41 static constexpr
bool parent_reference =
true;
52 init_root(Node * root)
const noexcept
57 descend_left(Node * child)
const noexcept
62 descend_right(Node * child)
const noexcept
67 found(Node * node)
const noexcept
71 void not_found()
const noexcept {};
76 template <
class Node,
class Tag = int,
84 compute_parent_pointer_type()
86 if constexpr (ParentContainer::parent_reference) {
87 return utilities::TypeHolder<Node *&>{};
89 return utilities::TypeHolder<Node *>{};
94 Node * _bst_children[2];
95 ParentContainer _bst_parent;
97 template <
class InnerNode>
98 friend InnerNode * utilities::go_right_if(
bool cond, InnerNode * parent);
99 template <
class InnerNode>
100 friend InnerNode * utilities::go_left_if(
bool cond, InnerNode * parent);
103 void set_parent(Node * new_parent) noexcept;
104 Node * get_parent()
const noexcept;
105 template <
class InnerPC = ParentContainer>
106 std::enable_if_t<InnerPC::parent_reference, Node *&> get_parent()
const 109 void set_left(Node * new_left) noexcept;
110 void set_right(Node * new_right) noexcept;
111 Node *& get_left() noexcept;
112 Node *& get_right() noexcept;
113 Node *
const & get_left()
const noexcept;
114 Node *
const & get_right()
const noexcept;
117 size_t get_depth()
const noexcept;
120 template <
class Node,
class Options,
class Tag = int,
121 class Compare = ygg::utilities::flexible_less,
129 static_assert(std::is_base_of<NB, Node>::value,
130 "Node class not properly derived from BSTNodeBase");
164 class NodeInterface {
167 get_parent(Node * n) noexcept
169 return n->NB::get_parent();
172 get_left(Node * n) noexcept
174 return n->NB::get_left();
177 get_right(Node * n) noexcept
179 return n->NB::get_right();
183 get_parent(
const Node * n) noexcept
185 return n->NB::get_parent();
188 get_left(
const Node * n) noexcept
190 return n->NB::get_left();
193 get_right(
const Node * n) noexcept
195 return n->NB::get_right();
201 template <
bool reverse>
204 template <
bool reverse>
205 class iterator :
public internal::IteratorBase<iterator<reverse>, Node,
206 NodeInterface, reverse> {
208 using internal::IteratorBase<iterator<reverse>, Node, NodeInterface,
209 reverse>::IteratorBase;
211 : internal::IteratorBase<iterator<reverse>, Node, NodeInterface,
214 : internal::IteratorBase<iterator<reverse>, Node, NodeInterface,
224 template <
bool reverse>
226 :
public internal::IteratorBase<const_iterator<reverse>, const Node,
227 NodeInterface, reverse> {
229 using internal::IteratorBase<const_iterator<reverse>,
const Node,
230 NodeInterface, reverse>::IteratorBase;
232 : internal::IteratorBase<const_iterator<reverse>,
const Node,
233 NodeInterface, reverse>(orig.n){};
235 : internal::IteratorBase<const_iterator<reverse>,
const Node,
236 NodeInterface, reverse>(orig.n){};
238 : internal::IteratorBase<const_iterator<reverse>,
const Node,
239 NodeInterface, reverse>(){};
253 inline Node * get_first_equal(Node * n) noexcept;
277 template <
class Comparable,
bool ensure_first = false>
280 template <
class Comparable,
bool ensure_first = false>
286 template <
class Comparable,
class Callbacks = DefaultFindCallbacks<Node>>
311 template <
class Comparable>
314 template <
class Comparable>
315 iterator<false> upper_bound(
const Comparable & query) CMP_NOEXCEPT(query);
338 template <
class Comparable>
341 template <
class Comparable>
342 iterator<false> lower_bound(
const Comparable & query) CMP_NOEXCEPT(query);
352 template <
class NodeTraits>
353 void dump_to_dot(
const std::string & filename)
const;
416 size_t size()
const noexcept;
423 void clear() noexcept;
432 bool empty()
const noexcept;
436 Node * get_root()
const noexcept;
437 static Node * get_parent(Node * n) noexcept;
438 static Node * get_left_child(Node * n) noexcept;
439 static Node * get_right_child(Node * n) noexcept;
443 bool verify_integrity()
const;
444 void dbg_verify()
const;
445 void dbg_print_tree()
const;
451 Node * get_smallest()
const noexcept;
452 Node * get_largest()
const noexcept;
453 Node * get_uncle(Node * node)
const noexcept;
457 SizeHolder<Options::constant_time_size> s;
460 template <
class NodeNameGetter>
461 void dump_to_dot_base(
const std::string & filename,
462 NodeNameGetter name_getter)
const;
464 template <
class NodeNameGetter>
465 void output_node_base(
const Node * node, std::ofstream & out,
466 NodeNameGetter name_getter)
const;
469 void verify_tree()
const;
470 void verify_order()
const;
471 void verify_size()
const;
474 #ifdef YGG_STORE_SEQUENCE 475 typename ygg::utilities::template BenchmarkSequenceStorage<
476 typename Options::SequenceInterface::KeyT>
488 #endif // YGG_BST_HPP
Definition: rbtree.hpp:18