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

Method GetBits

structure/bitmap_1.go:120–142  ·  view source on GitHub ↗

GetBits Get the values of a group of bits at the specified offsets in the bitmap If the key does not exist, it returns an error

(key string, offsets ...uint)

Source from the content-addressed store, hash-verified

118// GetBits Get the values of a group of bits at the specified offsets in the bitmap
119// If the key does not exist, it returns an error
120func (b *BitMapStructure) GetBits(key string, offsets ...uint) ([]bool, error) {
121 if len(offsets) == 0 {
122 return nil, ErrInvalidArgs
123 }
124
125 bitmap, length, err := b.getBitmapFromDB(key, false)
126 if err != nil {
127 return nil, err
128 }
129
130 result := make([]bool, len(offsets))
131
132 for idx, offset := range offsets {
133 // If the offset is out of range, default value is false
134 if offset >= length {
135 result[idx] = false
136 } else {
137 result[idx] = b.getBit(bitmap, offset)
138 }
139 }
140
141 return result, nil
142}
143
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

Callers 1

Calls 2

getBitmapFromDBMethod · 0.95
getBitMethod · 0.95

Tested by 1