00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef lint
00039 static const char libbu_rb_create_RCSid[] = "@(#) $Header: /cvsroot/brlcad/brlcad/src/libbu/rb_create.c,v 14.13 2006/08/31 23:16:38 lbutler Exp $";
00040 #endif
00041
00042 #include "common.h"
00043
00044
00045
00046 #include <stdio.h>
00047 #include <math.h>
00048 #include "machine.h"
00049 #include "bu.h"
00050 #include "./rb_internals.h"
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 bu_rb_tree *bu_rb_create (char *description, int nm_orders, int (**order_funcs)() )
00063 {
00064 int order;
00065 bu_rb_tree *tree;
00066
00067
00068
00069
00070 tree = (bu_rb_tree *) bu_malloc(sizeof(bu_rb_tree), "red-black tree");
00071 tree -> rbt_root = (struct bu_rb_node **)
00072 bu_malloc(nm_orders * sizeof(struct bu_rb_node),
00073 "red-black roots");
00074 tree -> rbt_unique = (char *)
00075 bu_malloc((size_t) ceil((double) (nm_orders / 8.0)),
00076 "red-black uniqueness flags");
00077 bu_rb_null(tree) = (struct bu_rb_node *)
00078 bu_malloc(sizeof(struct bu_rb_node),
00079 "red-black empty node");
00080 bu_rb_null(tree) -> rbn_parent = (struct bu_rb_node **)
00081 bu_malloc(nm_orders * sizeof(struct bu_rb_node *),
00082 "red-black parents");
00083 bu_rb_null(tree) -> rbn_left = (struct bu_rb_node **)
00084 bu_malloc(nm_orders * sizeof(struct bu_rb_node *),
00085 "red-black left children");
00086 bu_rb_null(tree) -> rbn_right = (struct bu_rb_node **)
00087 bu_malloc(nm_orders * sizeof(struct bu_rb_node *),
00088 "red-black right children");
00089 bu_rb_null(tree) -> rbn_color = (char *)
00090 bu_malloc((size_t) ceil((double) (nm_orders / 8.0)),
00091 "red-black colors");
00092 bu_rb_null(tree) -> rbn_size = (int *)
00093 bu_malloc(nm_orders * sizeof(int),
00094 "red-black subtree sizes");
00095 bu_rb_null(tree) -> rbn_package = (struct bu_rb_package **)
00096 bu_malloc(nm_orders * sizeof(struct bu_rb_package *),
00097 "red-black packages");
00098
00099
00100
00101 tree -> rbt_magic = BU_RB_TREE_MAGIC;
00102 tree -> rbt_description = description;
00103 tree -> rbt_nm_orders = nm_orders;
00104 tree -> rbt_order = order_funcs;
00105 tree -> rbt_print = 0;
00106 bu_rb_uniq_all_off(tree);
00107 tree -> rbt_debug = 0x0;
00108 tree -> rbt_current = bu_rb_null(tree);
00109 for (order = 0; order < nm_orders; ++order)
00110 bu_rb_root(tree, order) = bu_rb_null(tree);
00111 BU_LIST_INIT(&(tree -> rbt_nodes.l));
00112 BU_LIST_INIT(&(tree -> rbt_packages.l));
00113
00114
00115
00116
00117 bu_rb_null(tree) -> rbn_magic = BU_RB_NODE_MAGIC;
00118 bu_rb_null(tree) -> rbn_tree = tree;
00119 for (order = 0; order < nm_orders; ++order)
00120 {
00121 bu_rb_parent(bu_rb_null(tree), order) = BU_RB_NODE_NULL;
00122 bu_rb_set_color(bu_rb_null(tree), order, BU_RB_BLACK);
00123 bu_rb_left_child(bu_rb_null(tree), order) = BU_RB_NODE_NULL;
00124 bu_rb_right_child(bu_rb_null(tree), order) = BU_RB_NODE_NULL;
00125 bu_rb_size(bu_rb_null(tree), order) = 0;
00126 (bu_rb_null(tree) -> rbn_package)[order] = BU_RB_PKG_NULL;
00127 }
00128
00129 return (tree);
00130 }
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 bu_rb_tree *bu_rb_create1 (char *description, int (*order_func) ())
00147 {
00148 int (**ofp)();
00149
00150 ofp = (int (**)())
00151 bu_malloc(sizeof(int (*)()), "red-black function table");
00152 *ofp = order_func;
00153 return (bu_rb_create(description, 1, ofp));
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165