bitmap icon indicating copy to clipboard operation
bitmap copied to clipboard

range over zeros

Open aep opened this issue 1 year ago • 2 comments

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?

aep avatar Jun 08 '23 18:06 aep

@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 avatar Sep 22 '23 12:09 chippyash

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

chippyash avatar Sep 26 '23 06:09 chippyash