kelindar / bitmap

Simple dense bitmap index in Go with binary operators
MIT License
306 stars 23 forks source link

feature request: new method `OnesTo(n)` like `CountTo(n)`, `Ones` with a upper boundary? #40

Open trim21 opened 2 months ago

trim21 commented 2 months ago

currently need to call Grow then ones, them remove items >= n

Can we add a new method OnesTo(n) set Ones with a upper boundary?

A impl:

func (dst *Bitmap) OnesTo(n uint32) {
    blkAt := n >> 6

    b := make(Bitmap, blkAt+1)

    for i := uint32(0); i < blkAt; i++ {
        b[i] = math.MaxUint64 // saidly golang's compiler can't optimize this
    }

    b[blkAt] = uint64(math.MaxUint64) >> (64 - n%64)

    *dst = b
}