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

Method DelBits

structure/bitmap.go:202–233  ·  view source on GitHub ↗

DelBits function deletes multiple bits at the specified offsets in the bitmap for the provided key

(k string, off ...uint)

Source from the content-addressed store, hash-verified

200
201// DelBits function deletes multiple bits at the specified offsets in the bitmap for the provided key
202func (b *BitmapStructure) DelBits(k string, off ...uint) error {
203 // Convert the key to bytes
204 key := stringToBytesWithKey(k)
205 // Get the bits from the database
206 value, err := b.db.Get(key)
207 if err != nil {
208 return err
209 }
210 // Create a new bitset
211 bit := bitset.New(1)
212 // Unmarshal the retrieved bits into the bitset
213 err = bit.UnmarshalBinary(value)
214 if err != nil {
215 return err
216 }
217 // Clear the bits at the specified offsets
218 for _, u := range off {
219 bit.Clear(u)
220 }
221 // Convert the bitset to a byte array
222 buff, err := bitsetToByteArray(bit)
223 if err != nil {
224 return err
225 }
226 // Store the updated bitset in the database
227 err = b.db.Put(key, buff)
228 if err != nil {
229 return err
230 }
231 // Return nil if no errors occurred
232 return nil
233}
234
235// BitCount function counts the number of set bits in the specified range in the bitmap for the provided key
236func (b *BitmapStructure) BitCount(k string, start, end uint) (uint, error) {

Callers 1

Calls 5

stringToBytesWithKeyFunction · 0.85
bitsetToByteArrayFunction · 0.85
GetMethod · 0.65
PutMethod · 0.65
UnmarshalBinaryMethod · 0.45

Tested by 1