paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame^] | 1 | |
| 2 | #ifndef _BINTREE_H_ |
| 3 | #define _BINTREE_H_ |
| 4 | |
| 5 | struct bintree_node |
| 6 | { |
| 7 | struct bintree *tree; |
| 8 | |
| 9 | struct bintree_node *parent; |
| 10 | int parent_link; |
| 11 | |
| 12 | #define BL_LEFT 0 |
| 13 | #define BL_RIGHT 1 |
| 14 | #define BL_MAX 2 |
| 15 | struct bintree_node *link[BL_MAX]; |
| 16 | #define bl_left link[BL_LEFT] |
| 17 | #define bl_right link[BL_RIGHT] |
| 18 | |
| 19 | void *data; |
| 20 | }; |
| 21 | |
| 22 | struct bintree |
| 23 | { |
| 24 | int count; |
| 25 | struct bintree_node *root; |
| 26 | |
| 27 | int (*cmp) (void *, void *); |
| 28 | }; |
| 29 | |
| 30 | void *bintree_lookup (void *data, struct bintree *tree); |
| 31 | void *bintree_lookup_min (struct bintree *tree); |
| 32 | void *bintree_lookup_max (struct bintree *tree); |
| 33 | |
| 34 | int bintree_add (void *data, struct bintree *tree); |
| 35 | int bintree_remove (void *data, struct bintree *tree); |
| 36 | |
| 37 | void bintree_head (struct bintree *tree, struct bintree_node *node); |
| 38 | int bintree_end (struct bintree_node *node); |
| 39 | void bintree_next (struct bintree_node *node); |
| 40 | |
| 41 | struct bintree *bintree_create (); |
| 42 | void bintree_delete (struct bintree *); |
| 43 | |
| 44 | void bintree_print (void (*print) (int, void *), struct bintree *); |
| 45 | |
| 46 | #endif /*_BINTREE_H_*/ |
| 47 | |