| 27 | } |
| 28 | |
| 29 | struct tree_node *tree_insert(struct tree_node **rootp, |
| 30 | void *key, |
| 31 | int (*compare)(const void *, const void *)) |
| 32 | { |
| 33 | int res; |
| 34 | |
| 35 | if (!*rootp) { |
| 36 | struct tree_node *n; |
| 37 | |
| 38 | REFTABLE_CALLOC_ARRAY(n, 1); |
| 39 | if (!n) |
| 40 | return NULL; |
| 41 | |
| 42 | n->key = key; |
| 43 | *rootp = n; |
| 44 | return *rootp; |
| 45 | } |
| 46 | |
| 47 | res = compare(key, (*rootp)->key); |
| 48 | if (res < 0) |
| 49 | return tree_insert(&(*rootp)->left, key, compare); |
| 50 | else if (res > 0) |
| 51 | return tree_insert(&(*rootp)->right, key, compare); |
| 52 | return *rootp; |
| 53 | } |
| 54 | |
| 55 | void infix_walk(struct tree_node *t, void (*action)(void *arg, void *key), |
| 56 | void *arg) |