135 template <
template <
typename>
class NodeType,
typename Key,
class Compare>
136 requires StrictWeakOrder<Compare, Key>
150 template <
class Inserter>
153 auto rec = [&] (
auto && self,
Node * n)
noexcept ->
void
155 if (n == Node::NullPtr)
188 std::swap(
cmp, tree.cmp);
189 std::swap(
root, tree.root);
212 noexcept(
std::is_nothrow_default_constructible_v<
Node>
and
213 std::is_nothrow_default_constructible_v<Compare>
and
214 std::is_nothrow_constructible_v<Compare, Compare &>)
229 noexcept(std::is_nothrow_default_constructible_v<Node>
and
230 std::is_nothrow_constructible_v<Compare, Compare &>)
254 noexcept(bin_node_detail::nothrow_header_from_v<Node>
and
255 bin_node_detail::nothrow_compare_taken_v<Compare>)
258 cmp(bin_node_detail::compare_to_take(tree.
cmp))
261 tree.root = Node::NullPtr;
275 noexcept(nothrow_compare_copy_v<Compare, Key>)
346 noexcept(nothrow_compare_copy_v<Compare, Key>)
370 noexcept(nothrow_compare_copy_v<Compare, Key>)
391 noexcept(nothrow_compare_v<Compare, Key>)
393 Aleph::split_key_dup_rec<Node, Compare>(
root, key,
l.root,
r.root,
cmp);
407 Node *
remove(
const Key & key)
noexcept(nothrow_compare_copy_v<Compare, Key>)
429 if (op.insert(root, n) == Node::NullPtr)
430 op.insert(dup.root, n);
451 move_all(t.root, [&] (
Node * n)
noexcept { op.insert_dup(root, n); });
467 root = Aleph::join_exclusive<Node>(
root, t.root);
468 t.root = Node::NullPtr;
493 template <
typename Key,
class Compare = Aleph::less<Key>>
494 requires StrictWeakOrder<Compare, Key>
508 template <
typename Key,
class Compare = Aleph::less<Key>>
C++20 concepts hub: comparison, BST policy, and Aleph container concepts.
Inorder iterator on the nodes of a binary tree.
Functor encompassing basic operation for binary search trees.
Node * insert(Node *&root, Node *p) noexcept(nothrow_compare_v< Cmp, Key >)
Insert a node p in a binary search tree.
Node * search_or_insert(Node *&r, Node *p) noexcept(nothrow_compare_v< Cmp, Key >)
Search or insert a node in a binary search tree.
Node * insert_dup(Node *&root, Node *p) noexcept(nothrow_compare_v< Cmp, Key >)
Insert a node p in a binary search tree.
Node * search(Node *root, const Key &key) noexcept(nothrow_compare_v< Cmp, Key >)
Search a node with a specific key.
Node * remove(Node *&root, const Key &key) noexcept(nothrow_compare_v< Cmp, Key >)
Remove a key from a binary search tree.
Simple (unbalanced) binary search tree.
GenBinTree & operator=(const GenBinTree &)=delete
static void move_all(Node *&src, Inserter inserter) noexcept
void split_dup(const Key &key, GenBinTree &l, GenBinTree &r) noexcept(nothrow_compare_v< Compare, Key >)
Split the tree according to a key that could be in the tree.
Node * insert(Node *p) noexcept(nothrow_compare_copy_v< Compare, Key >)
Insert a node in the tree.
void join_dup(GenBinTree &t) noexcept
Join this with t independently of the presence of duplicated keys.
bool verify() const
Return true if the tree is a consistent (correct) binary search tree.
GenBinTree(const GenBinTree &)=delete
GenBinTree(Compare _cmp) noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_constructible_v< Compare, Compare & >)
Builds an empty tree with the comparison criteria _cmp.
Node * getRoot() const noexcept
Return the root of tree.
Node *& getRoot() noexcept
Return the root of tree.
Node * insert_dup(Node *p) noexcept(nothrow_compare_copy_v< Compare, Key >)
Insert a node in the tree.
void swap(GenBinTree &tree) noexcept(std::is_nothrow_swappable_v< Compare >)
Swaps in constant time the nodes and the comparison criteria of this and tree.
bool split(const Key &key, GenBinTree &l, GenBinTree &r) noexcept(nothrow_compare_copy_v< Compare, Key >)
Split the tree according to a key.
Node * remove(const Key &key) noexcept(nothrow_compare_copy_v< Compare, Key >)
Remove a key from the tree.
Node * search_or_insert(Node *p) noexcept(nothrow_compare_copy_v< Compare, Key >)
Search or insert a key.
GenBinTree() noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_default_constructible_v< Compare > and std::is_nothrow_constructible_v< Compare, Compare & >)
Builds an empty tree with a comparison criteria built by default.
void join(GenBinTree &tree, GenBinTree &dup) noexcept
Join tree with this.
GenBinTree(GenBinTree &&tree) noexcept(bin_node_detail::nothrow_header_from_v< Node > and bin_node_detail::nothrow_compare_taken_v< Compare >)
Takes the nodes and the comparison criteria of tree, which is left empty and can take nodes again.
Compare & get_compare() noexcept
See key_comp().
void join_exclusive(GenBinTree &t) noexcept
Join exclusive of this with t
Compare & key_comp() noexcept
return the comparison criteria
Node * search(const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >)
Search a key.
virtual ~GenBinTree()=default
bool verifyBin() const
See verify().
Strict weak ordering constraint for BST comparators.
bool split_key_rec(Node *&root, const typename Node::key_type &key, Node *&ts, Node *&tg, const Compare &cmp=Compare()) noexcept(nothrow_compare_v< Compare, typename Node::key_type >)
Split recursively according to a key.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
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).