summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/csset_erase.c
blob: c281c626b6d3bf9a0a95dc113b68cb9f69eb31e4 (plain)
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
#include <stdio.h>

#define i_key int
#include <stc/csset.h>

int main()
{
    c_AUTO (csset_int, set)
    {
        c_FORLIST (i, int, {30, 20, 80, 40, 60, 90, 10, 70, 50})
            csset_int_insert(&set, *i.ref);

        c_FOREACH (k, csset_int, set)
            printf(" %d", *k.ref);
        puts("");

        int val = 64;
        csset_int_iter it;
        printf("Show values >= %d:\n", val);
        it = csset_int_lower_bound(&set, val);

        c_FOREACH (k, csset_int, it, csset_int_end(&set)) 
            printf(" %d", *k.ref);
        puts("");

        printf("Erase values >= %d:\n", val);
        while (it.ref != csset_int_end(&set).ref)
            it = csset_int_erase_at(&set, it);

        c_FOREACH (k, csset_int, set)
            printf(" %d", *k.ref);
        puts("");

        val = 40;
        printf("Erase values < %d:\n", val);
        it = csset_int_lower_bound(&set, val);
        csset_int_erase_range(&set, csset_int_begin(&set), it);

        c_FOREACH (k, csset_int, set)
            printf(" %d", *k.ref);
        puts("");
    }
}