locate first span of length 'n' using rank and select #3
1 changed files with 26 additions and 0 deletions
|
@ -1177,3 +1177,29 @@ sparsemap_rank(sparsemap_t *map, size_t offset, size_t idx)
|
||||||
}
|
}
|
||||||
return (result);
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue