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
|
#include "config.h"
#include <stdio.h>
#include <string.h>
/**
* strset - an ordered set of strings
*
* This code implements an ordered set of string as a critbit tree. See:
*
* http://cr.yp.to/critbit.html
* http://github.com/agl/critbit (which this code is based on)
*
* Note that ccan/htable is faster and uses less memory, but doesn't provide
* ordered or prefix operations.
*
* Example:
* // Print all words in order.
* #include <ccan/strset/strset.h>
* #include <ccan/tal/grab_file/grab_file.h>
* #include <err.h>
* #include <string.h>
*
* static bool dump(const char *member, void *unused)
* {
* printf("%s ", member);
* return true; // Keep going with iteration.
* }
*
* int main(void)
* {
* struct strset words;
* char *file, *word;
*
* strset_init(&words);
* file = grab_fd(NULL, 0);
* if (!file)
* err(1, "Reading stdin");
*
* for (word = strtok(file, " \t\r\n");
* word;
* word = strtok(NULL, " \t\r\n")) {
* strset_add(&words, word);
* }
* strset_iterate(&words, dump, NULL);
* printf("\n");
* return 0;
* }
* // Given "foo bar" outputs "bar foo "
* // Given "foo foo bar" outputs "bar foo "
*
* License: CC0 (but some dependencies are LGPL!)
* Author: Rusty Russell <rusty@rustcorp.com.au>
* Ccanlint:
* license_depends_compat FAIL
*/
int main(int argc, char *argv[])
{
/* Expect exactly one argument */
if (argc != 2)
return 1;
if (strcmp(argv[1], "depends") == 0) {
printf("ccan/ilog\n"
"ccan/likely\n"
"ccan/short_types\n"
"ccan/str\n"
"ccan/typesafe_cb\n");
return 0;
}
return 1;
}
|