Bloodhound is an ANSI C implementation of an AVL self-balancing binary search tree with intrusive nodes.
4 #include <bloodhound.h>
12 static int node_compare(const AvlNode *lhs, const AvlNode *rhs, void*) {
13 return strcmp(((Node*) lhs)->key, ((Node*) rhs)->key);
16 static int node_het_compare(const void *lhs, const AvlNode *rhs, void*) {
17 return strcmp((const char*) lhs, ((Node*) rhs)->key);
20 static void node_delete(AvlNode *, void*) { }
24 Node first = {{NULL, NULL, 0}, "foo", 5};
25 Node second = {{NULL, NULL, 0}, "foo", 10};
26 Node third = {{NULL, NULL, 0}, "bar", 5};
29 AvlTree_new(&map, node_compare, NULL, node_delete, NULL);
31 node = (Node*) AvlTree_insert(&map, &first.node);
34 node = (Node*) AvlTree_insert(&map, &second.node);
35 assert(node == &first);
37 node = (Node*) AvlTree_insert(&map, &third.node);
40 node = (Node*) AvlTree_remove(&map, "bar", node_het_compare, NULL);
41 assert(node == &third);
43 node = (Node*) AvlTree_get_mut(&map, "foo", node_het_compare, NULL);
44 assert(node == &second);
bloodhound is licensed under the MIT license.