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