2 Copyright 2020 Google LLC
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file or at
6 https://developers.google.com/open-source/licenses/bsd
14 struct tree_node
*tree_search(struct tree_node
*tree
,
16 int (*compare
)(const void *, const void *))
21 res
= compare(key
, tree
->key
);
23 return tree_search(tree
->left
, key
, compare
);
25 return tree_search(tree
->right
, key
, compare
);
29 struct tree_node
*tree_insert(struct tree_node
**rootp
,
31 int (*compare
)(const void *, const void *))
38 REFTABLE_CALLOC_ARRAY(n
, 1);
47 res
= compare(key
, (*rootp
)->key
);
49 return tree_insert(&(*rootp
)->left
, key
, compare
);
51 return tree_insert(&(*rootp
)->right
, key
, compare
);
55 void infix_walk(struct tree_node
*t
, void (*action
)(void *arg
, void *key
),
59 infix_walk(t
->left
, action
, arg
);
62 infix_walk(t
->right
, action
, arg
);
65 void tree_free(struct tree_node
*t
)