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 #ifndef lint
00037 static const char libbu_rb_rotate_RCSid[] = "@(#) $Header: /cvsroot/brlcad/brlcad/src/libbu/rb_rotate.c,v 14.13 2006/08/31 23:16:39 lbutler Exp $";
00038 #endif
00039
00040 #include "common.h"
00041
00042 #include <stdlib.h>
00043 #include <stdio.h>
00044 #include <math.h>
00045
00046 #include "machine.h"
00047 #include "rtlist.h"
00048 #include "bu.h"
00049 #include "compat4.h"
00050 #include "./rb_internals.h"
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 void _rb_rot_left (struct bu_rb_node *x, int order)
00063 {
00064 struct bu_rb_node *y;
00065 struct bu_rb_node *beta;
00066 struct bu_rb_node *x_parent;
00067 bu_rb_tree *tree = x -> rbn_tree;
00068
00069
00070
00071
00072 BU_CKMAG(x, BU_RB_NODE_MAGIC, "red-black node");
00073 BU_RB_CKORDER(x -> rbn_tree, order);
00074
00075 y = bu_rb_right_child(x, order);
00076
00077 if (tree -> rbt_debug & BU_RB_DEBUG_ROTATE)
00078 bu_log("_rb_rot_left(<%x>, %d)...\n", x, order);
00079
00080 bu_rb_right_child(x, order) = beta = bu_rb_left_child(y, order);
00081 if (beta != bu_rb_null(tree))
00082 bu_rb_parent(beta, order) = x;
00083 bu_rb_parent(y, order) = x_parent = bu_rb_parent(x, order);
00084 if (x_parent == bu_rb_null(tree))
00085 bu_rb_root(tree, order) = y;
00086 else if (x == bu_rb_left_child(x_parent, order))
00087 bu_rb_left_child(x_parent, order) = y;
00088 else
00089 bu_rb_right_child(x_parent, order) = y;
00090 bu_rb_left_child(y, order) = x;
00091 bu_rb_parent(x, order) = y;
00092
00093 bu_rb_size(y, order) = bu_rb_size(x, order);
00094 bu_rb_size(x, order) =
00095 bu_rb_size(bu_rb_left_child(x, order), order) +
00096 bu_rb_size(bu_rb_right_child(x, order), order) + 1;
00097 if (tree -> rbt_debug & BU_RB_DEBUG_OS)
00098 bu_log("After rotation, size(%x, %d)=%d, size(%x, %d)=%d\n",
00099 x, order, bu_rb_size(x, order), y, order, bu_rb_size(y, order));
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 void _rb_rot_right (struct bu_rb_node *y, int order)
00111 {
00112 struct bu_rb_node *x;
00113 struct bu_rb_node *beta;
00114 struct bu_rb_node *y_parent;
00115 bu_rb_tree *tree = y -> rbn_tree;
00116
00117
00118
00119
00120 BU_CKMAG(y, BU_RB_NODE_MAGIC, "red-black node");
00121 BU_RB_CKORDER(y -> rbn_tree, order);
00122
00123 x = bu_rb_left_child(y, order);
00124
00125 if (tree -> rbt_debug & BU_RB_DEBUG_ROTATE)
00126 bu_log("_rb_rot_right(<%x>, %d)...\n", y, order);
00127
00128 bu_rb_left_child(y, order) = beta = bu_rb_right_child(x, order);
00129 if (beta != bu_rb_null(tree))
00130 bu_rb_parent(beta, order) = y;
00131 bu_rb_parent(x, order) = y_parent = bu_rb_parent(y, order);
00132 if (y_parent == bu_rb_null(tree))
00133 bu_rb_root(tree, order) = x;
00134 else if (y == bu_rb_left_child(y_parent, order))
00135 bu_rb_left_child(y_parent, order) = x;
00136 else
00137 bu_rb_right_child(y_parent, order) = x;
00138 bu_rb_right_child(x, order) = y;
00139 bu_rb_parent(y, order) = x;
00140
00141 bu_rb_size(x, order) = bu_rb_size(y, order);
00142 bu_rb_size(y, order) =
00143 bu_rb_size(bu_rb_left_child(y, order), order) +
00144 bu_rb_size(bu_rb_right_child(y, order), order) + 1;
00145 if (tree -> rbt_debug & BU_RB_DEBUG_OS)
00146 bu_log("After rotation, size(%x, %d)=%d, size(%x, %d)=%d\n",
00147 x, order, bu_rb_size(x, order), y, order, bu_rb_size(y, order));
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158