abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
avl.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include "avl.h"

Go to the source code of this file.

Macros

#define HEIGHT(node)   (node == NIL(avl_node) ? -1 : (node)->height)
 
#define BALANCE(node)   (HEIGHT((node)->right) - HEIGHT((node)->left))
 
#define compute_height(node)
 
#define COMPARE(key, nodekey, compare)
 
#define STACK_SIZE   50
 

Functions

static avl_nodenew_node ()
 
static avl_nodefind_rightmost ()
 
static void do_rebalance ()
 
static rotate_left ()
 
static rotate_right ()
 
static int do_check_tree ()
 
avl_treeavl_init_table (int(*)() compar)
 
 avl_lookup (avl_tree *tree, char *key, char **value_p)
 
 avl_first (avl_tree *tree, char **key_p, char **value_p)
 
 avl_last (avl_tree *tree, char **key_p, char **value_p)
 
 avl_insert (avl_tree *tree, char *key, char *value)
 
 avl_find_or_add (avl_tree *tree, char *key, char ***slot_p)
 
 avl_delete (avl_tree *tree, char **key_p, char **value_p)
 
static void avl_record_gen_forward (avl_node *node, avl_generator *gen)
 
static void avl_record_gen_backward (avl_node *node, avl_generator *gen)
 
avl_generatoravl_init_gen (avl_tree *tree, int dir)
 
 avl_gen (avl_generator *gen, char **key_p, char **value_p)
 
void avl_free_gen (avl_generator *gen)
 
static avl_nodefind_rightmost (avl_node **node_p)
 
static void do_rebalance (avl_node ***stack_nodep, int stack_n)
 
static rotate_left (avl_node **node_p)
 
static rotate_right (avl_node **node_p)
 
static void avl_walk_forward (avl_node *node, void(*)() func)
 
static void avl_walk_backward (avl_node *node, void(*)() func)
 
void avl_foreach (avl_tree *tree, void(*)() func, int direction)
 
static void free_entry (avl_node *node, void(*)() key_free, void(*)() value_free)
 
void avl_free_table (avl_tree *tree, void(*)() key_free, void(*)() value_free)
 
int avl_count (avl_tree *tree)
 
static avl_nodenew_node (char *key, char *value)
 
int avl_numcmp (char *x, char *y)
 
int avl_check_tree (avl_tree *tree)
 
static int do_check_tree (avl_node *node, int(*)() compar, int *error)
 

Macro Definition Documentation

#define BALANCE (   node)    (HEIGHT((node)->right) - HEIGHT((node)->left))

Definition at line 24 of file avl.c.

#define COMPARE (   key,
  nodekey,
  compare 
)
Value:
((compare == avl_numcmp) ? \
(int) key - (int) nodekey : \
(*compare)(key, nodekey))
enum keys key
int avl_numcmp(char *x, char *y)
Definition: avl.c:553

Definition at line 31 of file avl.c.

#define compute_height (   node)
Value:
{ \
int x=HEIGHT(node->left), y=HEIGHT(node->right); \
(node)->height = MAX(x,y) + 1; \
}
#define MAX(a, b)
Definition: avl.h:23
#define HEIGHT(node)
Definition: avl.c:23

Definition at line 26 of file avl.c.

#define HEIGHT (   node)    (node == NIL(avl_node) ? -1 : (node)->height)

Definition at line 23 of file avl.c.

#define STACK_SIZE   50

Definition at line 37 of file avl.c.

Function Documentation

int avl_check_tree ( avl_tree tree)

Definition at line 560 of file avl.c.

562 {
563  int error = 0;
564  (void) do_check_tree (tree->root, tree->compar, &error);
565  return error;
566 }
static int do_check_tree()
avl_node * root
Definition: avl.h:47
int(* compar)()
Definition: avl.h:48
int avl_count ( avl_tree tree)

Definition at line 530 of file avl.c.

532 {
533  return tree->num_entries;
534 }
int num_entries
Definition: avl.h:49
avl_delete ( avl_tree tree,
char **  key_p,
char **  value_p 
)

Definition at line 207 of file avl.c.

211 {
212  register avl_node **node_p, *node, *rightmost;
213  register int stack_n = 0;
214  char *key = *key_p;
215  int (*compare) () = tree->compar, diff;
216  avl_node **stack_nodep[STACK_SIZE];
217 
218  node_p = &tree->root;
219 
220  /* Walk down the tree saving the path; return if not found */
221  while ((node = *node_p) != NIL (avl_node))
222  {
223  diff = COMPARE (key, node->key, compare);
224  if (diff == 0)
225  goto delete_item;
226  stack_nodep[stack_n++] = node_p;
227  node_p = (diff < 0) ? &node->left : &node->right;
228  }
229  return 0; /* not found */
230 
231  /* prepare to delete node and replace it with rightmost of left tree */
232  delete_item:
233  *key_p = node->key;
234  if (value_p != 0)
235  *value_p = node->value;
236  if (node->left == NIL (avl_node))
237  {
238  *node_p = node->right;
239  }
240  else
241  {
242  rightmost = find_rightmost (&node->left);
243  rightmost->left = node->left;
244  rightmost->right = node->right;
245  rightmost->height = -2; /* mark bogus height for do_rebal */
246  *node_p = rightmost;
247  stack_nodep[stack_n++] = node_p;
248  }
249  FREE (node);
250 
251  /* work our way back up, re-balancing the tree */
252  do_rebalance (stack_nodep, stack_n);
253  tree->num_entries--;
254  tree->modified = 1;
255  return 1;
256 }
int num_entries
Definition: avl.h:49
int height
Definition: avl.h:41
char * key
Definition: avl.h:39
avl_node * root
Definition: avl.h:47
#define NIL(type)
Definition: avl.h:25
#define COMPARE(key, nodekey, compare)
Definition: avl.c:31
int modified
Definition: avl.h:50
static void do_rebalance()
#define FREE(obj)
Definition: avl.h:31
int(* compar)()
Definition: avl.h:48
char * value
Definition: avl.h:40
#define STACK_SIZE
Definition: avl.c:37
enum keys key
avl_node * left
Definition: avl.h:38
avl_node * right
Definition: avl.h:38
static avl_node * find_rightmost()
avl_find_or_add ( avl_tree tree,
char *  key,
char ***  slot_p 
)

Definition at line 170 of file avl.c.

174 {
175  register avl_node **node_p, *node;
176  register int stack_n = 0;
177  register int (*compare) () = tree->compar;
178  avl_node **stack_nodep[STACK_SIZE];
179  int diff;
180 
181  node_p = &tree->root;
182 
183  /* walk down the tree (saving the path); stop at insertion point */
184  while ((node = *node_p) != NIL (avl_node))
185  {
186  stack_nodep[stack_n++] = node_p;
187  diff = COMPARE (key, node->key, compare);
188  if (diff == 0)
189  {
190  if (slot_p != 0)
191  *slot_p = &node->value;
192  return 1; /* found */
193  }
194  node_p = (diff < 0) ? &node->left : &node->right;
195  }
196 
197  /* insert the item and re-balance the tree */
198  *node_p = new_node (key, NIL (char));
199  if (slot_p != 0)
200  *slot_p = &(*node_p)->value;
201  do_rebalance (stack_nodep, stack_n);
202  tree->num_entries++;
203  tree->modified = 1;
204  return 0; /* not already in tree */
205 }
int num_entries
Definition: avl.h:49
char * key
Definition: avl.h:39
static avl_node * new_node()
avl_node * root
Definition: avl.h:47
#define NIL(type)
Definition: avl.h:25
#define COMPARE(key, nodekey, compare)
Definition: avl.c:31
int modified
Definition: avl.h:50
static void do_rebalance()
int(* compar)()
Definition: avl.h:48
char * value
Definition: avl.h:40
#define STACK_SIZE
Definition: avl.c:37
enum keys key
avl_node * left
Definition: avl.h:38
avl_node * right
Definition: avl.h:38
avl_first ( avl_tree tree,
char **  key_p,
char **  value_p 
)

Definition at line 85 of file avl.c.

89 {
90  register avl_node *node;
91 
92  if (tree->root == 0)
93  {
94  return 0; /* no entries */
95  }
96  else
97  {
98  /* walk down the tree; stop at leftmost leaf */
99  for (node = tree->root; node->left != 0; node = node->left)
100  {
101  }
102  if (key_p != NIL (char *))
103  *key_p = node->key;
104  if (value_p != NIL (char *))
105  *value_p = node->value;
106  return 1;
107  }
108 }
char * key
Definition: avl.h:39
avl_node * root
Definition: avl.h:47
#define NIL(type)
Definition: avl.h:25
char * value
Definition: avl.h:40
avl_node * left
Definition: avl.h:38
void avl_foreach ( avl_tree tree,
void (*) ()  func,
int  direction 
)

Definition at line 483 of file avl.c.

487 {
488  if (direction == AVL_FORWARD)
489  {
490  avl_walk_forward (tree->root, func);
491  }
492  else
493  {
494  avl_walk_backward (tree->root, func);
495  }
496 }
static void avl_walk_forward(avl_node *node, void(*)() func)
Definition: avl.c:455
avl_node * root
Definition: avl.h:47
#define AVL_FORWARD
Definition: avl.h:62
static void avl_walk_backward(avl_node *node, void(*)() func)
Definition: avl.c:469
void avl_free_gen ( avl_generator gen)

Definition at line 338 of file avl.c.

340 {
341  FREE (gen->nodelist);
342  FREE (gen);
343 }
avl_node ** nodelist
Definition: avl.h:57
#define FREE(obj)
Definition: avl.h:31
void avl_free_table ( avl_tree tree,
void (*) ()  key_free,
void (*) ()  value_free 
)

Definition at line 519 of file avl.c.

523 {
524  free_entry (tree->root, key_free, value_free);
525  FREE (tree);
526 }
avl_node * root
Definition: avl.h:47
static void free_entry(avl_node *node, void(*)() key_free, void(*)() value_free)
Definition: avl.c:500
#define FREE(obj)
Definition: avl.h:31
avl_gen ( avl_generator gen,
char **  key_p,
char **  value_p 
)

Definition at line 314 of file avl.c.

318 {
319  avl_node *node;
320 
321  if (gen->count == gen->tree->num_entries)
322  {
323  return 0;
324  }
325  else
326  {
327  node = gen->nodelist[gen->count++];
328  if (key_p != NIL (char *))
329  *key_p = node->key;
330  if (value_p != NIL (char *))
331  *value_p = node->value;
332  return 1;
333  }
334 }
int num_entries
Definition: avl.h:49
char * key
Definition: avl.h:39
avl_node ** nodelist
Definition: avl.h:57
#define NIL(type)
Definition: avl.h:25
char * value
Definition: avl.h:40
avl_tree * tree
Definition: avl.h:56
avl_generator* avl_init_gen ( avl_tree tree,
int  dir 
)

Definition at line 287 of file avl.c.

290 {
291  avl_generator *gen;
292 
293  /* what a hack */
294  gen = ALLOC (avl_generator, 1);
295  gen->tree = tree;
296  gen->nodelist = ALLOC (avl_node *, avl_count (tree));
297  gen->count = 0;
298  if (dir == AVL_FORWARD)
299  {
300  avl_record_gen_forward (tree->root, gen);
301  }
302  else
303  {
304  avl_record_gen_backward (tree->root, gen);
305  }
306  gen->count = 0;
307 
308  /* catch any attempt to modify the tree while we generate */
309  tree->modified = 0;
310  return gen;
311 }
static void avl_record_gen_backward(avl_node *node, avl_generator *gen)
Definition: avl.c:273
int avl_count(avl_tree *tree)
Definition: avl.c:530
avl_node ** nodelist
Definition: avl.h:57
avl_node * root
Definition: avl.h:47
int modified
Definition: avl.h:50
#define ALLOC(type, num)
Definition: avl.h:27
avl_tree * tree
Definition: avl.h:56
static void avl_record_gen_forward(avl_node *node, avl_generator *gen)
Definition: avl.c:259
#define AVL_FORWARD
Definition: avl.h:62
avl_tree* avl_init_table ( int (*) ()  compar)

Definition at line 47 of file avl.c.

49 {
50  avl_tree *tree;
51 
52  tree = ALLOC (avl_tree, 1);
53  tree->root = NIL (avl_node);
54  tree->compar = compar;
55  tree->num_entries = 0;
56  return tree;
57 }
int num_entries
Definition: avl.h:49
avl_node * root
Definition: avl.h:47
#define NIL(type)
Definition: avl.h:25
#define ALLOC(type, num)
Definition: avl.h:27
int(* compar)()
Definition: avl.h:48
avl_insert ( avl_tree tree,
char *  key,
char *  value 
)

Definition at line 136 of file avl.c.

140 {
141  register avl_node **node_p, *node;
142  register int stack_n = 0;
143  register int (*compare) () = tree->compar;
144  avl_node **stack_nodep[STACK_SIZE];
145  int diff, status;
146 
147  node_p = &tree->root;
148 
149  /* walk down the tree (saving the path); stop at insertion point */
150  status = 0;
151  while ((node = *node_p) != NIL (avl_node))
152  {
153  stack_nodep[stack_n++] = node_p;
154  diff = COMPARE (key, node->key, compare);
155  if (diff == 0)
156  status = 1;
157  node_p = (diff < 0) ? &node->left : &node->right;
158  }
159 
160  /* insert the item and re-balance the tree */
161  *node_p = new_node (key, value);
162  do_rebalance (stack_nodep, stack_n);
163  tree->num_entries++;
164  tree->modified = 1;
165  return status;
166 }
int num_entries
Definition: avl.h:49
char * key
Definition: avl.h:39
static avl_node * new_node()
avl_node * root
Definition: avl.h:47
#define NIL(type)
Definition: avl.h:25
#define COMPARE(key, nodekey, compare)
Definition: avl.c:31
int modified
Definition: avl.h:50
static void do_rebalance()
int(* compar)()
Definition: avl.h:48
#define STACK_SIZE
Definition: avl.c:37
enum keys key
int value
avl_node * left
Definition: avl.h:38
avl_node * right
Definition: avl.h:38
avl_last ( avl_tree tree,
char **  key_p,
char **  value_p 
)

Definition at line 111 of file avl.c.

115 {
116  register avl_node *node;
117 
118  if (tree->root == 0)
119  {
120  return 0; /* no entries */
121  }
122  else
123  {
124  /* walk down the tree; stop at rightmost leaf */
125  for (node = tree->root; node->right != 0; node = node->right)
126  {
127  }
128  if (key_p != NIL (char *))
129  *key_p = node->key;
130  if (value_p != NIL (char *))
131  *value_p = node->value;
132  return 1;
133  }
134 }
char * key
Definition: avl.h:39
avl_node * root
Definition: avl.h:47
#define NIL(type)
Definition: avl.h:25
char * value
Definition: avl.h:40
avl_node * right
Definition: avl.h:38
avl_lookup ( avl_tree tree,
char *  key,
char **  value_p 
)

Definition at line 61 of file avl.c.

65 {
66  register avl_node *node;
67  register int (*compare) () = tree->compar, diff;
68 
69  node = tree->root;
70  while (node != NIL (avl_node))
71  {
72  diff = COMPARE (key, node->key, compare);
73  if (diff == 0)
74  {
75  /* got a match */
76  if (value_p != NIL (char *))
77  *value_p = node->value;
78  return 1;
79  }
80  node = (diff < 0) ? node->left : node->right;
81  }
82  return 0;
83 }
char * key
Definition: avl.h:39
avl_node * root
Definition: avl.h:47
#define NIL(type)
Definition: avl.h:25
#define COMPARE(key, nodekey, compare)
Definition: avl.c:31
int(* compar)()
Definition: avl.h:48
char * value
Definition: avl.h:40
enum keys key
avl_node * left
Definition: avl.h:38
avl_node * right
Definition: avl.h:38
int avl_numcmp ( char *  x,
char *  y 
)

Definition at line 553 of file avl.c.

555 {
556  return (int) x - (int) y;
557 }
static void avl_record_gen_backward ( avl_node node,
avl_generator gen 
)
static

Definition at line 273 of file avl.c.

276 {
277  if (node != NIL (avl_node))
278  {
279  avl_record_gen_backward (node->right, gen);
280  gen->nodelist[gen->count++] = node;
281  avl_record_gen_backward (node->left, gen);
282  }
283 }
static void avl_record_gen_backward(avl_node *node, avl_generator *gen)
Definition: avl.c:273
avl_node ** nodelist
Definition: avl.h:57
#define NIL(type)
Definition: avl.h:25
avl_node * left
Definition: avl.h:38
avl_node * right
Definition: avl.h:38
static void avl_record_gen_forward ( avl_node node,
avl_generator gen 
)
static

Definition at line 259 of file avl.c.

262 {
263  if (node != NIL (avl_node))
264  {
265  avl_record_gen_forward (node->left, gen);
266  gen->nodelist[gen->count++] = node;
267  avl_record_gen_forward (node->right, gen);
268  }
269 }
avl_node ** nodelist
Definition: avl.h:57
#define NIL(type)
Definition: avl.h:25
static void avl_record_gen_forward(avl_node *node, avl_generator *gen)
Definition: avl.c:259
avl_node * left
Definition: avl.h:38
avl_node * right
Definition: avl.h:38
static void avl_walk_backward ( avl_node node,
void (*) ()  func 
)
static

Definition at line 469 of file avl.c.

472 {
473  if (node != NIL (avl_node))
474  {
475  avl_walk_backward (node->right, func);
476  (*func) (node->key, node->value);
477  avl_walk_backward (node->left, func);
478  }
479 }
char * key
Definition: avl.h:39
#define NIL(type)
Definition: avl.h:25
char * value
Definition: avl.h:40
avl_node * left
Definition: avl.h:38
avl_node * right
Definition: avl.h:38
static void avl_walk_backward(avl_node *node, void(*)() func)
Definition: avl.c:469
static void avl_walk_forward ( avl_node node,
void (*) ()  func 
)
static

Definition at line 455 of file avl.c.

458 {
459  if (node != NIL (avl_node))
460  {
461  avl_walk_forward (node->left, func);
462  (*func) (node->key, node->value);
463  avl_walk_forward (node->right, func);
464  }
465 }
static void avl_walk_forward(avl_node *node, void(*)() func)
Definition: avl.c:455
char * key
Definition: avl.h:39
#define NIL(type)
Definition: avl.h:25
char * value
Definition: avl.h:40
avl_node * left
Definition: avl.h:38
avl_node * right
Definition: avl.h:38
static int do_check_tree ( )
static
static int do_check_tree ( avl_node node,
int (*) ()  compar,
int *  error 
)
static

Definition at line 570 of file avl.c.

574 {
575  int l_height, r_height, comp_height, bal;
576 
577  if (node == NIL (avl_node))
578  {
579  return -1;
580  }
581 
582  r_height = do_check_tree (node->right, compar, error);
583  l_height = do_check_tree (node->left, compar, error);
584 
585  comp_height = MAX (l_height, r_height) + 1;
586  bal = r_height - l_height;
587 
588  if (comp_height != node->height)
589  {
590  (void) printf ("Bad height for 0x%08x: computed=%d stored=%d\n",
591  node, comp_height, node->height);
592  ++*error;
593  }
594 
595  if (bal > 1 || bal < -1)
596  {
597  (void) printf ("Out of balance at node 0x%08x, balance = %d\n",
598  node, bal);
599  ++*error;
600  }
601 
602  if (node->left != NIL (avl_node) &&
603  (*compar) (node->left->key, node->key) > 0)
604  {
605  (void) printf ("Bad ordering between 0x%08x and 0x%08x",
606  node, node->left);
607  ++*error;
608  }
609 
610  if (node->right != NIL (avl_node) &&
611  (*compar) (node->key, node->right->key) > 0)
612  {
613  (void) printf ("Bad ordering between 0x%08x and 0x%08x",
614  node, node->right);
615  ++*error;
616  }
617 
618  return comp_height;
619 }
int height
Definition: avl.h:41
char * key
Definition: avl.h:39
static int do_check_tree()
#define NIL(type)
Definition: avl.h:25
#define MAX(a, b)
Definition: avl.h:23
avl_node * left
Definition: avl.h:38
avl_node * right
Definition: avl.h:38
static void do_rebalance ( )
static
static void do_rebalance ( avl_node ***  stack_nodep,
int  stack_n 
)
static

Definition at line 368 of file avl.c.

371 {
372  register avl_node **node_p, *node;
373  register int hl, hr;
374  int height;
375 
376  /* work our way back up, re-balancing the tree */
377  while (--stack_n >= 0)
378  {
379  node_p = stack_nodep[stack_n];
380  node = *node_p;
381  hl = HEIGHT (node->left); /* watch for NIL */
382  hr = HEIGHT (node->right); /* watch for NIL */
383  if ((hr - hl) < -1)
384  {
385  rotate_right (node_p);
386  }
387  else if ((hr - hl) > 1)
388  {
389  rotate_left (node_p);
390  }
391  else
392  {
393  height = MAX (hl, hr) + 1;
394  if (height == node->height)
395  break;
396  node->height = height;
397  }
398  }
399 }
int height
Definition: avl.h:41
static rotate_left()
#define MAX(a, b)
Definition: avl.h:23
static rotate_right()
#define HEIGHT(node)
Definition: avl.c:23
avl_node * left
Definition: avl.h:38
avl_node * right
Definition: avl.h:38
static avl_node* find_rightmost ( )
static
static avl_node* find_rightmost ( avl_node **  node_p)
static

Definition at line 346 of file avl.c.

348 {
349  register avl_node *node;
350  register int stack_n = 0;
351  avl_node **stack_nodep[STACK_SIZE];
352 
353  node = *node_p;
354  while (node->right != NIL (avl_node))
355  {
356  stack_nodep[stack_n++] = node_p;
357  node_p = &node->right;
358  node = *node_p;
359  }
360  *node_p = node->left;
361 
362  do_rebalance (stack_nodep, stack_n);
363  return node;
364 }
#define NIL(type)
Definition: avl.h:25
static void do_rebalance()
#define STACK_SIZE
Definition: avl.c:37
avl_node * left
Definition: avl.h:38
avl_node * right
Definition: avl.h:38
static void free_entry ( avl_node node,
void (*) ()  key_free,
void (*) ()  value_free 
)
static

Definition at line 500 of file avl.c.

504 {
505  if (node != NIL (avl_node))
506  {
507  free_entry (node->left, key_free, value_free);
508  free_entry (node->right, key_free, value_free);
509  if (key_free != 0)
510  (*key_free) (node->key);
511  if (value_free != 0)
512  (*value_free) (node->value);
513  FREE (node);
514  }
515 }
char * key
Definition: avl.h:39
#define NIL(type)
Definition: avl.h:25
static void free_entry(avl_node *node, void(*)() key_free, void(*)() value_free)
Definition: avl.c:500
#define FREE(obj)
Definition: avl.h:31
char * value
Definition: avl.h:40
avl_node * left
Definition: avl.h:38
avl_node * right
Definition: avl.h:38
static avl_node* new_node ( )
static
static avl_node* new_node ( char *  key,
char *  value 
)
static

Definition at line 537 of file avl.c.

540 {
541  register avl_node *new;
542 
543  new = ALLOC (avl_node, 1);
544  new->key = key;
545  new->value = value;
546  new->height = 0;
547  new->left = new->right = NIL (avl_node);
548  return new;
549 }
#define NIL(type)
Definition: avl.h:25
#define ALLOC(type, num)
Definition: avl.h:27
enum keys key
int value
static rotate_left ( )
static
static rotate_left ( avl_node **  node_p)
static

Definition at line 402 of file avl.c.

404 {
405  register avl_node *old_root = *node_p, *new_root, *new_right;
406 
407  if (BALANCE (old_root->right) >= 0)
408  {
409  *node_p = new_root = old_root->right;
410  old_root->right = new_root->left;
411  new_root->left = old_root;
412  }
413  else
414  {
415  new_right = old_root->right;
416  *node_p = new_root = new_right->left;
417  old_root->right = new_root->left;
418  new_right->left = new_root->right;
419  new_root->right = new_right;
420  new_root->left = old_root;
421  compute_height (new_right);
422  }
423  compute_height (old_root);
424  compute_height (new_root);
425 }
#define compute_height(node)
Definition: avl.c:26
#define BALANCE(node)
Definition: avl.c:24
avl_node * left
Definition: avl.h:38
avl_node * right
Definition: avl.h:38
static rotate_right ( )
static
static rotate_right ( avl_node **  node_p)
static

Definition at line 429 of file avl.c.

431 {
432  register avl_node *old_root = *node_p, *new_root, *new_left;
433 
434  if (BALANCE (old_root->left) <= 0)
435  {
436  *node_p = new_root = old_root->left;
437  old_root->left = new_root->right;
438  new_root->right = old_root;
439  }
440  else
441  {
442  new_left = old_root->left;
443  *node_p = new_root = new_left->right;
444  old_root->left = new_root->right;
445  new_left->right = new_root->left;
446  new_root->left = new_left;
447  new_root->right = old_root;
448  compute_height (new_left);
449  }
450  compute_height (old_root);
451  compute_height (new_root);
452 }
#define compute_height(node)
Definition: avl.c:26
#define BALANCE(node)
Definition: avl.c:24
avl_node * left
Definition: avl.h:38
avl_node * right
Definition: avl.h:38