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

range over zeros #35

Open
aep opened this issue Jun 8, 2023 · 2 comments
Open

range over zeros #35

aep opened this issue Jun 8, 2023 · 2 comments

Comments

@aep
Copy link

aep commented Jun 8, 2023

i'm intending to use this as a free-map for a filesystem.

is there a reason there's no range function to find zeros?
am i holding it wrong?

@chippyash
Copy link

@aep It seemed a bit strange to me at first, but if you understand the original use case, it kind makes sense. Here's a function that will range over all the bits if you need it.

// RangeAll iterates over all the bits in the bitmap.
// For the rare instances where bitmap.Range is insufficient
func RangeAll(src bitmap.Bitmap, fn func(k uint32, v bool)) {
	l := uint32(len(src))
	for blkAt := uint32(0); blkAt < l; blkAt++ {
		blk := src[blkAt]
		bit := uint64(0x1)
		for bitAt := uint32(0); bitAt < 64; bitAt++ {
			k := blkAt*64 + bitAt
			v := (blk & bit) != 0
			fn(k, v)
			bit <<= 1
		}
	}
}

@chippyash
Copy link

This and other functions are now available in https://github.com/chippyash/logicgate

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

2 participants