5 * avl - Key-value dictionary based on AVL trees
7 * A simple, well-tested implementation of AVL trees for mapping
8 * unique keys to values. This implementation supports insertion,
9 * removal, lookup, and traversal.
11 * An AVL tree is a self-balancing binary tree that performs
12 * insertion, removal, and lookup in O(log n) time per operation.
15 * #include <ccan/avl/avl.h>
24 * #define new_tally() calloc(1, sizeof(struct tally))
26 * static void chomp(char *str)
28 * char *end = strchr(str, 0);
29 * if (end > str && end[-1] == '\n')
35 * AVL *avl = avl_new((AvlCompare) strcmp);
37 * struct tally *tally;
40 * while (fgets(line, sizeof(line), stdin))
44 * tally = avl_lookup(avl, line);
46 * avl_insert(avl, strdup(line), tally = new_tally());
51 * avl_foreach(i, avl) {
53 * struct tally *tally = i.value;
55 * printf("% 5ld: %s\n", tally->count, line);
67 * Author: Joey Adams <joeyadams3.14159@gmail.com>
69 int main(int argc, char *argv[])
71 /* Expect exactly one argument */
75 if (strcmp(argv[1], "depends") == 0) {