blob: cc0c09e68d7b843566f792b455a870e3b495225e (
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
|
#include "config.h"
#include <stdio.h>
#include <string.h>
/**
* idtree - id allocation tree
*
* There are often cases where you want to provide an integer handle for
* some data, and easily map it back to another structure.
*
* idtree is an efficient implementation of an int->void * mapping, with
* assignment of the lowest available id number. It is from the Linux kernel
* via the Samba project.
*
* Example:
* #include <ccan/idtree/idtree.h>
* #include <ccan/tal/tal.h>
* #include <stdlib.h>
* #include <stdio.h>
*
* // Silly example which puts args in the idtree and retreives them
* int main(int argc, char *argv[])
* {
* struct idtree *idtree = idtree_new(NULL);
* unsigned int i;
*
* // This will return consecutive id numbers.
* for (i = 0; i < argc; i++) {
* printf("idtree_add('%s') -> id %i\n",
* argv[i], idtree_add(idtree, argv[i], -1));
* }
* for (i = 0; i < argc; i++) {
* printf("id %i -> '%s'\n",
* i, (char *)idtree_lookup(idtree, i));
* }
* return 0;
* }
*
* License: GPL (v2 or any later version)
* Maintainer: Rusty Russell <rusty@rustcorp.com.au>
* Author: Jim Houston <jim.houston@ccur.com>
*/
int main(int argc, char *argv[])
{
if (argc != 2)
return 1;
if (strcmp(argv[1], "depends") == 0) {
printf("ccan/tal\n");
return 0;
}
return 1;
}
|