6 * avl - Key-value dictionary based on AVL trees
8 * A simple, well-tested implementation of AVL trees for mapping
9 * unique keys to values. This implementation supports insertion,
10 * removal, lookup, and traversal.
12 * An AVL tree is a self-balancing binary tree that performs
13 * insertion, removal, and lookup in O(log n) time per operation.
16 * #include <ccan/avl/avl.h>
25 * #define new_tally() calloc(1, sizeof(struct tally))
27 * static void chomp(char *str)
29 * char *end = strchr(str, 0);
30 * if (end > str && end[-1] == '\n')
36 * AVL *avl = avl_new((total_order_noctx_cb) strcmp);
38 * struct tally *tally;
41 * while (fgets(line, sizeof(line), stdin))
45 * tally = avl_lookup(avl, line);
47 * avl_insert(avl, strdup(line), tally = new_tally());
52 * avl_foreach(i, avl) {
54 * struct tally *tally = i.value;
56 * printf("% 5ld: %s\n", tally->count, line);
67 * Author: Joey Adams <joeyadams3.14159@gmail.com>
71 int main(int argc, char *argv[])
73 /* Expect exactly one argument */
77 if (strcmp(argv[1], "depends") == 0) {
78 printf("ccan/order\n");