Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_balanceXt.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
43# ifndef TPL_BALANCEXT_H
44# define TPL_BALANCEXT_H
45
46# include <tpl_binNodeXt.H>
47 # include <ah-errors.H>
48
49using namespace Aleph;
50
51namespace Aleph {
52
71 template <class Node> inline
72Node * select_gotoup_root(Node * root, const size_t & i)
73{
74 assert(root not_eq Node::NullPtr);
75 assert(COUNT(Node::NullPtr) == 0);
76
77 if (i >= COUNT(root))
78 ah_out_of_range_error_if(true) << "";
79
80 if (i == COUNT(LLINK(root)))
81 return root;
82
83 if (i < COUNT(LLINK(root)))
84 {
87 }
88 else
89 {
91 i - COUNT(LLINK(root)) - 1);
93 }
94 return root;
95}
96
110template <class Node> inline Node * balance_tree(Node * root)
111{
112 if (COUNT(root) <= 1)
113 return root;
114
118
119 return root;
120}
121
122} // end namespace Aleph
123
124# endif // TPL_BALANCEXT_H
Exception handling system with formatted messages for Aleph-w.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
Definition ah-errors.H:579
WeightedDigraph::Node 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)
Definition gmpfrxx.h:4060
Node * select_gotoup_root(Node *root, const size_t &i)
Selecciona un nodo de un árbol binario según su posición infija y lo convierte en su raíz.
constexpr Node *& RLINK(Node *p) noexcept
Return the right tree of p.
auto & COUNT(Node *p) noexcept
Return the number of nodes of the tree fron p is root.
Node * rotate_to_left_xt(Node *p) noexcept
Rotate to left the extended binary tree with root p.
constexpr Node *& LLINK(Node *p) noexcept
Return a pointer to left subtree.
Node * rotate_to_right_xt(Node *p) noexcept
Rotate to right the extended bianry tree with root p
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
Node * balance_tree(Node *root)
Reequilibra un árbol binario de búsqueda.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Extended binary node with subtree count.