nfs-ganesha 1.4
|
00001 /* 00002 * $Id: rbt_node.h,v 1.4 2006/01/27 10:28:34 deniel Exp $ 00003 */ 00004 00005 /* 00006 * Implementation of RedBlack trees 00007 * Definitions and structures 00008 */ 00009 00010 /* 00011 * This implementation of RedBlack trees was copied from 00012 * the STL library and adapted to a C environment. 00013 */ 00014 00015 /* 00016 * RB tree implementation -*- C++ -*- 00017 00018 * Copyright (C) 2001 Free Software Foundation, Inc. 00019 * 00020 * This file is part of the GNU ISO C++ Library. This library is free 00021 * software; you can redistribute it and/or modify it under the 00022 * terms of the GNU General Public License as published by the 00023 * Free Software Foundation; either version 2, or (at your option) 00024 * any later version. 00025 00026 * This library is distributed in the hope that it will be useful, 00027 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00028 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00029 * GNU General Public License for more details. 00030 00031 * You should have received a copy of the GNU General Public License along 00032 * with this library; see the file COPYING. If not, write to the Free 00033 * Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00034 * USA. 00035 00036 * As a special exception, you may use this file as part of a free software 00037 * library without restriction. Specifically, if other files instantiate 00038 * templates or use macros or inline functions from this file, or you compile 00039 * this file and link it with other files to produce an executable, this 00040 * file does not by itself cause the resulting executable to be covered by 00041 * the GNU General Public License. This exception does not however 00042 * invalidate any other reasons why the executable file might be covered by 00043 * the GNU General Public License. 00044 */ 00045 00046 /* 00047 * 00048 * Copyright (c) 1996,1997 00049 * Silicon Graphics Computer Systems, Inc. 00050 * 00051 * Permission to use, copy, modify, distribute and sell this software 00052 * and its documentation for any purpose is hereby granted without fee, 00053 * provided that the above copyright notice appear in all copies and 00054 * that both that copyright notice and this permission notice appear 00055 * in supporting documentation. Silicon Graphics makes no 00056 * representations about the suitability of this software for any 00057 * purpose. It is provided "as is" without express or implied warranty. 00058 * 00059 * 00060 * Copyright (c) 1994 00061 * Hewlett-Packard Company 00062 * 00063 * Permission to use, copy, modify, distribute and sell this software 00064 * and its documentation for any purpose is hereby granted without fee, 00065 * provided that the above copyright notice appear in all copies and 00066 * that both that copyright notice and this permission notice appear 00067 * in supporting documentation. Hewlett-Packard Company makes no 00068 * representations about the suitability of this software for any 00069 * purpose. It is provided "as is" without express or implied warranty. 00070 * 00071 * 00072 */ 00073 00074 /* NOTE: This is an internal header file, included by other STL headers. 00075 * You should not attempt to use it directly. 00076 */ 00077 00078 /* 00079 00080 Red-black tree class, designed for use in implementing STL 00081 associative containers (set, multiset, map, and multimap). The 00082 insertion and deletion algorithms are based on those in Cormen, 00083 Leiserson, and Rivest, Introduction to Algorithms (MIT Press, 1990), 00084 except that 00085 00086 (1) the header cell is maintained with links not only to the root 00087 but also to the leftmost node of the tree, to enable constant time 00088 begin(), and to the rightmost node of the tree, to enable linear time 00089 performance when used with the generic set algorithms (set_union, 00090 etc.); 00091 00092 (2) when a node being deleted has two children its successor node is 00093 relinked into its place, rather than copied, so that the only 00094 iterators invalidated are those referring to the deleted node. 00095 00096 */ 00097 00098 #ifndef _RBT_NODE_H 00099 #define _RBT_NODE_H 00100 00101 #include <stdint.h> 00102 00103 /* 00104 * allocation parameters 00105 */ 00106 #define RBT_NUM 16 /* allocate nodes RBT_NUM at a time */ 00107 00108 /* 00109 * rbt_head is the head structure. 00110 * There is one rbt_head structure per tree. 00111 */ 00112 struct rbt_head 00113 { 00114 struct rbt_node *root; /* root node */ 00115 struct rbt_node *leftmost; /* leftmost node */ 00116 struct rbt_node *rightmost; /* rightmost nodei */ 00117 unsigned int rbt_num_node; /* number of nodes */ 00118 }; 00119 00120 /* 00121 * rbt_node is the node structure. 00122 * There is one rbt_tree structure per node. 00123 * 00124 * Usually, rbt_node is part of a bigger structure. 00125 * In this case, rbt_opaq point to this bigger structure. 00126 * 00127 * The field anchor is never NULL. It points to a pointer 00128 * containing the rbt_node address. This pointer is either 00129 * - the field left in the parent node 00130 * - the field next in the parent node 00131 * - the field root in the rbt_head structure (for the root node) 00132 */ 00133 00134 typedef struct rbt_node 00135 { 00136 unsigned int rbt_flags; 00137 struct rbt_node **anchor; /* anchor for this node */ 00138 struct rbt_node *parent; /* parent node or NULL for root */ 00139 struct rbt_node *left; /* left node */ 00140 struct rbt_node *next; /* "right" node */ 00141 uint64_t rbt_value; /* used for order */ 00142 void *rbt_opaq; /* pointer for external object */ 00143 } rbt_node_t; 00144 00145 /* 00146 * flags for rbt_node 00147 */ 00148 #define RBT_RED 01 /* red node */ 00149 00150 #endif /* _RBT_NODE_H */