diff options
Diffstat (limited to 'storage/xtradb/include/ut0rbt.h')
-rw-r--r-- | storage/xtradb/include/ut0rbt.h | 169 |
1 files changed, 88 insertions, 81 deletions
diff --git a/storage/xtradb/include/ut0rbt.h b/storage/xtradb/include/ut0rbt.h index 6fd050acfe7..e26b637ae13 100644 --- a/storage/xtradb/include/ut0rbt.h +++ b/storage/xtradb/include/ut0rbt.h @@ -1,5 +1,12 @@ -/***************************************************************************** -Copyright (c) 2006, 2009, Innobase Oy. All Rights Reserved. +/***************************************************************************//** + +Copyright (c) 2007, 2010, Innobase Oy. All Rights Reserved. + +Portions of this file contain modifications contributed and copyrighted by +Sun Microsystems, Inc. Those modifications are gratefully acknowledged and +are described briefly in the InnoDB documentation. The contributions by +Sun Microsystems are incorporated with their permission, and subject to the +conditions contained in the file COPYING.Sun_Microsystems. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -14,13 +21,12 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *****************************************************************************/ - -/*******************************************************************//** +/******************************************************************//** @file include/ut0rbt.h -Red-Black tree implementation. +Various utilities Created 2007-03-20 Sunny Bains -************************************************************************/ +*******************************************************/ #ifndef INNOBASE_UT0RBT_H #define INNOBASE_UT0RBT_H @@ -52,7 +58,7 @@ typedef struct ib_rbt_bound_struct ib_rbt_bound_t; typedef void (*ib_rbt_print_node)(const ib_rbt_node_t* node); typedef int (*ib_rbt_compare)(const void* p1, const void* p2); -/* Red black tree color types */ +/** Red black tree color types */ enum ib_rbt_color_enum { IB_RBT_RED, IB_RBT_BLACK @@ -60,7 +66,7 @@ enum ib_rbt_color_enum { typedef enum ib_rbt_color_enum ib_rbt_color_t; -/* Red black tree node */ +/** Red black tree node */ struct ib_rbt_node_struct { ib_rbt_color_t color; /* color of this node */ @@ -71,7 +77,7 @@ struct ib_rbt_node_struct { char value[1]; /* Data value */ }; -/* Red black tree instance.*/ +/** Red black tree instance.*/ struct ib_rbt_struct { ib_rbt_node_t* nil; /* Black colored node that is used as a sentinel. This is @@ -87,7 +93,7 @@ struct ib_rbt_struct { ulint sizeof_value; /* Sizeof the item in bytes */ }; -/* The result of searching for a key in the tree, this is useful for +/** The result of searching for a key in the tree, this is useful for a speedy lookup and insert if key doesn't exist.*/ struct ib_rbt_bound_struct { const ib_rbt_node_t* @@ -110,131 +116,132 @@ struct ib_rbt_bound_struct { /* Compare a key with the node value (t is tree, k is key, n is node)*/ #define rbt_compare(t, k, n) (t->compare(k, n->value)) -/****************************************************************//** +/**********************************************************************//** Free an instance of a red black tree */ UNIV_INTERN void rbt_free( /*=====*/ - ib_rbt_t* tree); /*!< in: rb tree to free */ -/****************************************************************//** + ib_rbt_t* tree); /*!< in: rb tree to free */ +/**********************************************************************//** Create an instance of a red black tree @return rb tree instance */ UNIV_INTERN ib_rbt_t* rbt_create( /*=======*/ - size_t sizeof_value, /*!< in: size in bytes */ - ib_rbt_compare compare); /*!< in: comparator */ -/****************************************************************//** -Delete a node from the red black tree, identified by key. -@return TRUE if success FALSE if not found */ + size_t sizeof_value, /*!< in: size in bytes */ + ib_rbt_compare compare); /*!< in: comparator */ +/**********************************************************************//** +Delete a node from the red black tree, identified by key */ UNIV_INTERN ibool rbt_delete( /*=======*/ - ib_rbt_t* tree, /*!< in: rb tree */ - const void* key); /*!< in: key to delete */ -/****************************************************************//** -Remove a node from the rb tree, the node is not free'd, that is the -callers responsibility. + /* in: TRUE on success */ + ib_rbt_t* tree, /* in: rb tree */ + const void* key); /* in: key to delete */ +/**********************************************************************//** +Remove a node from the red black tree, NOTE: This function will not delete +the node instance, THAT IS THE CALLERS RESPONSIBILITY. @return the deleted node with the const. */ UNIV_INTERN ib_rbt_node_t* rbt_remove_node( /*============*/ - ib_rbt_t* tree, /*!< in: rb tree */ + ib_rbt_t* tree, /*!< in: rb tree */ const ib_rbt_node_t* - node); /*!< in: node to delete, this - is a fudge and declared const - because the caller has access - only to const nodes.*/ -/****************************************************************//** -Find a matching node in the rb tree. + node); /*!< in: node to delete, this + is a fudge and declared const + because the caller has access + only to const nodes.*/ +/**********************************************************************//** +Return a node from the red black tree, identified by +key, NULL if not found @return node if found else return NULL */ UNIV_INTERN const ib_rbt_node_t* rbt_lookup( /*=======*/ - const ib_rbt_t* tree, /*!< in: rb tree to search */ - const void* key); /*!< in: key to lookup */ -/****************************************************************//** -Generic insert of a value in the rb tree. + const ib_rbt_t* tree, /*!< in: rb tree to search */ + const void* key); /*!< in: key to lookup */ +/**********************************************************************//** +Add data to the red black tree, identified by key (no dups yet!) @return inserted node */ UNIV_INTERN const ib_rbt_node_t* rbt_insert( /*=======*/ - ib_rbt_t* tree, /*!< in: rb tree */ - const void* key, /*!< in: key for ordering */ - const void* value); /*!< in: data that will be - copied to the node.*/ -/****************************************************************//** + ib_rbt_t* tree, /*!< in: rb tree */ + const void* key, /*!< in: key for ordering */ + const void* value); /*!< in: data that will be + copied to the node.*/ +/**********************************************************************//** Add a new node to the tree, useful for data that is pre-sorted. @return appended node */ UNIV_INTERN const ib_rbt_node_t* rbt_add_node( /*=========*/ - ib_rbt_t* tree, /*!< in: rb tree */ - ib_rbt_bound_t* parent, /*!< in: parent */ - const void* value); /*!< in: this value is copied - to the node */ -/****************************************************************//** + ib_rbt_t* tree, /*!< in: rb tree */ + ib_rbt_bound_t* parent, /*!< in: parent */ + const void* value); /*!< in: this value is copied + to the node */ +/**********************************************************************//** Return the left most data node in the tree @return left most node */ UNIV_INTERN const ib_rbt_node_t* rbt_first( /*======*/ - const ib_rbt_t* tree); /*!< in: rb tree */ -/****************************************************************//** + const ib_rbt_t* tree); /*!< in: rb tree */ +/**********************************************************************//** Return the right most data node in the tree @return right most node */ UNIV_INTERN const ib_rbt_node_t* rbt_last( /*=====*/ - const ib_rbt_t* tree); /*!< in: rb tree */ -/****************************************************************//** + const ib_rbt_t* tree); /*!< in: rb tree */ +/**********************************************************************//** Return the next node from current. @return successor node to current that is passed in. */ UNIV_INTERN const ib_rbt_node_t* rbt_next( /*=====*/ - const ib_rbt_t* tree, /*!< in: rb tree */ - const ib_rbt_node_t* /*!< in: current node */ + const ib_rbt_t* tree, /*!< in: rb tree */ + const ib_rbt_node_t* /* in: current node */ current); -/****************************************************************//** +/**********************************************************************//** Return the prev node from current. @return precedessor node to current that is passed in */ UNIV_INTERN const ib_rbt_node_t* rbt_prev( /*=====*/ - const ib_rbt_t* tree, /*!< in: rb tree */ - const ib_rbt_node_t* /*!< in: current node */ + const ib_rbt_t* tree, /*!< in: rb tree */ + const ib_rbt_node_t* /* in: current node */ current); -/****************************************************************//** +/**********************************************************************//** Find the node that has the lowest key that is >= key. @return node that satisfies the lower bound constraint or NULL */ UNIV_INTERN const ib_rbt_node_t* rbt_lower_bound( /*============*/ - const ib_rbt_t* tree, /*!< in: rb tree */ - const void* key); /*!< in: key to search */ -/****************************************************************//** + const ib_rbt_t* tree, /*!< in: rb tree */ + const void* key); /*!< in: key to search */ +/**********************************************************************//** Find the node that has the greatest key that is <= key. @return node that satisifies the upper bound constraint or NULL */ UNIV_INTERN const ib_rbt_node_t* rbt_upper_bound( /*============*/ - const ib_rbt_t* tree, /*!< in: rb tree */ - const void* key); /*!< in: key to search */ -/****************************************************************//** + const ib_rbt_t* tree, /*!< in: rb tree */ + const void* key); /*!< in: key to search */ +/**********************************************************************//** Search for the key, a node will be retuned in parent.last, whether it was found or not. If not found then parent.last will contain the parent node for the possibly new key otherwise the matching node. @@ -243,10 +250,10 @@ UNIV_INTERN int rbt_search( /*=======*/ - const ib_rbt_t* tree, /*!< in: rb tree */ - ib_rbt_bound_t* parent, /*!< in: search bounds */ - const void* key); /*!< in: key to search */ -/****************************************************************//** + const ib_rbt_t* tree, /*!< in: rb tree */ + ib_rbt_bound_t* parent, /*!< in: search bounds */ + const void* key); /*!< in: key to search */ +/**********************************************************************//** Search for the key, a node will be retuned in parent.last, whether it was found or not. If not found then parent.last will contain the parent node for the possibly new key otherwise the matching node. @@ -255,27 +262,27 @@ UNIV_INTERN int rbt_search_cmp( /*===========*/ - const ib_rbt_t* tree, /*!< in: rb tree */ - ib_rbt_bound_t* parent, /*!< in: search bounds */ - const void* key, /*!< in: key to search */ - ib_rbt_compare compare); /*!< in: comparator */ -/****************************************************************//** + const ib_rbt_t* tree, /*!< in: rb tree */ + ib_rbt_bound_t* parent, /*!< in: search bounds */ + const void* key, /*!< in: key to search */ + ib_rbt_compare compare); /*!< in: comparator */ +/**********************************************************************//** Clear the tree, deletes (and free's) all the nodes. */ UNIV_INTERN void rbt_clear( /*======*/ - ib_rbt_t* tree); /*!< in: rb tree */ -/****************************************************************//** + ib_rbt_t* tree); /*!< in: rb tree */ +/**********************************************************************//** Merge the node from dst into src. Return the number of nodes merged. @return no. of recs merged */ UNIV_INTERN ulint rbt_merge_uniq( /*===========*/ - ib_rbt_t* dst, /*!< in: dst rb tree */ - const ib_rbt_t* src); /*!< in: src rb tree */ -/****************************************************************//** + ib_rbt_t* dst, /*!< in: dst rb tree */ + const ib_rbt_t* src); /*!< in: src rb tree */ +/**********************************************************************//** Merge the node from dst into src. Return the number of nodes merged. Delete the nodes from src after copying node to dst. As a side effect the duplicates will be left untouched in the src, since we don't support @@ -286,9 +293,9 @@ UNIV_INTERN ulint rbt_merge_uniq_destructive( /*=======================*/ - ib_rbt_t* dst, /*!< in: dst rb tree */ - ib_rbt_t* src); /*!< in: src rb tree */ -/****************************************************************//** + ib_rbt_t* dst, /*!< in: dst rb tree */ + ib_rbt_t* src); /*!< in: src rb tree */ +/**********************************************************************//** Verify the integrity of the RB tree. For debugging. 0 failure else height of tree (in count of black nodes). @return TRUE if OK FALSE if tree invalid. */ @@ -296,14 +303,14 @@ UNIV_INTERN ibool rbt_validate( /*=========*/ - const ib_rbt_t* tree); /*!< in: tree to validate */ -/****************************************************************//** + const ib_rbt_t* tree); /*!< in: tree to validate */ +/**********************************************************************//** Iterate over the tree in depth first order. */ UNIV_INTERN void rbt_print( /*======*/ - const ib_rbt_t* tree, /*!< in: tree to traverse */ - ib_rbt_print_node print); /*!< in: print function */ + const ib_rbt_t* tree, /*!< in: tree to traverse */ + ib_rbt_print_node print); /*!< in: print function */ #endif /* INNOBASE_UT0RBT_H */ |