~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/ut/ut0rbt.c

  • Committer: Marisa Plumb
  • Date: 2010-11-30 00:28:02 UTC
  • mto: This revision was merged to the branch mainline in revision 1984.
  • Revision ID: marisa.plumb@gmail.com-20101130002802-vapha1qp5giia1s7
edits and basic rewrites to the introduction docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************//**
2
 
 
3
 
Copyright (C) 2007, 2010, Innobase Oy. All Rights Reserved.
4
 
 
5
 
Portions of this file contain modifications contributed and copyrighted by
6
 
Sun Microsystems, Inc. Those modifications are gratefully acknowledged and
7
 
are described briefly in the InnoDB documentation. The contributions by
8
 
Sun Microsystems are incorporated with their permission, and subject to the
9
 
conditions contained in the file COPYING.Sun_Microsystems.
 
1
/*****************************************************************************
 
2
 
 
3
Copyright (c) 2006, 2009, Innobase Oy. All Rights Reserved.
10
4
 
11
5
This program is free software; you can redistribute it and/or modify it under
12
6
the terms of the GNU General Public License as published by the Free Software
21
15
Place, Suite 330, Boston, MA 02111-1307 USA
22
16
 
23
17
*****************************************************************************/
24
 
/********************************************************************//**
 
18
 
 
19
/*******************************************************************//**
 
20
@file ut/ut0rbt.c
25
21
Red-Black tree implementation
26
22
 
27
 
(c) 2007 Oracle/Innobase Oy
28
 
 
29
23
Created 2007-03-20 Sunny Bains
30
24
***********************************************************************/
31
25
 
32
26
#include "ut0rbt.h"
33
27
 
34
 
/**********************************************************************//**
 
28
/************************************************************************
35
29
Definition of a red-black tree
36
30
==============================
37
31
 
47
41
   from (3) above, the implication is that on any path from the root
48
42
   to a leaf, red nodes must not be adjacent.
49
43
 
50
 
   However, any number of black nodes may appear in a sequence.
51
 
 */
 
44
   However, any number of black nodes may appear in a sequence. */
52
45
 
53
46
#if     defined(IB_RBT_TESTING)
54
47
#warning "Testing enabled!"
57
50
#define ROOT(t)         (t->root->left)
58
51
#define SIZEOF_NODE(t)  ((sizeof(ib_rbt_node_t) + t->sizeof_value) - 1)
59
52
 
60
 
/**********************************************************************//**
 
53
/****************************************************************//**
61
54
Print out the sub-tree recursively. */
62
55
static
63
56
void
64
57
rbt_print_subtree(
65
58
/*==============*/
66
 
        const ib_rbt_t*         tree,           /*!< in: tree to traverse */
67
 
        const ib_rbt_node_t*    node,           /*!< in: node to print */
68
 
        ib_rbt_print_node       print)          /*!< in: print key function */
 
59
        const ib_rbt_t*         tree,   /*!< in: tree to traverse */
 
60
        const ib_rbt_node_t*    node,   /*!< in: node to print */
 
61
        ib_rbt_print_node       print)  /*!< in: print key function */
69
62
{
70
63
        /* FIXME: Doesn't do anything yet */
71
64
        if (node != tree->nil) {
75
68
        }
76
69
}
77
70
 
78
 
/**********************************************************************//**
 
71
/****************************************************************//**
79
72
Verify that the keys are in order.
80
73
@return TRUE of OK. FALSE if not ordered */
81
74
static
82
75
ibool
83
76
rbt_check_ordering(
84
77
/*===============*/
85
 
        const ib_rbt_t*         tree)           /*!< in: tree to verfify */
 
78
        const ib_rbt_t*         tree)   /*!< in: tree to verfify */
86
79
{
87
80
        const ib_rbt_node_t*    node;
88
81
        const ib_rbt_node_t*    prev = NULL;
100
93
        return(TRUE);
101
94
}
102
95
 
103
 
/**********************************************************************//**
 
96
/****************************************************************//**
104
97
Check that every path from the root to the leaves has the same count.
105
98
Count is expressed in the number of black nodes.
106
99
@return 0 on failure else black height of the subtree */
108
101
ibool
109
102
rbt_count_black_nodes(
110
103
/*==================*/
111
 
        const ib_rbt_t*         tree,           /*!< in: tree to verify */
112
 
        const ib_rbt_node_t*    node)           /*!< in: start of sub-tree */
 
104
        const ib_rbt_t*         tree,   /*!< in: tree to verify */
 
105
        const ib_rbt_node_t*    node)   /*!< in: start of sub-tree */
113
106
{
114
107
        ulint   result;
115
108
 
148
141
        return(result);
149
142
}
150
143
 
151
 
/**********************************************************************//**
 
144
/****************************************************************//**
152
145
Turn the node's right child's left sub-tree into node's right sub-tree.
153
146
This will also make node's right child it's parent. */
154
147
static
155
148
void
156
149
rbt_rotate_left(
157
150
/*============*/
158
 
        const ib_rbt_node_t*    nil,            /*!< in: nil node of the tree */
159
 
        ib_rbt_node_t*          node)           /*!< in: node to rotate */
 
151
        const ib_rbt_node_t*    nil,    /*!< in: nil node of the tree */
 
152
        ib_rbt_node_t*          node)   /*!< in: node to rotate */
160
153
{
161
154
        ib_rbt_node_t*  right = node->right;
162
155
 
184
177
        node->parent = right;
185
178
}
186
179
 
187
 
/**********************************************************************//**
 
180
/****************************************************************//**
188
181
Turn the node's left child's right sub-tree into node's left sub-tree.
189
182
This also make node's left child it's parent. */
190
183
static
191
184
void
192
185
rbt_rotate_right(
193
186
/*=============*/
194
 
        const ib_rbt_node_t*    nil,            /*!< in: nil node of tree */
195
 
        ib_rbt_node_t*          node)           /*!< in: node to rotate */
 
187
        const ib_rbt_node_t*    nil,    /*!< in: nil node of tree */
 
188
        ib_rbt_node_t*          node)   /*!< in: node to rotate */
196
189
{
197
190
        ib_rbt_node_t*  left = node->left;
198
191
 
220
213
        node->parent = left;
221
214
}
222
215
 
223
 
/**********************************************************************//**
224
 
Append a node to the tree. */
 
216
/****************************************************************//**
 
217
Append a node to the tree.
 
218
@return inserted node */
225
219
static
226
220
ib_rbt_node_t*
227
221
rbt_tree_add_child(
228
222
/*===============*/
229
 
        const ib_rbt_t* tree,
230
 
        ib_rbt_bound_t* parent,
231
 
        ib_rbt_node_t*  node)
 
223
        const ib_rbt_t* tree,           /*!< in: rbt tree */
 
224
        ib_rbt_bound_t* parent,         /*!< in: node's parent */
 
225
        ib_rbt_node_t*  node)           /*!< in: node to add */
232
226
{
233
227
        /* Cast away the const. */
234
228
        ib_rbt_node_t*  last = (ib_rbt_node_t*) parent->last;
247
241
        return(node);
248
242
}
249
243
 
250
 
/**********************************************************************//**
251
 
Generic binary tree insert */
 
244
/****************************************************************//**
 
245
Generic binary tree insert
 
246
@return inserted node */
252
247
static
253
248
ib_rbt_node_t*
254
249
rbt_tree_insert(
255
250
/*============*/
256
 
        ib_rbt_t*       tree,
257
 
        const void*     key,
258
 
        ib_rbt_node_t*  node)
 
251
        ib_rbt_t*       tree,           /*!< in: rb tree */
 
252
        const void*     key,            /*!< in: key for ordering */
 
253
        ib_rbt_node_t*  node)           /*!< in: node hold the insert value */
259
254
{
260
255
        ib_rbt_bound_t  parent;
261
256
        ib_rbt_node_t*  current = ROOT(tree);
283
278
        return(node);
284
279
}
285
280
 
286
 
/**********************************************************************//**
 
281
/****************************************************************//**
287
282
Balance a tree after inserting a node. */
288
283
static
289
284
void
290
285
rbt_balance_tree(
291
286
/*=============*/
292
 
        const ib_rbt_t* tree,                   /*!< in: tree to balance */
293
 
        ib_rbt_node_t*  node)                   /*!< in: node that was inserted */
 
287
        const ib_rbt_t* tree,           /*!< in: tree to balance */
 
288
        ib_rbt_node_t*  node)           /*!< in: node that was inserted */
294
289
{
295
290
        const ib_rbt_node_t*    nil = tree->nil;
296
291
        ib_rbt_node_t*          parent = node->parent;
373
368
        ROOT(tree)->color = IB_RBT_BLACK;
374
369
}
375
370
 
376
 
/**********************************************************************//**
 
371
/****************************************************************//**
377
372
Find the given node's successor.
378
373
@return successor node or NULL if no successor */
379
374
static
380
375
ib_rbt_node_t*
381
376
rbt_find_successor(
382
377
/*===============*/
383
 
        const ib_rbt_t*         tree,           /*!< in: rb tree */
384
 
        const ib_rbt_node_t*    current)        /*!< in: this is declared const
385
 
                                                because it can be called via
386
 
                                                rbt_next() */
 
378
        const ib_rbt_t*         tree,   /*!< in: rb tree */
 
379
        const ib_rbt_node_t*    current)/*!< in: this is declared const
 
380
                                        because it can be called via
 
381
                                        rbt_next() */
387
382
{
388
383
        const ib_rbt_node_t*    nil = tree->nil;
389
384
        ib_rbt_node_t*          next = current->right;
413
408
        return(next);
414
409
}
415
410
 
416
 
/**********************************************************************//**
 
411
/****************************************************************//**
417
412
Find the given node's precedecessor.
418
413
@return predecessor node or NULL if no predecesor */
419
414
static
453
448
        return(prev);
454
449
}
455
450
 
456
 
/**********************************************************************//**
 
451
/****************************************************************//**
457
452
Replace node with child. After applying transformations eject becomes
458
453
an orphan. */
459
454
static
460
455
void
461
456
rbt_eject_node(
462
457
/*===========*/
463
 
        ib_rbt_node_t*  eject,                  /*!< in: node to eject */
464
 
        ib_rbt_node_t*  node)                   /*!< in: node to replace with */
 
458
        ib_rbt_node_t*  eject,          /*!< in: node to eject */
 
459
        ib_rbt_node_t*  node)           /*!< in: node to replace with */
465
460
{
466
461
        /* Update the to be ejected node's parent's child pointers. */
467
462
        if (eject->parent->left == eject) {
477
472
        node->parent = eject->parent;
478
473
}
479
474
 
480
 
/**********************************************************************//**
 
475
/****************************************************************//**
481
476
Replace a node with another node. */
482
477
static
483
478
void
484
479
rbt_replace_node(
485
480
/*=============*/
486
 
        ib_rbt_node_t*  replace,                /*!< in: node to replace */
487
 
        ib_rbt_node_t*  node)                   /*!< in: node to replace with */
 
481
        ib_rbt_node_t*  replace,        /*!< in: node to replace */
 
482
        ib_rbt_node_t*  node)           /*!< in: node to replace with */
488
483
{
489
484
        ib_rbt_color_t  color = node->color;
490
485
 
504
499
        replace->color = color;
505
500
}
506
501
 
507
 
/**********************************************************************//**
 
502
/****************************************************************//**
508
503
Detach node from the tree replacing it with one of it's children.
509
504
@return the child node that now occupies the position of the detached node */
510
505
static
511
506
ib_rbt_node_t*
512
507
rbt_detach_node(
513
508
/*============*/
514
 
        const ib_rbt_t* tree,                   /*!< in: rb tree */
515
 
        ib_rbt_node_t*  node)                   /*!< in: node to detach */
 
509
        const ib_rbt_t* tree,           /*!< in: rb tree */
 
510
        ib_rbt_node_t*  node)           /*!< in: node to detach */
516
511
{
517
512
        ib_rbt_node_t*          child;
518
513
        const ib_rbt_node_t*    nil = tree->nil;
547
542
        return(child);
548
543
}
549
544
 
550
 
/**********************************************************************//**
 
545
/****************************************************************//**
551
546
Rebalance the right sub-tree after deletion.
552
547
@return node to rebalance if more rebalancing required else NULL */
553
548
static
554
549
ib_rbt_node_t*
555
550
rbt_balance_right(
556
551
/*==============*/
557
 
        const ib_rbt_node_t*    nil,            /*!< in: rb tree nil node */
558
 
        ib_rbt_node_t*          parent,         /*!< in: parent node */
559
 
        ib_rbt_node_t*          sibling)        /*!< in: sibling node */
 
552
        const ib_rbt_node_t*    nil,    /*!< in: rb tree nil node */
 
553
        ib_rbt_node_t*          parent, /*!< in: parent node */
 
554
        ib_rbt_node_t*          sibling)/*!< in: sibling node */
560
555
{
561
556
        ib_rbt_node_t*          node = NULL;
562
557
 
607
602
        return(node);
608
603
}
609
604
 
610
 
/**********************************************************************//**
 
605
/****************************************************************//**
611
606
Rebalance the left sub-tree after deletion.
612
607
@return node to rebalance if more rebalancing required else NULL */
613
608
static
614
609
ib_rbt_node_t*
615
610
rbt_balance_left(
616
611
/*=============*/
617
 
        const ib_rbt_node_t*    nil,            /*!< in: rb tree nil node */
618
 
        ib_rbt_node_t*          parent,         /*!< in: parent node */
619
 
        ib_rbt_node_t*          sibling)        /*!< in: sibling node */
 
612
        const ib_rbt_node_t*    nil,    /*!< in: rb tree nil node */
 
613
        ib_rbt_node_t*          parent, /*!< in: parent node */
 
614
        ib_rbt_node_t*          sibling)/*!< in: sibling node */
620
615
{
621
616
        ib_rbt_node_t*  node = NULL;
622
617
 
667
662
        return(node);
668
663
}
669
664
 
670
 
/**********************************************************************//**
 
665
/****************************************************************//**
671
666
Delete the node and rebalance the tree if necessary */
672
667
static
673
668
void
674
669
rbt_remove_node_and_rebalance(
675
670
/*==========================*/
676
 
        ib_rbt_t*               tree,           /*!< in: rb tree */
677
 
        ib_rbt_node_t*          node)           /*!< in: node to remove */
 
671
        ib_rbt_t*       tree,           /*!< in: rb tree */
 
672
        ib_rbt_node_t*  node)           /*!< in: node to remove */
678
673
{
679
674
        /* Detach node and get the node that will be used
680
675
        as rebalance start. */
719
714
        --tree->n_nodes;
720
715
}
721
716
 
722
 
/**********************************************************************//**
 
717
/****************************************************************//**
723
718
Recursively free the nodes. */
724
719
static
725
720
void
726
721
rbt_free_node(
727
722
/*==========*/
728
 
        ib_rbt_node_t*  node,                   /*!< in: node to free */
729
 
        ib_rbt_node_t*  nil)                    /*!< in: rb tree nil node */
 
723
        ib_rbt_node_t*  node,           /*!< in: node to free */
 
724
        ib_rbt_node_t*  nil)            /*!< in: rb tree nil node */
730
725
{
731
726
        if (node != nil) {
732
727
                rbt_free_node(node->left, nil);
736
731
        }
737
732
}
738
733
 
739
 
/**********************************************************************//**
 
734
/****************************************************************//**
740
735
Free all the nodes and free the tree. */
741
736
UNIV_INTERN
742
737
void
743
738
rbt_free(
744
739
/*=====*/
745
 
        ib_rbt_t*       tree)                   /*!< in: rb tree to free */
 
740
        ib_rbt_t*       tree)           /*!< in: rb tree to free */
746
741
{
747
742
        rbt_free_node(tree->root, tree->nil);
748
743
        ut_free(tree->nil);
749
744
        ut_free(tree);
750
745
}
751
746
 
752
 
/**********************************************************************//**
 
747
/****************************************************************//**
753
748
Create an instance of a red black tree.
754
749
@return an empty rb tree */
755
750
UNIV_INTERN
756
751
ib_rbt_t*
757
752
rbt_create(
758
753
/*=======*/
759
 
        size_t          sizeof_value,           /*!< in: sizeof data item */
760
 
        ib_rbt_compare  compare)                /*!< in: fn to compare items */
 
754
        size_t          sizeof_value,   /*!< in: sizeof data item */
 
755
        ib_rbt_compare  compare)        /*!< in: fn to compare items */
761
756
{
762
757
        ib_rbt_t*       tree;
763
758
        ib_rbt_node_t*  node;
787
782
        return(tree);
788
783
}
789
784
 
790
 
/**********************************************************************//**
 
785
/****************************************************************//**
791
786
Generic insert of a value in the rb tree.
792
787
@return inserted node */
793
788
UNIV_INTERN
794
789
const ib_rbt_node_t*
795
790
rbt_insert(
796
791
/*=======*/
797
 
        ib_rbt_t*       tree,                   /*!< in: rb tree */
798
 
        const void*     key,                    /*!< in: key for ordering */
799
 
        const void*     value)                  /*!< in: value of key, this value
800
 
                                                is copied to the node */
 
792
        ib_rbt_t*       tree,           /*!< in: rb tree */
 
793
        const void*     key,            /*!< in: key for ordering */
 
794
        const void*     value)          /*!< in: value of key, this value
 
795
                                        is copied to the node */
801
796
{
802
797
        ib_rbt_node_t*  node;
803
798
 
816
811
        return(node);
817
812
}
818
813
 
819
 
/**********************************************************************//**
 
814
/****************************************************************//**
820
815
Add a new node to the tree, useful for data that is pre-sorted.
821
816
@return appended node */
822
817
UNIV_INTERN
823
818
const ib_rbt_node_t*
824
819
rbt_add_node(
825
820
/*=========*/
826
 
        ib_rbt_t*       tree,                   /*!< in: rb tree */
827
 
        ib_rbt_bound_t* parent,                 /*!< in: bounds */
828
 
        const void*     value)                  /*!< in: this value is copied
829
 
                                                to the node */
 
821
        ib_rbt_t*       tree,           /*!< in: rb tree */
 
822
        ib_rbt_bound_t* parent,         /*!< in: bounds */
 
823
        const void*     value)          /*!< in: this value is copied
 
824
                                        to the node */
830
825
{
831
826
        ib_rbt_node_t*  node;
832
827
 
854
849
        return(node);
855
850
}
856
851
 
857
 
/**********************************************************************//**
 
852
/****************************************************************//**
858
853
Find a matching node in the rb tree.
859
854
@return NULL if not found else the node where key was found */
860
855
UNIV_INTERN
861
856
const ib_rbt_node_t*
862
857
rbt_lookup(
863
858
/*=======*/
864
 
        const ib_rbt_t* tree,                   /*!< in: rb tree */
865
 
        const void*     key)                    /*!< in: key to use for search */
 
859
        const ib_rbt_t* tree,           /*!< in: rb tree */
 
860
        const void*     key)            /*!< in: key to use for search */
866
861
{
867
862
        const ib_rbt_node_t*    current = ROOT(tree);
868
863
 
882
877
        return(current != tree->nil ? current : NULL);
883
878
}
884
879
 
885
 
/**********************************************************************//**
886
 
Delete a node indentified by key.
 
880
/****************************************************************//**
 
881
Delete a node from the red black tree, identified by key.
887
882
@return TRUE if success FALSE if not found */
888
883
UNIV_INTERN
889
884
ibool
890
885
rbt_delete(
891
886
/*=======*/
892
 
        ib_rbt_t*       tree,                   /*!< in: rb tree */
893
 
        const void*     key)                    /*!< in: key to delete */
 
887
        ib_rbt_t*       tree,           /*!< in: rb tree */
 
888
        const void*     key)            /*!< in: key to delete */
894
889
{
895
890
        ibool           deleted = FALSE;
896
891
        ib_rbt_node_t*  node = (ib_rbt_node_t*) rbt_lookup(tree, key);
905
900
        return(deleted);
906
901
}
907
902
 
908
 
/**********************************************************************//**
 
903
/****************************************************************//**
909
904
Remove a node from the rb tree, the node is not free'd, that is the
910
905
callers responsibility.
911
906
@return deleted node but without the const */
929
924
        return((ib_rbt_node_t*) const_node);
930
925
}
931
926
 
932
 
/**********************************************************************//**
 
927
/****************************************************************//**
933
928
Find the node that has the lowest key that is >= key.
934
929
@return node satisfying the lower bound constraint or NULL */
935
930
UNIV_INTERN
936
931
const ib_rbt_node_t*
937
932
rbt_lower_bound(
938
933
/*============*/
939
 
        const ib_rbt_t* tree,                   /*!< in: rb tree */
940
 
        const void*     key)                    /*!< in: key to search */
 
934
        const ib_rbt_t* tree,           /*!< in: rb tree */
 
935
        const void*     key)            /*!< in: key to search */
941
936
{
942
937
        ib_rbt_node_t*  lb_node = NULL;
943
938
        ib_rbt_node_t*  current = ROOT(tree);
963
958
        return(lb_node);
964
959
}
965
960
 
966
 
/**********************************************************************//**
 
961
/****************************************************************//**
967
962
Find the node that has the greatest key that is <= key.
968
963
@return node satisfying the upper bound constraint or NULL */
969
964
UNIV_INTERN
970
965
const ib_rbt_node_t*
971
966
rbt_upper_bound(
972
967
/*============*/
973
 
        const ib_rbt_t* tree,                   /*!< in: rb tree */
974
 
        const void*     key)                    /*!< in: key to search */
 
968
        const ib_rbt_t* tree,           /*!< in: rb tree */
 
969
        const void*     key)            /*!< in: key to search */
975
970
{
976
971
        ib_rbt_node_t*  ub_node = NULL;
977
972
        ib_rbt_node_t*  current = ROOT(tree);
997
992
        return(ub_node);
998
993
}
999
994
 
1000
 
/**********************************************************************//**
 
995
/****************************************************************//**
1001
996
Find the node that has the greatest key that is <= key.
1002
997
@return value of result */
1003
998
UNIV_INTERN
1004
999
int
1005
1000
rbt_search(
1006
1001
/*=======*/
1007
 
        const ib_rbt_t* tree,                   /*!< in: rb tree */
1008
 
        ib_rbt_bound_t* parent,                 /*!< in: search bounds */
1009
 
        const void*     key)                    /*!< in: key to search */
 
1002
        const ib_rbt_t* tree,           /*!< in: rb tree */
 
1003
        ib_rbt_bound_t* parent,         /*!< in: search bounds */
 
1004
        const void*     key)            /*!< in: key to search */
1010
1005
{
1011
1006
        ib_rbt_node_t*  current = ROOT(tree);
1012
1007
 
1031
1026
        return(parent->result);
1032
1027
}
1033
1028
 
1034
 
/**********************************************************************//**
 
1029
/****************************************************************//**
1035
1030
Find the node that has the greatest key that is <= key. But use the
1036
1031
supplied comparison function.
1037
1032
@return value of result */
1039
1034
int
1040
1035
rbt_search_cmp(
1041
1036
/*===========*/
1042
 
        const ib_rbt_t* tree,                   /*!< in: rb tree */
1043
 
        ib_rbt_bound_t* parent,                 /*!< in: search bounds */
1044
 
        const void*     key,                    /*!< in: key to search */
1045
 
        ib_rbt_compare  compare)                /*!< in: fn to compare items */
 
1037
        const ib_rbt_t* tree,           /*!< in: rb tree */
 
1038
        ib_rbt_bound_t* parent,         /*!< in: search bounds */
 
1039
        const void*     key,            /*!< in: key to search */
 
1040
        ib_rbt_compare  compare)        /*!< in: fn to compare items */
1046
1041
{
1047
1042
        ib_rbt_node_t*  current = ROOT(tree);
1048
1043
 
1067
1062
        return(parent->result);
1068
1063
}
1069
1064
 
1070
 
/**********************************************************************//**
 
1065
/****************************************************************//**
 
1066
Get the leftmost node.
1071
1067
Return the left most node in the tree. */
1072
1068
UNIV_INTERN
1073
1069
const ib_rbt_node_t*
1074
1070
rbt_first(
1075
1071
/*======*/
1076
 
                                                /* out leftmost node or NULL */
1077
 
        const ib_rbt_t* tree)                   /* in: rb tree */
 
1072
        const ib_rbt_t* tree)           /* in: rb tree */
1078
1073
{
1079
1074
        ib_rbt_node_t*  first = NULL;
1080
1075
        ib_rbt_node_t*  current = ROOT(tree);
1087
1082
        return(first);
1088
1083
}
1089
1084
 
1090
 
/**********************************************************************//**
 
1085
/****************************************************************//**
1091
1086
Return the right most node in the tree.
1092
1087
@return the rightmost node or NULL */
1093
1088
UNIV_INTERN
1094
1089
const ib_rbt_node_t*
1095
1090
rbt_last(
1096
1091
/*=====*/
1097
 
        const ib_rbt_t* tree)                   /*!< in: rb tree */
 
1092
        const ib_rbt_t* tree)           /*!< in: rb tree */
1098
1093
{
1099
1094
        ib_rbt_node_t*  last = NULL;
1100
1095
        ib_rbt_node_t*  current = ROOT(tree);
1107
1102
        return(last);
1108
1103
}
1109
1104
 
1110
 
/**********************************************************************//**
 
1105
/****************************************************************//**
1111
1106
Return the next node.
1112
1107
@return node next from current */
1113
1108
UNIV_INTERN
1114
1109
const ib_rbt_node_t*
1115
1110
rbt_next(
1116
1111
/*=====*/
1117
 
        const ib_rbt_t*         tree,           /*!< in: rb tree */
1118
 
        const ib_rbt_node_t*    current)        /*!< in: current node */
 
1112
        const ib_rbt_t*         tree,   /*!< in: rb tree */
 
1113
        const ib_rbt_node_t*    current)/*!< in: current node */
1119
1114
{
1120
1115
        return(current ? rbt_find_successor(tree, current) : NULL);
1121
1116
}
1122
1117
 
1123
 
/**********************************************************************//**
 
1118
/****************************************************************//**
1124
1119
Return the previous node.
1125
1120
@return node prev from current */
1126
1121
UNIV_INTERN
1127
1122
const ib_rbt_node_t*
1128
1123
rbt_prev(
1129
1124
/*=====*/
1130
 
        const ib_rbt_t*         tree,           /*!< in: rb tree */
1131
 
        const ib_rbt_node_t*    current)        /*!< in: current node */
 
1125
        const ib_rbt_t*         tree,   /*!< in: rb tree */
 
1126
        const ib_rbt_node_t*    current)/*!< in: current node */
1132
1127
{
1133
1128
        return(current ? rbt_find_predecessor(tree, current) : NULL);
1134
1129
}
1135
1130
 
1136
 
/**********************************************************************//**
 
1131
/****************************************************************//**
1137
1132
Reset the tree. Delete all the nodes. */
1138
1133
UNIV_INTERN
1139
1134
void
1140
1135
rbt_clear(
1141
1136
/*======*/
1142
 
        ib_rbt_t*       tree)                   /*!< in: rb tree */
 
1137
        ib_rbt_t*       tree)           /*!< in: rb tree */
1143
1138
{
1144
1139
        rbt_free_node(ROOT(tree), tree->nil);
1145
1140
 
1147
1142
        tree->root->left = tree->root->right = tree->nil;
1148
1143
}
1149
1144
 
1150
 
/**********************************************************************//**
 
1145
/****************************************************************//**
1151
1146
Merge the node from dst into src. Return the number of nodes merged.
1152
1147
@return no. of recs merged */
1153
1148
UNIV_INTERN
1154
1149
ulint
1155
1150
rbt_merge_uniq(
1156
1151
/*===========*/
1157
 
        ib_rbt_t*       dst,                    /*!< in: dst rb tree */
1158
 
        const ib_rbt_t* src)                    /*!< in: src rb tree */
 
1152
        ib_rbt_t*       dst,            /*!< in: dst rb tree */
 
1153
        const ib_rbt_t* src)            /*!< in: src rb tree */
1159
1154
{
1160
1155
        ib_rbt_bound_t          parent;
1161
1156
        ulint                   n_merged = 0;
1176
1171
        return(n_merged);
1177
1172
}
1178
1173
 
1179
 
/**********************************************************************//**
 
1174
/****************************************************************//**
1180
1175
Merge the node from dst into src. Return the number of nodes merged.
1181
1176
Delete the nodes from src after copying node to dst. As a side effect
1182
1177
the duplicates will be left untouched in the src.
1185
1180
ulint
1186
1181
rbt_merge_uniq_destructive(
1187
1182
/*=======================*/
1188
 
        ib_rbt_t*       dst,                    /*!< in: dst rb tree */
1189
 
        ib_rbt_t*       src)                    /*!< in: src rb tree */
 
1183
        ib_rbt_t*       dst,            /*!< in: dst rb tree */
 
1184
        ib_rbt_t*       src)            /*!< in: src rb tree */
1190
1185
{
1191
1186
        ib_rbt_bound_t  parent;
1192
1187
        ib_rbt_node_t*  src_node;
1224
1219
        return(rbt_size(dst) - old_size);
1225
1220
}
1226
1221
 
1227
 
/**********************************************************************//**
 
1222
/****************************************************************//**
1228
1223
Check that every path from the root to the leaves has the same count and
1229
1224
the tree nodes are in order.
1230
1225
@return TRUE if OK FALSE otherwise */
1241
1236
        return(FALSE);
1242
1237
}
1243
1238
 
1244
 
/**********************************************************************//**
 
1239
/****************************************************************//**
1245
1240
Iterate over the tree in depth first order. */
1246
1241
UNIV_INTERN
1247
1242
void
1248
1243
rbt_print(
1249
1244
/*======*/
1250
 
        const ib_rbt_t*         tree,           /*!< in: tree to traverse */
1251
 
        ib_rbt_print_node       print)          /*!< in: print function */
 
1245
        const ib_rbt_t*         tree,   /*!< in: tree to traverse */
 
1246
        ib_rbt_print_node       print)  /*!< in: print function */
1252
1247
{
1253
1248
        rbt_print_subtree(tree, ROOT(tree), print);
1254
1249
}