1 # ifndef TPL_BINTREEOPS_H
2 # define TPL_BINTREEOPS_H
4 # include <tpl_binNodeUtils.H>
5 # include <tpl_binNodeXt.H>
40 typedef typename Node::key_type
Key;
53 return searchInBinTree <Node, Cmp> (root, key, cmp);
74 return Aleph::search_parent<Node, Cmp>(root, key, parent, cmp);
95 return Aleph::search_rank_parent<Node, Cmp>(root, key, cmp);
113 if (root == Node::NullPtr)
116 if (cmp(
KEY(p),
KEY(root)))
118 else if (cmp(
KEY(root),
KEY(p)))
121 return Node::NullPtr;
141 if (root == Node::NullPtr)
144 if (cmp(
KEY(p),
KEY(root)))
168 if (r == Node::NullPtr)
173 else if (cmp (
KEY(r),
KEY(p)))
198 if (root == Node::NullPtr)
200 ts = tg = Node::NullPtr;
205 if (cmp(key,
KEY(root)) )
215 if (cmp(
KEY(root), key) )
245 Node *& ts, Node *& tg)
247 if (root == Node::NullPtr)
249 ts = tg = Node::NullPtr;
254 if (cmp(key,
KEY(root)))
256 else if (cmp(
KEY(root), key))
278 Node *
remove(Node *& root,
const Key & key)
280 if (root == Node::NullPtr)
281 return Node::NullPtr;
283 if (cmp (key,
KEY(root)))
284 return remove((Node*&)
LLINK(root), key);
285 else if (cmp(
KEY(root), key))
286 return remove((Node*&)
RLINK(root), key);
288 Node * ret_val = root;
316 Node * l = Node::NullPtr, * r = Node::NullPtr;
319 return Node::NullPtr;
374 if (t2 == Node::NullPtr)
377 Node * l = (Node*)
LLINK(t2);
378 Node * r = (Node*)
RLINK(t2);
380 if (
insert(t1, t2) == Node::NullPtr)
406 Node *
join(Node * t1, Node * t2, Node *& dup)
408 if (t1 == Node::NullPtr)
411 if (t2 == Node::NullPtr)
414 Node * l = (Node*)
LLINK(t1);
415 Node * r = (Node*)
RLINK(t1);
422 Node * p =
remove(t1,
KEY(t1));
424 I(p != Node::NullPtr);
460 if (root == Node::NullPtr)
462 l = r = (Node*) Node::NullPtr;
468 Node ** current_parent = NULL;
469 Node ** pending_child = NULL;
470 char current_is_right;
472 if (cmp (key,
KEY(root)))
476 current_is_right =
true;
482 current_is_right =
false;
487 while (current != Node::NullPtr)
489 if (cmp (key,
KEY(current)))
491 if (not current_is_right)
493 current_is_right = not current_is_right;
494 *pending_child = *current_parent;
495 pending_child = current_parent;
498 current_parent =
static_cast<Node**
>(&
LLINK(current));
502 if (current_is_right)
504 current_is_right = not current_is_right;
505 *pending_child = *current_parent;
506 pending_child = current_parent;
508 current_parent =
static_cast<Node**
>(&
RLINK(current));
511 current = *current_parent;
514 *pending_child =
static_cast<Node*
>(Node::NullPtr);
535 if (root == Node::NullPtr)
538 if (cmp(
KEY(p),
KEY(root)))
541 if (left_branch == Node::NullPtr)
542 return (Node*) Node::NullPtr;
544 LLINK(root) = left_branch;
547 else if (cmp(
KEY(root),
KEY(p)))
550 if (right_branch == Node::NullPtr)
551 return (Node*) Node::NullPtr;
553 RLINK(root) = right_branch;
557 return (Node*) Node::NullPtr;
580 if (root == Node::NullPtr)
583 if (cmp(
KEY(p),
KEY(root)))
586 if (left_branch == p)
588 LLINK(root) = left_branch;
596 else if (cmp(
KEY(root),
KEY(p)))
599 if (right_branch == p)
601 RLINK(root) = right_branch;
629 template <
class Node,
636 typedef typename Node::key_type
Key;
670 I(
COUNT(Node::NullPtr) == 0);
672 if (r == Node::NullPtr)
675 if (this->cmp(key,
KEY(r)))
677 else if (this->cmp(
KEY(r), key))
727 I(
COUNT(Node::NullPtr) == 0);
729 Node * parent = NULL;
732 while (r != Node::NullPtr)
733 if (this->cmp(key,
KEY(r)))
736 r = (Node*)
LLINK(r);
739 else if (this->cmp(
KEY(r), key))
742 r = (Node*)
RLINK(r);
777 if (root == Node::NullPtr)
779 l = r = Node::NullPtr;
784 if (this->cmp(key,
KEY(root)))
792 else if (this->cmp(
KEY(root), key))
824 if (root == Node::NullPtr)
826 l = r = Node::NullPtr;
831 if (this->cmp(key,
KEY(root)))
837 else if (this->cmp(
KEY(root), key))
868 if (root == Node::NullPtr)
872 return Node::NullPtr;
895 if (root == Node::NullPtr)
908 # endif // TPL_BINTREEOPS_H
Node * rotate_to_left(Node *p)
Definition: tpl_binNodeUtils.H:2422
#define LLINK(p)
Definition: tpl_binNode.H:196
Node::key_type Key
El tipo de clave de búsqueda.
Definition: tpl_binTreeOps.H:40
void split_key_dup_rec(Node *root, const typename Node::key_type &key, Node *&ts, Node *&tg)
Definition: tpl_binTreeOps.H:244
#define RLINK(p)
Definition: tpl_binNode.H:201
Definition: ahFunction.H:145
Node * insert(Node *&root, Node *p)
Definition: tpl_binTreeOps.H:111
Node * insert_dup_root(Node *&root, Node *p)
Definition: tpl_binTreeOps.H:893
int inorder_position(Node *r, const Key &key, Node *&p)
Definition: tpl_binTreeOps.H:668
#define COUNT(p)
Definition: tpl_binNodeXt.H:34
void split_key(Node *root, const Key &key, Node *&l, Node *&r)
Definition: tpl_binTreeOps.H:458
bool split_key_rec(Node *root, const Key &key, Node *&ts, Node *&tg)
Definition: tpl_binTreeOps.H:196
Node * rotate_to_right(Node *p)
Definition: tpl_binNodeUtils.H:2375
Node * search(Node *root, const Key &key)
Definition: tpl_binTreeOps.H:51
Definition: tpl_binTreeOps.H:632
int find_position(Node *r, const Key &key, Node *&p)
Definition: tpl_binTreeOps.H:725
Node * join_exclusive(Node *&ts, Node *&tg)
Definition: tpl_binNodeUtils.H:2155
Node * insert_root(Node *&root, Node *p)
Definition: tpl_binTreeOps.H:866
Node::key_type key_type
El tipo de clave de búsqueda.
Definition: tpl_binTreeOps.H:43
Cmp & get_compare()
Definition: tpl_binTreeOps.H:37
Cmp & key_comp()
Retorna una referencia al criterio de comparación.
Definition: tpl_binTreeOps.H:34
Node * join_preorder(Node *t1, Node *t2, Node *&dup)
Definition: tpl_binTreeOps.H:372
Node * join(Node *t1, Node *t2, Node *&dup)
Definition: tpl_binTreeOps.H:406
bool split_key_rec(Node *root, const Key &key, Node *&l, Node *&r)
Definition: tpl_binTreeOps.H:775
Node * search_or_insert_root_rec(Node *root, Node *p)
Definition: tpl_binTreeOps.H:578
void split_key_dup_rec(Node *root, const Key &key, Node *&l, Node *&r)
Definition: tpl_binTreeOps.H:822
Node * insert_root(Node *&root, Node *p)
Definition: tpl_binTreeOps.H:314
Node * insert_root_rec(Node *root, Node *p)
Definition: tpl_binTreeOps.H:533
#define KEY(p)
Definition: tpl_binNode.H:206
Node * search_rank_parent(Node *root, const Key &key)
Definition: tpl_binTreeOps.H:93
Definition: tpl_binTreeOps.H:25
Node * insert_dup(Node *&root, Node *p)
Definition: tpl_binTreeOps.H:139
Node * search_parent(Node *root, const Key &key, Node *&parent)
Definition: tpl_binTreeOps.H:72
Node * insert_dup_root(Node *&root, Node *p)
Definition: tpl_binTreeOps.H:348
Node * search_or_insert(Node *&r, Node *p)
Definition: tpl_binTreeOps.H:166