bitmap
bitmap copied to clipboard
range over zeros
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 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
}
}
}
This and other functions are now available in https://github.com/chippyash/logicgate