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

Method DelBit

structure/bitmap.go:170–199  ·  view source on GitHub ↗

DelBit function deletes a bit at the specified offset in the bitmap for the provided key

(k string, off uint)

Source from the content-addressed store, hash-verified

168
169// DelBit function deletes a bit at the specified offset in the bitmap for the provided key
170func (b *BitmapStructure) DelBit(k string, off uint) error {
171 // Convert the key to bytes
172 key := stringToBytesWithKey(k)
173 // Get the bits from the database
174 value, err := b.db.Get(key)
175 if err != nil {
176 return err
177 }
178 // Create a new bitset
179 bit := bitset.New(1)
180 // Unmarshal the retrieved bits into the bitset
181 err = bit.UnmarshalBinary(value)
182 if err != nil {
183 return err
184 }
185 // Clear the bit at the specified offset
186 bit.Clear(off)
187 // Convert the bitset to a byte array
188 buff, err := bitsetToByteArray(bit)
189 if err != nil {
190 return err
191 }
192 // Store the updated bitset in the database
193 err = b.db.Put(key, buff)
194 if err != nil {
195 return err
196 }
197 // Return nil if no errors occurred
198 return nil
199}
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 {

Callers 1

Calls 5

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

Tested by 1