]> git.ozlabs.org Git - ccan/blob - ccan/objset/_info
objset: new module.
[ccan] / ccan / objset / _info
1 #include <string.h>
2 #include "config.h"
3
4 /**
5  * objset - unordered set of pointers.
6  *
7  * This code implements a very simple unordered set of pointers.  It's very
8  * fast to add and check if something is in the set; it's implemented by
9  * a hash table.
10  *
11  * License: LGPL (v2.1 or any later version)
12  *
13  * Example:
14  *      // Silly example to determine if an arg starts with a -
15  *      #include <ccan/objset/objset.h>
16  *      #include <stdio.h>
17  *
18  *      struct objset_arg {
19  *              OBJSET_MEMBERS(const char *);
20  *      };
21  *
22  *      int main(int argc, char *argv[])
23  *      {
24  *              struct objset_arg args;
25  *              unsigned int i;
26  *
27  *              objset_init(&args);
28  *              // Put all args starting with - in the set.
29  *              for (i = 1; i < argc; i++)
30  *                      if (argv[i][0] == '-')
31  *                              objset_add(&args, argv[i]);
32  *
33  *              if (objset_empty(&args))
34  *                      printf("No arguments start with -.\n");
35  *              else {
36  *                      for (i = 1; i < argc; i++)
37  *                              if (objset_get(&args, argv[i]))
38  *                                      printf("%i,", i);
39  *                      printf("\n");
40  *              }
41  *              return 0;
42  *      }
43  *      // Given 'a b c' outputs No arguments start with -.
44  *      // Given 'a -b c' outputs 2,
45  *      // Given 'a -b -c d' outputs 2,3,
46  */
47 int main(int argc, char *argv[])
48 {
49         /* Expect exactly one argument */
50         if (argc != 2)
51                 return 1;
52
53         if (strcmp(argv[1], "depends") == 0) {
54                 printf("ccan/hash\n");
55                 printf("ccan/htable\n");
56                 printf("ccan/tcon\n");
57                 return 0;
58         }
59
60         return 1;
61 }