| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include <stdio.h> |
| 18 |
|
| 19 |
#if defined(CWISS_EXAMPLE_UNIFIED) |
| 20 |
#include "cwisstable.h" |
| 21 |
#elif defined(CWISS_EXAMPLE_SPLIT) |
| 22 |
#include "cwisstable/declare.h" |
| 23 |
#include "cwisstable/policy.h" |
| 24 |
#else |
| 25 |
#error "must set CWISS_EXAMPLE_UNIFIED or CWISS_EXAMPLE_SPLIT" |
| 26 |
#endif |
| 27 |
|
| 28 |
CWISS_DECLARE_FLAT_HASHSET(MyIntSet, int); |
| 29 |
|
| 30 |
int main(void) { |
| 31 |
MyIntSet set = MyIntSet_new(8); |
| 32 |
|
| 33 |
for (int i = 0; i < 8; ++i) { |
| 34 |
int val = i * i + 1; |
| 35 |
MyIntSet_dump(&set); |
| 36 |
MyIntSet_insert(&set, &val); |
| 37 |
} |
| 38 |
MyIntSet_dump(&set); |
| 39 |
printf("\n"); |
| 40 |
|
| 41 |
int k = 4; |
| 42 |
assert(!MyIntSet_contains(&set, &k)); |
| 43 |
k = 5; |
| 44 |
MyIntSet_Iter it = MyIntSet_find(&set, &k); |
| 45 |
int* v = MyIntSet_Iter_get(&it); |
| 46 |
assert(v); |
| 47 |
printf("5: %p: %d\n", v, *v); |
| 48 |
|
| 49 |
MyIntSet_rehash(&set, 16); |
| 50 |
|
| 51 |
it = MyIntSet_find(&set, &k); |
| 52 |
v = MyIntSet_Iter_get(&it); |
| 53 |
assert(v); |
| 54 |
printf("5: %p: %d\n", v, *v); |
| 55 |
|
| 56 |
printf("entries:\n"); |
| 57 |
it = MyIntSet_iter(&set); |
| 58 |
for (int* p = MyIntSet_Iter_get(&it); p != NULL; |
| 59 |
p = MyIntSet_Iter_next(&it)) { |
| 60 |
printf("%d\n", *p); |
| 61 |
} |
| 62 |
printf("\n"); |
| 63 |
|
| 64 |
MyIntSet_erase(&set, &k); |
| 65 |
assert(!MyIntSet_contains(&set, &k)); |
| 66 |
|
| 67 |
printf("entries:\n"); |
| 68 |
it = MyIntSet_iter(&set); |
| 69 |
for (int* p = MyIntSet_Iter_get(&it); p != NULL; |
| 70 |
p = MyIntSet_Iter_next(&it)) { |
| 71 |
printf("%d\n", *p); |
| 72 |
} |
| 73 |
printf("\n"); |
| 74 |
|
| 75 |
MyIntSet_dump(&set); |
| 76 |
MyIntSet_destroy(&set); |
| 77 |
|
| 78 |
return 0; |
| 79 |
} |