might be working

This commit is contained in:
Gregory Burd 2024-04-05 21:53:48 -04:00
parent fa7d07044a
commit 9ceaae6bc8
2 changed files with 6 additions and 22 deletions

View file

@ -92,6 +92,7 @@ main(void)
// create the sparse bitmap
sparsemap_t *map = sparsemap(buf, sizeof(uint8_t) * TEST_ARRAY_SIZE, 0);
#if 0
for (i = 0; i < 8; i++) sparsemap_set(map, i, true);
rank = sparsemap_rank(map, 0, 8);
__diag("rank was %lu at offset 0\n", rank);
@ -115,35 +116,19 @@ main(void)
rank = sparsemap_rank(map, 0, 10);
__diag("rank was %lu between [0, 10]\n", rank);
assert(rank == 5);
for (i = 100; i < 108; i++) {
bool set = sparsemap_is_set(map, i);
if (set) {
__diag("verified %d was set, %s\n", i,
was_set(i, array) ? "but knew that" : "because it wasn't");
} else {
__diag("darn, %d was not set, %s\n", i,
was_set(i, array) ? "and yet we did set it" : "because it wasn't");
}
}
__diag("and %d was %s", i, sparsemap_is_set(map, i + 1) ? "set" : "not set");
rank = sparsemap_rank(map, 109, 8);
__diag("rank was %lu at offset 109\n", rank);
rank = sparsemap_span(map, 0, 8);
__diag("span was found at %lu\n", rank);
sparsemap_clear(map);
#endif
for (i = 2049; i < 2057; i++) sparsemap_set(map, i, true);
rank = sparsemap_rank(map, 2048, 8);
rank = sparsemap_rank(map, 2049, 2058);
__diag("rank was %lu at offset 108\n", rank);
assert(rank == 8);
for (i = 100; i < 108; i++) {
for (i = 2049; i < 2057; i++) {
bool set = sparsemap_is_set(map, i);
if (set) {
__diag("verified %d was set, %s\n", i,
was_set(i, array) ? "but we thought it was" : "because it wasn't");
__diag("verified %d was set, %s\n", i);
} else {
__diag("darn, %d was not really set, %s\n", i,
was_set(i, array) ? "but we thought it was" : "because it wasn't");
__diag("darn, %d was not really set, %s\n", i);
}
}
__diag("and %d was %s", i, sparsemap_is_set(map, i + 1) ? "set" : "not set");

View file

@ -492,7 +492,6 @@ __sm_chunk_map_rank(__sm_chunk_t *map, size_t start, size_t idx)
} else {
sm_bitvec_t w = map->m_data[1 +
__sm_chunk_map_get_position(map, i * SM_FLAGS_PER_INDEX_BYTE + j)];
idx -= start;
for (size_t k = 0; k < idx; k++) {
if (w & ((sm_bitvec_t)1 << k)) {
ret++;