This commit is contained in:
Gregory Burd 2024-04-05 21:13:25 -04:00
parent 9d3f87837b
commit db551328a6

View file

@ -1177,3 +1177,29 @@ sparsemap_rank(sparsemap_t *map, size_t offset, size_t idx)
}
return (result);
}
/**
* Finds a span of set bits of at least |len| after |loc|. Returns the index of
* the n'th set bit that starts a span of at least |len| bits set to true.
* Returns ???TODO??? when a span of suitable length was not found.
*/
size_t
sparsemap_span(sparsemap_t *map, size_t loc, size_t len)
{
size_t size = 1024;
// size_t size = sparsemap_get_size(map);
// assert(size >= SM_SIZEOF_OVERHEAD);
// if (loc + 1 > size - len || len < size) {
// return size;
// }
do {
size_t nth = sparsemap_select(map, loc, len);
size_t count = sparsemap_rank(map, nth - len, nth);
if (count == len) {
return nth - len;
}
} while ((loc = sparsemap_select(map, loc + 1, 1)) < size - len);
return size;
}