Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
trim21 opened this issue Jul 19, 2024 · 0 comments

Comments

@trim21
Copy link

trim21 commented Jul 19, 2024

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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant