fixedbitset icon indicating copy to clipboard operation
fixedbitset copied to clipboard

Finding consecutive run from a starting point

Open grovesNL opened this issue 1 year ago • 0 comments
trafficstars

Hi! :wave: Is there a way to find consecutive runs of 1 or 0 given a starting point? It looks like I could implement this manually by indexing bits one at a time, but I was wondering if there was a more efficient way to do this (especially taking of instructions like trailing/leading zeros or population count while iterating through blocks for example).

Ideally it could search lower, higher, or bidirectionally (the case I'm most interested in).

For example, starting at bit 4, search lower and higher bits to find how many consecutive 1s we can find in this run. If bit 4 is set to 0, then the run length is 0. If bits 3, 4, 5, 6, 7 are all set to 1, then the run length would be 5.

In case it's helpful for context, the same idea was requested in roaring-rs #274.

grovesNL avatar Jul 11 '24 20:07 grovesNL