-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset-test.c
More file actions
60 lines (46 loc) · 1.11 KB
/
set-test.c
File metadata and controls
60 lines (46 loc) · 1.11 KB
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
/*
* Colibri Set Test
*
* Copyright (c) 2014-2021 Alexei A. Smekalkine
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <stdio.h>
#include <data/set.h>
#include <data/string.h>
SET_DECLARE (string)
static const char *strings[] = {
"test string #1",
"Lorem ipsum dolor sit amet",
"consectetur adipiscing elit",
"sed do eiusmod tempor incididunt",
"ut labore et dolore magna aliqua",
"test string #2",
NULL,
};
static const char *string_get (const struct string *o)
{
return (void *) o;
}
int main (int argc, char *argv[])
{
const struct string **list = (void *) strings;
struct string_set A;
size_t i;
const char *entry;
string_set_init (&A);
for (i = 0; list[i] != NULL; ++i)
if (string_set_insert (&A, list[i]) == NULL)
fprintf (stderr, "W: cannot add '%s' to set\n",
string_get (list[i]));
printf ("A:\n\n");
set_foreach (i, entry, &A)
printf ("%2zu: %s\n", i, entry);
string_set_remove (&A, list[1]);
string_set_remove (&A, list[3]);
printf ("\nA \\ {list[1], list[3]}:\n\n");
set_foreach (i, entry, &A)
printf ("%2zu: %s\n", i, entry);
string_set_fini (&A);
return 0;
}