fixup example

This commit is contained in:
Gregory Burd 2024-04-05 22:02:01 -04:00
parent 9ceaae6bc8
commit bafafe8194

View file

@ -126,16 +126,16 @@ main(void)
for (i = 2049; i < 2057; i++) { for (i = 2049; i < 2057; i++) {
bool set = sparsemap_is_set(map, i); bool set = sparsemap_is_set(map, i);
if (set) { if (set) {
__diag("verified %d was set, %s\n", i); __diag("verified %d was set\n", i);
} else { } else {
__diag("darn, %d was not really set, %s\n", i); __diag("darn, %d was not really set\n", i);
} }
} }
__diag("and %d was %s", i, sparsemap_is_set(map, i + 1) ? "set" : "not set"); __diag("and %d was %s", i, sparsemap_is_set(map, i + 1) ? "set" : "not set");
rank = sparsemap_rank(map, 2048, 2060); rank = sparsemap_rank(map, 2048, 2060);
__diag("rank was %lu at offset 109\n", rank); __diag("rank was %lu at offset 109\n", rank);
rank = sparsemap_span(map, 2048, 8); //rank = sparsemap_span(map, 2048, 8);
__diag("span was found at %lu\n", rank); //__diag("span was found at %lu\n", rank);
sparsemap_clear(map); sparsemap_clear(map);
// seed the PRNG // seed the PRNG
@ -146,7 +146,7 @@ main(void)
#endif #endif
for (i = 0; i < TEST_ARRAY_SIZE; i++) { for (i = 0; i < TEST_ARRAY_SIZE; i++) {
array[i] = (int)__random(&prng) % 7000 + 1; array[i] = (int)__random(&prng) % TEST_ARRAY_SIZE + 1;
if (array[i] < 0) { if (array[i] < 0) {
i--; i--;
} }
@ -161,15 +161,16 @@ main(void)
assert(sparsemap_is_set(map, array[i]) == true); assert(sparsemap_is_set(map, array[i]) == true);
} }
size_t l = sparsemap_span(map, 0, 8); size_t len = 6;
__diag("found span of 8 at %lu starting from 0\n", l); size_t l = sparsemap_span(map, 0, len);
for (i = (int)l; i < l + 8; i++) { __diag("found span of %d at %lu starting from 0\n", len, l);
bool set = sparsemap_is_set(map, l + i); for (i = (int)l; i < l + len; i++) {
bool set = sparsemap_is_set(map, i);
if (set) { if (set) {
__diag("verified %lu was set\n", l + i); __diag("verified %lu was set\n", i);
} else { } else {
__diag("darn, %lu was not really set, %s\n", l + i, __diag("darn, %lu was not really set, %s\n", i,
was_set(l + i, array) ? "but we thought it was" : "because it wasn't"); was_set(i, array) ? "but we thought it was" : "because it wasn't");
} }
} }