rb_internals.h

Go to the documentation of this file.
00001 /*                  R B _ I N T E R N A L S . H
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 1998-2006 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation; either version 2 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 
00022 /** \addtogroup rb */
00023 /*@{*/
00024 /** @file rb_internals.h
00025  *      The constants, macro functions, etc. need within LIBBU(3)
00026  *      to handle the red-black tree utilities.
00027  *
00028  *  @author
00029  *      Paul J. Tanenbaum
00030  *
00031  *  @par Source -
00032  *      The U. S. Army Research Laboratory
00033  *@n    Aberdeen Proving Ground, Maryland  21005-5068  USA
00034  *
00035  *  $Header: /cvsroot/brlcad/brlcad/src/libbu/rb_internals.h,v 14.12 2006/09/03 15:14:07 lbutler Exp $
00036  */
00037 
00038 #include "compat4.h"
00039 
00040 #ifndef SEEN_BU_H
00041 #include "bu.h"
00042 #endif
00043 
00044 #ifndef BU_RB_INTERNALS_H
00045 #define BU_RB_INTERNALS_H seen
00046 
00047 /**                     B U _ R B _ C K M A G ( )
00048  *          Check and validate a structure pointer
00049  *
00050  *      This macro has three parameters: a pointer, the magic number
00051  *      expected at that location, and a string describing the expected
00052  *      structure type.
00053  */
00054 #define BU_RB_CKMAG             BU_CKMAG
00055 #define BU_RB_NODE_MAGIC        0x72626e6f
00056 #define BU_RB_PKG_MAGIC         0x7262706b
00057 #define BU_RB_LIST_MAGIC        0x72626c73
00058 
00059 /**                     B U _ R B _ C K O R D E R ( )
00060  *
00061  *      This macro has two parameters: a tree and an order number.
00062  *      It ensures that the order number is valid for the tree.
00063  */
00064 #define BU_RB_CKORDER(t, o)                                     \
00065     if (((o) < 0) || ((o) >= (t) -> rbt_nm_orders))             \
00066     {                                                           \
00067         bu_log(                                                 \
00068             "Error: Order %d outside 0..%d (nm_orders-1), file %s, line %d\n", \
00069             (o), (t) -> rbt_nm_orders - 1, __FILE__, __LINE__); \
00070         exit (0);                                               \
00071     }
00072 
00073 /*
00074  *      Access functions for fields of bu_rb_tree
00075  */
00076 #define bu_rb_order_func(t, o)  (((t) -> rbt_order)[o])
00077 #define bu_rb_print(t, p)       (((t) -> rbt_print)((p) -> rbp_data))
00078 #define bu_rb_root(t, o)        (((t) -> rbt_root)[o])
00079 #define bu_rb_current(t)        ((t) -> rbt_current)
00080 #define bu_rb_null(t)           ((t) -> rbt_empty_node)
00081 #define bu_rb_get_uniqueness(t, o)                                      \
00082 (                                                                       \
00083     (((t) -> rbt_unique)[(o)/8] & (0x1 << ((o) % 8))) ? 1 : 0           \
00084 )
00085 #define bu_rb_set_uniqueness(t, o, u)                                   \
00086 {                                                                       \
00087     int _b = (o) / 8;                                                   \
00088     int _p = (o) - _b * 8;                                              \
00089                                                                         \
00090     ((t) -> rbt_unique)[_b] &= ~(0x1 << _p);                            \
00091     ((t) -> rbt_unique)[_b] |= (u) << _p;                               \
00092 }
00093 
00094 /*
00095  *      Access functions for fields of (struct bu_rb_node)
00096  */
00097 #define bu_rb_parent(n, o)      (((n) -> rbn_parent)[o])
00098 #define bu_rb_left_child(n, o)  (((n) -> rbn_left)[o])
00099 #define bu_rb_right_child(n, o) (((n) -> rbn_right)[o])
00100 #define BU_RB_LEFT              0
00101 #define BU_RB_RIGHT             1
00102 #define bu_rb_child(n, o, d)    (((d) == BU_RB_LEFT)            ?       \
00103                                     bu_rb_left_child((n), (o))  :       \
00104                                     bu_rb_right_child((n), (o)))
00105 #define bu_rb_other_child(n, o, d) (((d) == BU_RB_LEFT)         ?       \
00106                                     bu_rb_right_child((n), (o)) :       \
00107                                     bu_rb_left_child((n), (o)))
00108 #define bu_rb_size(n, o)        (((n) -> rbn_size)[o])
00109 #define bu_rb_get_color(n, o)                                           \
00110 (                                                                       \
00111     (((n) -> rbn_color)[(o)/8] & (0x1 << ((o) % 8))) ? 1 : 0            \
00112 )
00113 #define bu_rb_set_color(n, o, c)                                        \
00114 {                                                                       \
00115     int _b = (o) / 8;                                                   \
00116     int _p = (o) - _b * 8;                                              \
00117                                                                         \
00118     ((n) -> rbn_color)[_b] &= ~(0x1 << _p);                             \
00119     ((n) -> rbn_color)[_b] |= (c) << _p;                                \
00120 }
00121 #define BU_RB_RED               0
00122 #define BU_RB_BLACK             1
00123 #define bu_rb_data(n, o)        (((n) -> rbn_package)[o] -> rbp_data)
00124 
00125 /**
00126  *      Interface to _rb_walk()
00127  *      (Valid values for the parameter what_to_walk)
00128  */
00129 #define WALK_NODES              0
00130 #define WALK_DATA               1
00131 
00132 /**                 B U _ R B _ R O T A T E ( )
00133  *                          and
00134  *              B U _ R B _ O T H E R _ R O T A T E ( )
00135  *
00136  *      These macros have three parameters: the node about which
00137  *      to rotate, the order to be rotated, and the direction of
00138  *      rotation.  They allow indirection in the use of _rb_rot_left()
00139  *      and _rb_rot_right().
00140  */
00141 #define bu_rb_rotate(n, o, d)   (((d) == BU_RB_LEFT)            ?       \
00142                                     _rb_rot_left((n), (o))      :       \
00143                                     _rb_rot_right((n), (o)))
00144 #define bu_rb_other_rotate(n, o, d) (((d) == BU_RB_LEFT)        ?       \
00145                                     _rb_rot_right((n), (o))     :       \
00146                                     _rb_rot_left((n), (o)))
00147 
00148 /*
00149  *      Functions internal to LIBREDBLACK
00150  */
00151 BU_EXTERN(struct bu_rb_node *_rb_neighbor, (struct bu_rb_node *node,
00152                                          int            order,
00153                                          int            sense
00154                                         ));
00155 BU_EXTERN(void _rb_rot_left,            (struct bu_rb_node      *x,
00156                                          int            order
00157                                         ));
00158 BU_EXTERN(void _rb_rot_right,           (struct bu_rb_node      *y,
00159                                          int            order
00160                                         ));
00161 BU_EXTERN(void _rb_walk,                (bu_rb_tree     *tree,
00162                                          int            order,
00163                                          void           (*visit)(),
00164                                          int            what_to_visit,
00165                                          int            trav_type
00166                                         ));
00167 BU_EXTERN(void bu_rb_free_node,         (struct bu_rb_node *node));
00168 BU_EXTERN(void bu_rb_free_package,      (struct bu_rb_package *package));
00169 
00170 #endif /* BU_RB_INTERNALS_H */
00171 /*@}*/
00172 
00173 /*
00174  * Local Variables:
00175  * mode: C
00176  * tab-width: 8
00177  * c-basic-offset: 4
00178  * indent-tabs-mode: t
00179  * End:
00180  * ex: shiftwidth=4 tabstop=8
00181  */

Generated on Mon Sep 18 01:24:48 2006 for BRL-CAD by  doxygen 1.4.6