]> git.ozlabs.org Git - ccan/blob - ccan/idtree/_info
tdb: enforce hashing, via example hash in old rwlocks entry in header.
[ccan] / ccan / idtree / _info
1 #include <stdio.h>
2 #include <string.h>
3 #include "config.h"
4
5 /**
6  * idtree - id allocation tree
7  *
8  * There are often cases where you want to provide an integer handle for
9  * some data, and easily map it back to another structure.
10  *
11  * idtree is an efficient implementation of an int->void * mapping, with
12  * assignment of the lowest available id number.  It is from the Linux kernel
13  * via the Samba project.
14  *
15  * Example:
16  *      #include <ccan/idtree/idtree.h>
17  *      #include <ccan/talloc/talloc.h>
18  *      #include <stdlib.h>
19  *      #include <stdio.h>
20  *
21  *      // Silly example which puts args in the idtree and retreives them
22  *      int main(int argc, char *argv[])
23  *      {
24  *              struct idtree *idtree = idtree_new(NULL);
25  *              unsigned int i;
26  *      
27  *              // This will return consecutive id numbers.
28  *              for (i = 0; i < argc; i++) {
29  *                      printf("idtree_add('%s') -> id %i\n",
30  *                             argv[i], idtree_add(idtree, argv[i], -1));
31  *              }
32  *              for (i = 0; i < argc; i++) {
33  *                      printf("id %i -> '%s'\n", i, idtree_lookup(idtree, i));
34  *              }
35  *              return 0;
36  *      }
37  *
38  * Licence: GPL (2 or any later version)
39  * Maintainer: Rusty Russell <rusty@rustcorp.com.au>
40  * Author: Jim Houston <jim.houston@ccur.com>
41  */
42 int main(int argc, char *argv[])
43 {
44         if (argc != 2)
45                 return 1;
46
47         if (strcmp(argv[1], "depends") == 0) {
48                 printf("ccan/talloc\n");
49                 return 0;
50         }
51
52         return 1;
53 }