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

Method BitDels

structure/bitmap_1.go:279–311  ·  view source on GitHub ↗

BitDels delete a group of bits at the specified offsets in the bitmap If the key does not exist, it returns an error There is room for optimization

(key string, offsets ...uint)

Source from the content-addressed store, hash-verified

277// If the key does not exist, it returns an error
278// There is room for optimization
279func (b *BitMapStructure) BitDels(key string, offsets ...uint) error {
280 // Check the parameters
281 if len(offsets) == 0 {
282 return ErrInvalidValue
283 }
284
285 bitmap, length, err := b.getBitmapFromDB(key, false)
286 if err != nil {
287 return err
288 }
289
290 sort.Slice(offsets, func(i, j int) bool {
291 return offsets[i] < offsets[j]
292 })
293
294 // Number of deletions so far
295 cntDel := uint(0)
296 // Current offset to delete
297 offsetIndex := 0
298
299 length -= uint(len(offsets))
300 for i := uint(0); i < length; i++ {
301 if offsetIndex < len(offsets) && i+cntDel == offsets[offsetIndex] {
302 cntDel++
303 offsetIndex++
304 i--
305 continue
306 }
307 b.setBit(bitmap, i, b.getBit(bitmap, i+cntDel))
308 }
309
310 return b.setBitmapToDB(key, bitmap, length)
311}
312
313var (
314 // ErrListEmpty is returned if the list is empty.

Callers 1

Calls 4

getBitmapFromDBMethod · 0.95
setBitMethod · 0.95
getBitMethod · 0.95
setBitmapToDBMethod · 0.95

Tested by 1