MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / BitCount

Method BitCount

structure/bitmap_1.go:146–164  ·  view source on GitHub ↗

BitCount Count the number of bits set to 1 in the specified range of the bitmap If the key does not exist, it returns an error

(key string, start uint, end uint)

Source from the content-addressed store, hash-verified

144// BitCount Count the number of bits set to 1 in the specified range of the bitmap
145// If the key does not exist, it returns an error
146func (b *BitMapStructure) BitCount(key string, start uint, end uint) (int, error) {
147 bitmap, length, err := b.getBitmapFromDB(key, false)
148 if err != nil {
149 return 0, err
150 }
151
152 total1 := 0
153
154 // Iterate over the range
155 for offset := start; offset <= end; offset++ {
156 if offset < length {
157 if b.getBit(bitmap, offset) {
158 total1++
159 }
160 }
161 }
162
163 return total1, nil
164}
165
166// BitOp count the number of bits set to 1 in the specified range of the bitmap
167// If the key does not exist, it returns an error

Callers

nothing calls this directly

Calls 2

getBitmapFromDBMethod · 0.95
getBitMethod · 0.95

Tested by

no test coverage detected