8#ifndef EC_NEW_AVL_TREE_H
9#define EC_NEW_AVL_TREE_H
24#define COVISE_GREATER_THAN 2
25#define COVISE_GT_EQUAL 1
27#define COVISE_LS_EQUAL -1
28#define COVISE_LESS_THAN -2
93#if defined(__hpux) || defined(_SX)
189 if (
start->data == d)
195 retval = search_identical_node(d,
start->left->right);
201 retval = search_identical_node(d,
start->left);
210 retval = search_identical_node(d,
start->right->left);
216 retval = search_identical_node(d,
start->right);
266#define ERR_NODE 0x100403AC
281#if defined(__hpux) || defined(_SX)
285 CO_AVL_Node<T> *retval = 0L;
291 retval =
left->search_identical_node(d);
297 retval =
right->search_identical_node(d);
308 sprintf(tmp_str,
"AVLTree<T>::search_node, mode %d", search);
339 best_data = node->
data;
344 best_data = node->
data;
366 best_data = node->
data;
371 best_data = node->
data;
393 best_data = node->
data;
407 printf(
"Sorry, wrong parameter for search\n");
434 CO_AVL_Node<T> *node, *father, *Left, *Right, *Left_right, *Right_left;
438 print_comment(__LINE__, __FILE__,
"AVLTree<T>::rebalance_tree");
441 if (grow_shrink ==
GROW)
443 fprintf(stdout,
"\n rebalance_growing_tree(%8x,%8x,%d):",
444 this, tree_node, add_balance);
448 fprintf(stdout,
"\n rebalance_shrinking_tree(%8x,%8x,%d):",
449 this, tree_node, add_balance);
450 if ((
int *)
this == (
int *)0x10032c88 && (
int *)tree_node == (
int *)0x100b4858)
455 if (tree_node ==
NULL)
465 printf(
"[node=%x, data=%x]", node, node->
data);
469 fprintf(stdout,
" (node=%x,add_b=%d)", node, add_b);
471 bal = (node->
balance += add_b);
472 if (((bal == 0) && (grow_shrink ==
GROW))
474 || ((bal == add_b) && (grow_shrink ==
SHRINK)))
478 if (((bal != add_b) && (grow_shrink ==
GROW))
479 || ((bal != 0) && (grow_shrink ==
SHRINK)))
488 printf(
"Left==NULL \n");
508 if (father->
left == node)
514 father->
right = Left;
521 (Left->
up) = (node->
up);
525 (Left->
right)->up = node;
558 Left_right = Left->
right;
560 if (Left_right ==
NULL)
562 printf(
"Left_right==NULL \n");
563 print(
"Left_right==NULL");
570 if (father->
left == node)
572 father->
left = Left_right;
576 father->
right = Left_right;
584 Left_right->
up = father;
586 if (Left_right->
left)
588 (Left_right->
left)->up = Left;
590 Left_right->
left = Left;
591 Left->
up = Left_right;
593 if (Left_right->
right)
595 (Left_right->
right)->up = node;
597 Left_right->
right = node;
598 node->
up = Left_right;
618 printf(
"Right==NULL \n");
619 print(
"Right==NULL");
638 if (father->
left == node)
640 father->
left = Right;
644 father->
right = Right;
651 (Right->
up) = (node->
up);
655 (Right->
left)->up = node;
688 Right_left = Right->
left;
690 if (Right_left ==
NULL)
692 printf(
"Right_left==NULL \n");
693 print(
"Right_left==NULL");
700 if (father->
left == node)
702 father->
left = Right_left;
706 father->
right = Right_left;
713 Right_left->
up = father;
715 if (Right_left->
right)
717 (Right_left->
right)->up = Right;
719 Right_left->
right = Right;
720 Right->
up = Right_left;
722 if (Right_left->
left)
724 (Right_left->
left)->up = node;
726 Right_left->
left = node;
727 node->
up = Right_left;
743 if (grow_shrink ==
GROW)
756 if ((father->
left) == node)
758 add_b = -grow_shrink;
790 print(
"AVLTree<T>::insert_node, before");
801 print(
"tree after:");
807 new_data = new_node->
data;
824 new_node->
up = father;
827 father->
left = new_node;
832 father->
right = new_node;
837 rebalance_tree(father, add_balance,
GROW);
840 print(
"tree after:");
867 print(
"AVLTree<T>::remove_node_compare, before");
872 old_node = best_node;
875 print_comment(__LINE__, __FILE__,
"node not found for removal");
880 ret_data = node->
data;
884 printf(
"[node=%x, data=%x]", node, node->
data);
890 fprintf(stdout,
" case 1");
902 if (father->
left == node)
905 fprintf(stdout,
".1");
913 fprintf(stdout,
".2");
922 fprintf(stdout,
".3");
924 root = (node->
right);
927 (node->
right)->up = father;
931 else if (node->
right == 0L)
934 fprintf(stdout,
" case 2");
945 if (father->
left == node)
961 (node->
left)->up = father;
979 fprintf(stdout,
" case 3");
984 node = (node->
right);
988 printf(
"[node=%x, data=%x]", node, node->
data);
998 printf(
"\n father==NULL; tree=%8x; node=%8x : \n", root, node);
999 print(
"father==NULL");
1004 if (father->
right == node)
1015 (node->
left)->up = father;
1020 fprintf(stdout,
" case 4");
1022 node = (node->
right);
1025 node = (node->
left);
1028 father = (node->
up);
1030 if (father->
right == node)
1041 (node->
right)->up = father;
1048 if ((old_node->
up)->left == old_node)
1049 (old_node->
up)->
left = node;
1052 (node->
up) = (old_node->
up);
1061 (node->
left)->up = node;
1064 (node->
right)->up = node;
1066 if (father == old_node)
1073 rebalance_tree(father, add_balance,
SHRINK);
1076 print(
"tree after:");
1093 int add_balance = 0;
1104 printf(
"Serious Error, did not find a node with correct data\n");
1107 tmp_node = best_node;
1109 old_node = node = search_identical_node(
data, tmp_node);
1113 printf(
"remove_node failed\n");
1114 search_identical_node(
data, tmp_node);
1118 ret_data = node->
data;
1131 if (father->
left == node)
1134 fprintf(stdout,
".1");
1142 fprintf(stdout,
".2");
1151 fprintf(stdout,
".3");
1153 root = (node->
right);
1156 (node->
right)->up = father;
1160 else if (node->
right == 0L)
1163 fprintf(stdout,
" case 2");
1173 if (father->
left == node)
1186 root = (node->
left);
1189 (node->
left)->up = father;
1207 fprintf(stdout,
" case 3");
1209 node = (node->
left);
1212 node = (node->
right);
1216 printf(
"[node=%x, data=%x]", node, node->
data);
1221 father = (node->
up);
1226 printf(
"\n father==NULL; tree=%8x; node=%8x : \n", root, node);
1227 print(
"father==NULL");
1232 if (father->
right == node)
1243 (node->
left)->up = father;
1248 fprintf(stdout,
" case 4");
1250 node = (node->
right);
1253 node = (node->
left);
1256 father = (node->
up);
1257 if (father->
right == node)
1268 (node->
right)->up = father;
1274 if ((old_node->
up)->left == old_node)
1275 (old_node->
up)->
left = node;
1278 (node->
up) = (old_node->
up);
1287 (node->
left)->up = node;
1290 (node->
right)->up = node;
1292 if (father == old_node)
1299 rebalance_tree(father, add_balance,
SHRINK);
1302 print(
"tree after:");
1322 printf(
"Tree empty");
1335 if (curr_node == curr_node->
up)
1337 print_comment(__LINE__, __FILE__,
" .... recursive; ERROR!");
1338 printf(
" .... recursive; ERROR!");
1343 if (curr_node->
right)
1344 show_tree(curr_node->
right);
1348 for (i=0; i<covise_depth; i++)
1350 sprintf(tmp_str,
" Node %4d @@%p: bal=%2d data=%p",
1351 covise_n_node, curr_node, curr_node->
balance,
1352 (
void *)curr_node->
data);
1359 if (curr_node->
left)
1360 show_tree(curr_node->
left);
GLdouble n
Definition: khronos-glext.h:8447
GLuint start
Definition: khronos-glext.h:6343
GLuint GLuint GLsizei count
Definition: khronos-glext.h:6343
GLdouble GLdouble right
Definition: khronos-glext.h:12128
GLboolean GLboolean GLboolean b
Definition: khronos-glext.h:6895
GLint left
Definition: khronos-glext.h:8444
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
GLuint const GLchar * name
Definition: khronos-glext.h:6722
GLboolean GLboolean GLboolean GLboolean a
Definition: khronos-glext.h:6895
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: khronos-glext.h:6354
#define NULL
Definition: covise_avl_tree.h:272
const int COVISE_LESS_THAN
Definition: covise_avl_tree.h:34
const int COVISE_LS_EQUAL
Definition: covise_avl_tree.h:33
#define SHRINK
Definition: covise_avl_tree.h:427
const int COVISE_GT_EQUAL
Definition: covise_avl_tree.h:31
const int COVISE_EQUAL
Definition: covise_avl_tree.h:32
#define ERR_NODE
Definition: covise_avl_tree.h:266
#define GROW
Definition: covise_avl_tree.h:426
const int COVISE_GREATER_THAN
Definition: covise_avl_tree.h:30
list of all chemical elements
Definition: coConfig.h:27
UTILEXPORT int compare(const coObjID &a, const coObjID &b)
int covise_std_compare(char *, char *)
void print_comment(int line, const char *filename, const char *fmt,...)
Definition: coLog.cpp:25
std::enable_if< I==sizeof...(Tp), void >::type print(Stream &s, const std::tuple< Tp... > &t)
Definition: tokenbuffer_util.h:68
Definition: covise_avl_tree.h:119
T * remove_node_compare(T *data)
Definition: covise_avl_tree.h:852
CO_AVL_Node< T > * search_identical_node(T *d, CO_AVL_Node< T > *start)
Definition: covise_avl_tree.h:182
void empty_tree(void)
Definition: covise_avl_tree.h:160
CO_AVL_Node< T > * get_root(void)
Definition: covise_avl_tree.h:155
int insert_node(T *data)
Definition: covise_avl_tree.h:775
AVLTree(int(*comp)(T *a, T *b), const char *n)
Definition: covise_avl_tree.h:141
AVLTree(int(*comp)(T *a, T *b))
Definition: covise_avl_tree.h:133
void show_tree(CO_AVL_Node< T > *curr_node)
Definition: covise_avl_tree.h:1330
AVLTree()
Definition: covise_avl_tree.h:127
CO_AVL_Node< T > * best_node
Definition: covise_avl_tree.h:123
~AVLTree()
Definition: covise_avl_tree.h:149
const char * name
Definition: covise_avl_tree.h:124
T * search_node(T *data, int search)
Definition: covise_avl_tree.h:303
void rebalance_tree(CO_AVL_Node< T > *tree_node, int add_balance, int grow_shrink)
Definition: covise_avl_tree.h:430
int count
Definition: covise_avl_tree.h:125
int(* compare)(T *a, T *b)
Definition: covise_avl_tree.h:121
void print(char *)
Definition: covise_avl_tree.h:1312
T * remove_node(T *data)
Definition: covise_avl_tree.h:1089
CO_AVL_Node< T > * root
Definition: covise_avl_tree.h:122
Definition: covise_avl_tree.h:47
friend class CO_AVL_Tree
Definition: covise_avl_tree.h:48
CO_AVL_Node(T *d)
Definition: covise_avl_tree.h:56
T * data
Definition: covise_avl_tree.h:55
CO_AVL_Node< T > * search_identical_node(T *d)
Definition: covise_avl_tree.h:96
void print()
Definition: covise_avl_tree.h:69
void remove_nod(void)
Definition: covise_avl_tree.h:78
~CO_AVL_Node()
Definition: covise_avl_tree.h:64
CO_AVL_Node< T > * right
Definition: covise_avl_tree.h:52
CO_AVL_Node< T > * up
Definition: covise_avl_tree.h:53
CO_AVL_Node< T > * left
Definition: covise_avl_tree.h:51
int balance
Definition: covise_avl_tree.h:54