]> git.ozlabs.org Git - ccan/blob - ccan/strset/_info
crypto/shachain/tools: update to new rbuf API.
[ccan] / ccan / strset / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * strset - an ordered set of strings
7  *
8  * This code implements an ordered set of string as a critbit tree. See:
9  *
10  *  http://cr.yp.to/critbit.html
11  *  http://github.com/agl/critbit (which this code is based on)
12  *
13  * Note that ccan/htable is faster and uses less memory, but doesn't provide
14  * ordered or prefix operations.
15  *
16  * Example:
17  *      // Print all words in order.
18  *      #include <ccan/strset/strset.h>
19  *      #include <ccan/tal/grab_file/grab_file.h>
20  *      #include <err.h>
21  *      #include <string.h>
22  *
23  *      static bool dump(const char *member, void *unused)
24  *      {
25  *              printf("%s ", member);
26  *              return true; // Keep going with iteration.
27  *      }
28  *
29  *      int main(void)
30  *      {
31  *              struct strset words;
32  *              char *file, *word;
33  *
34  *              strset_init(&words);
35  *              file = grab_fd(NULL, 0);
36  *              if (!file)
37  *                      err(1, "Reading stdin");
38  *
39  *              for (word = strtok(file, " \t\r\n");
40  *                   word;
41  *                   word = strtok(NULL, " \t\r\n")) {
42  *                      strset_add(&words, word);
43  *              }
44  *              strset_iterate(&words, dump, NULL);
45  *              printf("\n");
46  *              return 0;
47  *      }
48  *      // Given "foo bar" outputs "bar foo \n"
49  *      // Given "foo foo bar" outputs "bar foo \n"
50  *
51  * License: CC0 (but some dependencies are LGPL!)
52  * Author: Rusty Russell <rusty@rustcorp.com.au>
53  * Ccanlint:
54  *      license_depends_compat FAIL
55  */
56 int main(int argc, char *argv[])
57 {
58         /* Expect exactly one argument */
59         if (argc != 2)
60                 return 1;
61
62         if (strcmp(argv[1], "depends") == 0) {
63                 printf("ccan/ilog\n"
64                        "ccan/likely\n"
65                        "ccan/short_types\n"
66                        "ccan/str\n"
67                        "ccan/typesafe_cb\n");
68                 return 0;
69         }
70
71         return 1;
72 }