134 template <
template <
typename>
class NodeType,
typename Key,
class Compare>
148 template <
class Inserter>
151 auto rec = [&] (
auto && self,
Node * n)
noexcept ->
void
153 if (n == Node::NullPtr)
178 std::swap(
root, tree.root);
179 std::swap(
cmp, tree.cmp);
318 if (op.insert(root, n) == Node::NullPtr)
319 op.insert(dup.root, n);
334 move_all(t.root, [&] (
Node * n)
noexcept { op.insert_dup(root, n); });
351 t.root = Node::NullPtr;
376 template <
typename Key,
class Compare = Aleph::less<Key>>
390 template <
typename Key,
class Compare = Aleph::less<Key>>
Inorder iterator on the nodes of a binary tree.
T & insert(const T &item)
Insert a new item by copy.
T remove()
Remove the first item of the list.
Simple (unbalanced) binary search tree.
GenBinTree & operator=(const GenBinTree &)=delete
static void move_all(Node *&src, Inserter inserter) noexcept
void join_dup(GenBinTree &t) noexcept
Join this with t independently of the presence of duplicated keys.
GenBinTree(const GenBinTree &)=delete
Node * getRoot() const noexcept
Return the root of tree.
Node *& getRoot() noexcept
Return the root of tree.
bool split(const Key &key, GenBinTree &l, GenBinTree &r) noexcept
Split the tree according to a key.
bool verify() const
Return true if the tree is a consistent (correct) binary search tree.
Node * insert(Node *p) noexcept
Insert a node in the tree.
Compare & key_comp() noexcept
return the comparison criteria
void split_dup(const Key &key, GenBinTree &l, GenBinTree &r) noexcept
Split the tree according to a key that could be in the tree.
Node * search(const Key &key) const noexcept
Search a key.
GenBinTree(Compare _cmp=Compare()) noexcept
Initialize an empty tree with comparison criteria __cmp
void join(GenBinTree &tree, GenBinTree &dup) noexcept
Join tree with this.
Compare & get_compare() noexcept
Node * insert_dup(Node *p) noexcept
Insert a node in the tree.
Node * remove(const Key &key) noexcept
Remove a key from the tree.
void join_exclusive(GenBinTree &t) noexcept
Join exclusive of this with t
void swap(GenBinTree &tree) noexcept
Swap this with tree in constant time.
virtual ~GenBinTree()=default
Node * search_or_insert(Node *p) noexcept
Search or insert a key.
bool split_key_rec(Node *&root, const typename Node::key_type &key, Node *&ts, Node *&tg, const Compare &cmp=Compare()) noexcept
Split recursively according to a key.
constexpr Node *& RLINK(Node *p) noexcept
Return the right tree of p.
constexpr Node *& LLINK(Node *p) noexcept
Return a pointer to left subtree.
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Binary search tree with nodes with virtual destructors,.
Binary search tree with nodes without virtual destructors,.
Iterator on nodes of the tree.
Iterator() noexcept=default
Default constructor creates an "end" iterator.
Iterator(const GenBinTree &tree)
Binary tree operations (split, join, rotate).