43# ifndef TPL_BINNODEXT_H
44# define TPL_BINNODEXT_H
85template <RankedBinNodeLike Node>
inline auto &
COUNT(
Node * p)
noexcept
91 template <RankedBinNodeLike Node>
static inline
94 assert(
r != Node::NullPtr);
95 assert(
COUNT(Node::NullPtr) == 0);
117 template <RankedBinNodeLike Node>
inline
135 template <RankedBinNodeLike Node>
inline
138 assert(
COUNT(Node::NullPtr) == 0);
167 template <RankedBinNodeLike Node>
inline
188 template <RankedBinNodeLike Node>
inline
193 parent = Node::NullPtr;
225 template <RankedBinNodeLike Node,
class Compare>
inline
227 const typename Node::key_type & key,
229 noexcept(nothrow_compare_v<Compare, typename Node::key_type>)
231 assert(
COUNT(Node::NullPtr) == 0);
233 if (
r == Node::NullPtr)
250template <BinNodeLike Node,
class Compare = Aleph::less<
typename Node::key_type>>
252 const typename Node::key_type & key,
253 Node *& p, Compare &&
cmp = Compare())
260 template <BinNodeLike Node,
class Compare>
inline
263 noexcept(nothrow_compare_v<Compare, typename Node::key_type>)
270 template <BinNodeLike Node,
class Compare = Aleph::less<
typename Node::key_type>>
272 Compare &&
cmp = Compare())
307 template <RankedBinNodeLike
Node,
311 noexcept(nothrow_compare_v<Compare, typename Node::key_type>)
313 assert(
COUNT(Node::NullPtr) == 0);
316 Node * candidate = Node::NullPtr;
318 while (
r != Node::NullPtr)
335 if (candidate != Node::NullPtr)
346template <BinNodeLike
Node,
349 Node *& p, Compare &&
cmp = Compare())
373template <RankedBinNodeLike Node,
class Compare>
inline
375 noexcept(nothrow_compare_v<Compare, typename Node::key_type>)
377 const typename Node::key_type & key =
KEY(p);
379 while (
r != Node::NullPtr)
413 template <RankedBinNodeLike Node,
class Compare>
inline
416 assert(
COUNT(Node::NullPtr) == 0);
418 if (
r == Node::NullPtr)
421 Node * q = Node::NullPtr;
425 if (q != Node::NullPtr)
431 if (q != Node::NullPtr)
440 template <BinNodeLike
Node,
458 template <RankedBinNodeLike Node,
class Compare>
inline
461 assert(
COUNT(Node::NullPtr) == 0);
463 if (
r == Node::NullPtr)
478 template <BinNodeLike
Node,
499 template <RankedBinNodeLike Node,
class Compare>
inline
502 assert(
COUNT(Node::NullPtr) == 0);
504 if (
r == Node::NullPtr)
527template <BinNodeLike
Node,
530 Compare &&
cmp = Compare()) noexcept
551 template <RankedBinNodeLike Node,
class Compare>
static inline
554 noexcept(nothrow_compare_v<Compare, typename Node::key_type>)
556 if (
root == Node::NullPtr)
558 l =
r = Node::NullPtr;
603template <BinNodeLike Node,
class Compare>
inline
606 noexcept(nothrow_compare_v<Compare, typename Node::key_type>)
610 root = Node::NullPtr;
627template <BinNodeLike
Node,
652 template <RankedBinNodeLike Node,
class Compare>
static inline
655 noexcept(nothrow_compare_v<Compare, typename Node::key_type>)
657 if (
root == Node::NullPtr)
659 l =
r = Node::NullPtr;
696 template <BinNodeLike Node,
class Compare>
inline
699 noexcept(nothrow_compare_v<Compare, typename Node::key_type>)
701 __split_key_dup_rec_xt<Node, Compare>(
root, key,
l,
r,
cmp);
702 root = Node::NullPtr;
717 template <BinNodeLike
Node,
741 template <RankedBinNodeLike Node,
class Compare>
inline
744 if (
root == Node::NullPtr)
751 return Node::NullPtr;
760 template <BinNodeLike
Node,
782 template <RankedBinNodeLike Node,
class Compare>
inline
785 if (
root == Node::NullPtr)
799template <BinNodeLike
Node,
808 template <RankedBinNodeLike Node>
static inline
815 LLINK(tg) = Node::NullPtr;
850template <RankedBinNodeLike Node>
inline
858 r = tg = Node::NullPtr;
862 __split_pos_rec<Node>(
r, i, ts, tg);
881 template <RankedBinNodeLike Node>
inline
884 assert(
COUNT(Node::NullPtr) == 0);
903 template <RankedBinNodeLike Node>
inline
906 if (ts == Node::NullPtr)
909 if (tg == Node::NullPtr)
920 ts = tg = Node::NullPtr;
941 template <RankedBinNodeLike
Node,
944 Compare &
cmp)
noexcept
946 if (
root == Node::NullPtr)
947 return Node::NullPtr;
949 Node * ret_val = Node::NullPtr;
953 if (ret_val != Node::NullPtr)
961 if (ret_val != Node::NullPtr)
976template <BinNodeLike Node,
class Compare = Aleph::less<
typename Node::key_type>>
978 const typename Node::key_type & key,
979 Compare &&
cmp = Compare()) noexcept
985 template <RankedBinNodeLike Node>
static inline
1004 if (ret_val != Node::NullPtr)
1020 template <RankedBinNodeLike Node>
inline
1032 template <RankedBinNodeLike Node>
inline
1035 if (
root == Node::NullPtr)
1050 template <RankedBinNodeLike Node>
inline
1053 assert(p != Node::NullPtr);
1071 template <RankedBinNodeLike Node>
inline
1074 assert(p != Node::NullPtr);
1097 template <RankedBinNodeLike Node,
class Key,
class Compare>
inline
1101 if (
root == Node::NullPtr)
1106 Node * left_branch = search_or_insert_root_rec_xt<Node, Key>(
LLINK(
root), p,
cmp);
1107 if (left_branch == p)
1119 Node * right_branch = search_or_insert_root_rec_xt<Node, Key>(
RLINK(
root), p,
cmp);
1120 if (right_branch == p)
1128 return right_branch;
1135template <BinNodeLike
Node,
class Key,
1138 Compare &&
cmp = Compare()) noexcept
1140 return search_or_insert_root_rec_xt<Node, Key>(
root, p,
cmp);
1162template <
class TreeType,
class Node,
typename Key,
class Compare>
1190 return curr !=
nullptr;
1200 assert(
curr !=
nullptr);
1213 constexpr auto max_pos =
1214 static_cast<size_t>(std::numeric_limits<int>::max());
1317 noexcept(
noexcept(
tree_ptr->find_position(key)))
1319 std::pair<long, Node*> p =
tree_ptr->find_position(key);
1377 <<
"Iterator has no current";
1451 noexcept(nothrow_compare_v<Compare, Key>)
1460 return curr == itor.curr;
1474 return not (*
this == itor);
C++20 concepts hub: comparison, BST policy, and Aleph container concepts.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
#define ah_range_error_if(C)
Throws std::range_error if condition holds.
SentinelCtor
Tag type for sentinel node construction.
void put_itor_at_the_end(Itor &it) noexcept
WeightedDigraph::Node Node
BinNodeXt_Data(SentinelCtor) noexcept
size_t size() const noexcept
BinNodeXt_Data() noexcept
size_t & getCount() noexcept
Node for extended binary search tree.
Base iterator template for ranked binary search trees.
BinTreeXt_Iterator() noexcept
void reset_last() noexcept
static constexpr int Pos_Empty_Container
bool operator==(const BinTreeXt_Iterator &itor) const noexcept(nothrow_compare_v< Compare, Key >)
Return true if this and itor are on the same position.
void reset_first() noexcept
void update_curr() const noexcept
bool has_curr() const noexcept(nothrow_compare_v< Compare, Key >)
Return true if the iterator has a current node.
void next_ne() noexcept
Move the iterator one position forward, without the check of next().
void update_pos() const noexcept(nothrow_compare_v< Compare, Key >)
void reset_to_key(const Key &key) noexcept(noexcept(tree_ptr->find_position(key)))
Put the iterator on the node of a key.
static constexpr int Pos_Out_Of_Range
Node * get_curr_ne() const noexcept
Return the current node.
BinTreeXt_Iterator(const TreeType &__tree, Node *__curr) noexcept
bool curr_updated() const noexcept
void reset_to_node(Node *node) noexcept
static constexpr int Pos_Not_Current
BinTreeXt_Iterator(const TreeType &__tree, const size_t pos) noexcept
Initialize an iterator on the inorder position pos.
BinTreeXt_Iterator & operator=(const BinTreeXt_Iterator &itor) noexcept
void reset_to_pos(const size_t pos) noexcept
Put the iterator on the inorder position pos.
bool is_container_empty() const noexcept
size_t get_current_position() const
static constexpr int Pos_Not_Updated
static int saturated_pos(const size_t pos) noexcept
BinTreeXt_Iterator(const BinTreeXt_Iterator &itor) noexcept
bool pos_updated() const noexcept
BinTreeXt_Iterator(const TreeType &__tree) noexcept
bool operator!=(const BinTreeXt_Iterator &itor) const
Node * get_curr() const noexcept
Return the current node.
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
int cmp(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
long inorder_position_of_node(Node *r, Node *p, Compare &cmp) noexcept(nothrow_compare_v< Compare, typename Node::key_type >)
The inorder position of the node p, in a tree that may have keys equivalent to that of p.
static void __split_key_dup_rec_xt(Node *root, const typename Node::key_type &key, Node *&l, Node *&r, Compare &cmp) noexcept(nothrow_compare_v< Compare, typename Node::key_type >)
The recursion of split_key_dup_rec_xt().
Node * insert_dup_root_xt(Node *&root, Node *p, Compare &cmp) noexcept
Insert a node as root of an extended binary search tree.
Node * insert_dup_by_key_xt(Node *&r, Node *p, Compare &cmp) noexcept
Insert a node in an extended binary search tree without testing for duplicity.
static bool __split_key_rec_xt(Node *root, const typename Node::key_type &key, Node *&l, Node *&r, Compare &cmp) noexcept(nothrow_compare_v< Compare, typename Node::key_type >)
The recursion of split_key_rec_xt().
bool split_key_rec_xt(Node *&root, const typename Node::key_type &key, Node *&l, Node *&r, Compare &cmp) noexcept(nothrow_compare_v< Compare, typename Node::key_type >)
Split an extended binary search tree according to a key.
bool check_rank_tree(Node *root) noexcept
Return true if root is a valid extended binary tree.
void split_pos_rec(Node *&r, const size_t i, Node *&ts, Node *&tg)
Split a extended binary tree according to a position.
Node * insert_by_key_xt(Node *&r, Node *p, Compare &cmp) noexcept
Insert a node in an extended binary search tree.
#define DECLARE_BINNODE_SENTINEL(Name, height, Control_Data)
Specify tree node for a binary tree.
auto & COUNT(Node *p) noexcept
Return the number of nodes of the tree fron p is root.
void split_key_dup_rec_xt(Node *&root, const typename Node::key_type &key, Node *&l, Node *&r, Compare &cmp) noexcept(nothrow_compare_v< Compare, typename Node::key_type >)
Split an extended binary search tree according to a key which can be in the tree.
Node * insert_root_xt(Node *&root, Node *p, Compare &cmp) noexcept
Insert a node p as root of an extended binary search tree.
Node * remove_by_pos_xt(Node *&root, size_t pos)
Remove from a extended binary tree the node whose inorder position is pos.
Node * remove_by_key_xt(Node *&root, const typename Node::key_type &key, Compare &cmp) noexcept
Remove a key of extended binary tree.
long inorder_position(Node *r, const typename Node::key_type &key, Node *&p, Compare &cmp) noexcept(nothrow_compare_v< Compare, typename Node::key_type >)
Compute the inorder position of a key.
Node * rotate_to_left_xt(Node *p) noexcept
Rotate to left the extended binary tree with root p.
Node * select(Node *r, const size_t pos)
Iterative selection of a node according to inorder position.
Node * select_ne(Node *r, const size_t pos) noexcept
Iterative selection of a node according to inorder position without exception.
Node * rotate_to_right_xt(Node *p) noexcept
Rotate to right the extended bianry tree with root p
void insert_by_pos_xt(Node *&r, Node *p, size_t pos)
Insert a node in a specific inorder position in a binary tree.
Node * select_rec(Node *r, const size_t i)
Recursively select the i-th node inorder sense.
constexpr bool nothrow_compare_v
Whether Compare compares two keys of type Key without throwing, as the operations of the trees call i...
Node * join_exclusive_xt(Node *&ts, Node *&tg) noexcept
Exclusive union of two extended binary search trees.
const long double offset[]
Offset values indexed by symbol string length (bounded by MAX_OFFSET_INDEX)
Main namespace for Aleph-w library functions.
Node * search_or_insert_by_key_xt(Node *&r, Node *p, Compare &cmp) noexcept
Search or insert a node in an extended binary search tree.
static Node * __remove_by_pos_xt(Node *&root, size_t pos) noexcept
and
Check uniqueness with explicit hash + equality functors.
Node * search_or_insert_root_rec_xt(Node *root, Node *p, Compare &cmp) noexcept
Search or insert a key in an extended binary search tree.
static Node * __select_rec(Node *r, const size_t i) noexcept
long find_position(Node *r, const typename Node::key_type &key, Node *&p, Compare &cmp) noexcept(nothrow_compare_v< Compare, typename Node::key_type >)
Find the inorder position of a key in an extended binary search tree.
static void __split_pos_rec(Node *r, size_t i, Node *&ts, Node *&tg) noexcept
Utility functions for binary tree operations.
Basic binary tree node definitions.