[6] | 1 | /* |
---|
| 2 | * Revision Control Information |
---|
| 3 | * |
---|
| 4 | * /projects/hsis/CVS/utilities/avl/avl.h,v |
---|
| 5 | * rajeev |
---|
| 6 | * 1.3 |
---|
| 7 | * 1995/08/08 22:36:24 |
---|
| 8 | * |
---|
| 9 | */ |
---|
| 10 | #ifndef AVL_INCLUDED |
---|
| 11 | #define AVL_INCLUDED |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | typedef struct avl_node_struct avl_node; |
---|
| 15 | struct avl_node_struct { |
---|
| 16 | avl_node *left, *right; |
---|
| 17 | char *key; |
---|
| 18 | char *value; |
---|
| 19 | int height; |
---|
| 20 | }; |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | typedef struct avl_tree_struct avl_tree; |
---|
| 24 | struct avl_tree_struct { |
---|
| 25 | avl_node *root; |
---|
| 26 | int (*compar)(const void *, const void *); |
---|
| 27 | int num_entries; |
---|
| 28 | int modified; |
---|
| 29 | }; |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | typedef struct avl_generator_struct avl_generator; |
---|
| 33 | struct avl_generator_struct { |
---|
| 34 | avl_tree *tree; |
---|
| 35 | avl_node **nodelist; |
---|
| 36 | int count; |
---|
| 37 | }; |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | #define AVL_FORWARD 0 |
---|
| 41 | #define AVL_BACKWARD 1 |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | EXTERN avl_tree *avl_init_table ARGS((int (*)(const void *, const void *))); |
---|
| 45 | EXTERN int avl_delete ARGS((avl_tree *, void *, void *)); |
---|
| 46 | EXTERN int avl_insert ARGS((avl_tree *, void *, void *)); |
---|
| 47 | EXTERN int avl_lookup ARGS((avl_tree *, const void *, void *)); |
---|
| 48 | EXTERN int avl_first ARGS((avl_tree *, char **, char **)); |
---|
| 49 | EXTERN int avl_last ARGS((avl_tree *, char **, char **)); |
---|
| 50 | EXTERN int avl_find_or_add ARGS((avl_tree *, char *, char ***)); |
---|
| 51 | EXTERN int avl_count ARGS((avl_tree *)); |
---|
| 52 | EXTERN int avl_numcmp ARGS((const void *, const void *)); |
---|
| 53 | EXTERN int avl_check_tree ARGS((avl_tree *tree)); |
---|
| 54 | EXTERN int avl_gen ARGS((avl_generator *, char **, char **)); |
---|
| 55 | EXTERN void avl_foreach ARGS((avl_tree *, void (*)(const void *, const void *), int)); |
---|
| 56 | EXTERN void avl_free_table ARGS((avl_tree *, void (*)(char *), void (*)(char *))); |
---|
| 57 | EXTERN void avl_free_gen ARGS((avl_generator *)); |
---|
| 58 | EXTERN avl_generator *avl_init_gen ARGS((avl_tree *, int)); |
---|
| 59 | |
---|
| 60 | #define avl_is_member(tree, key) avl_lookup(tree, key, (char **) 0) |
---|
| 61 | |
---|
| 62 | #define avl_foreach_item(table, gen, dir, key_p, value_p) \ |
---|
| 63 | for(gen = avl_init_gen(table, dir); \ |
---|
| 64 | avl_gen(gen, key_p, value_p) || (avl_free_gen(gen),0);) |
---|
| 65 | |
---|
| 66 | #endif |
---|