1 #define intmap_index_t uint8_t
2 #define sintmap_index_t int8_t
4 #include <ccan/intmap/intmap.c>
5 #include <ccan/tap/tap.h>
10 typedef UINTMAP(uint8_t *) umap;
11 typedef SINTMAP(int8_t *) smap;
13 static bool check_umap(const umap *map)
15 /* This is a larger type than unsigned, and allows negative */
20 /* Must be in order, must contain value. */
22 for (v = uintmap_first(map, &i); v; v = uintmap_after(map, &i)) {
32 static bool check_smap(const smap *map)
34 /* This is a larger type than int, and allows negative */
39 /* Must be in order, must contain value. */
40 prev = -0x80000001ULL;
41 for (v = sintmap_first(map, &i); v; v = sintmap_after(map, &i)) {
56 uint8_t urandoms[NUM];
59 plan_tests(6 * NUM + 2);
63 for (i = 0; i < NUM; i++) {
64 urandoms[i] = random();
65 srandoms[i] = random();
67 for (i = 0; i < NUM; i++) {
68 /* In case we have duplicates. */
69 while (!uintmap_add(&umap, urandoms[i], urandoms+i))
70 urandoms[i] = random();
71 ok1(check_umap(&umap));
73 for (i = 0; i < NUM; i++) {
74 ok1(uintmap_del(&umap, urandoms[i]) == urandoms+i);
75 ok1(check_umap(&umap));
77 ok1(uintmap_empty(&umap));
79 for (i = 0; i < NUM; i++) {
80 /* In case we have duplicates. */
81 while (!sintmap_add(&smap, srandoms[i], srandoms+i))
82 srandoms[i] = random();
83 ok1(check_smap(&smap));
85 for (i = 0; i < NUM; i++) {
86 ok1(sintmap_del(&smap, srandoms[i]) == srandoms+i);
87 ok1(check_smap(&smap));
89 ok1(sintmap_empty(&smap));
91 /* This exits depending on whether all tests passed */