summaryrefslogtreecommitdiff
path: root/ccan/avl/_info
blob: c7fc98a46ff2f97327d9c92518a550651c255432 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "config.h"
#include <stdio.h>
#include <string.h>

/**
 * avl - Key-value dictionary based on AVL trees
 *
 * A simple, well-tested implementation of AVL trees for mapping
 * unique keys to values.  This implementation supports insertion,
 * removal, lookup, and traversal.
 *
 * An AVL tree is a self-balancing binary tree that performs
 * insertion, removal, and lookup in O(log n) time per operation.
 *
 * Example:
 * #include <ccan/avl/avl.h>
 * 
 * #include <stdio.h>
 * #include <stdlib.h>
 * #include <string.h>
 * 
 * struct tally {
 * 	long count;
 * };
 * #define new_tally() calloc(1, sizeof(struct tally))
 * 
 * static void chomp(char *str)
 * {
 * 	char *end = strchr(str, 0);
 * 	if (end > str && end[-1] == '\n')
 * 		end[-1] = 0;
 * }
 * 
 * int main(void)
 * {
 * 	AVL          *avl = avl_new((total_order_noctx_cb) strcmp);
 * 	AvlIter       i;
 * 	struct tally *tally;
 * 	char          line[256];
 * 	
 * 	while (fgets(line, sizeof(line), stdin))
 * 	{
 * 		chomp(line);
 * 		
 * 		tally = avl_lookup(avl, line);
 * 		if (tally == NULL)
 * 			avl_insert(avl, strdup(line), tally = new_tally());
 * 		
 * 		tally->count++;
 * 	}
 * 	
 * 	avl_foreach(i, avl) {
 * 		char         *line  = i.key;
 * 		struct tally *tally = i.value;
 * 		
 * 		printf("% 5ld: %s\n", tally->count, line);
 * 		
 * 		free(line);
 * 		free(tally);
 * 	}
 * 	
 * 	avl_free(avl);
 * 	
 * 	return 0;
 * }
 *
 * Author: Joey Adams <joeyadams3.14159@gmail.com>
 * License: MIT
 * Version: 0.1
 */
int main(int argc, char *argv[])
{
	/* Expect exactly one argument */
	if (argc != 2)
		return 1;

	if (strcmp(argv[1], "depends") == 0) {
		printf("ccan/order\n");
		return 0;
	}

	return 1;
}