contain-rs / bit-vec

A Vec of Bits
Apache License 2.0
167 stars 60 forks source link

Question: Is it possible to efficiently find a sequence of bits? #25

Open bgdncz opened 8 years ago

bgdncz commented 8 years ago

Hi! I don't know the relevance of this issue regarding BitVecs in particular, but is there a way to efficiently find a sequence of (un)set bits with a precise length? Ex: 15 set bits (and return the location of the first one)

pczarn commented 8 years ago

For 15 or more set bits, use memchr to find 0xFF bytes within storage. Once you found one, inspect the previous byte and the next one. In general, processing chunk by chunk is probably the second best option.

bgdncz commented 8 years ago

@pczarn Well, 15 was an example, what if I need to find 5 unset bits?