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

Method getBitmapFromDB

structure/bitmap_1.go:343–375  ·  view source on GitHub ↗

getBitmapFromDB retrieves data from the database. When isKeyCanNotExist is true, it returns an empty slice if the key doesn't exist instead of an error.

(key string, isKeyCanNotExist bool)

Source from the content-addressed store, hash-verified

341
342// getBitmapFromDB retrieves data from the database. When isKeyCanNotExist is true, it returns an empty slice if the key doesn't exist instead of an error.
343func (b *BitMapStructure) getBitmapFromDB(key string, isKeyCanNotExist bool) ([]byte, uint, error) {
344 if isKeyCanNotExist {
345 // Get data corresponding to the key from the database
346 dbData, err := b.db.Get([]byte(key))
347 // Since the key might not exist, we need to handle ErrKeyNotFound separately as it is a valid case
348 if err != nil && err != _const.ErrKeyNotFound {
349 return nil, 0, err
350 }
351 // Deserialize the data into a bitmap
352 bitmapArr, length, err := b.decodeBitmap(dbData)
353 if err != nil {
354 if len(dbData) != 0 {
355 return nil, 0, err
356 } else {
357 bitmapArr = make([]byte, 0)
358 length = 0
359 }
360 }
361 return bitmapArr, length, nil
362 } else {
363 // Get data corresponding to the key from the database
364 dbData, err := b.db.Get([]byte(key))
365 if err != nil {
366 return nil, 0, err
367 }
368 // Deserialize the data into a bitmap
369 bitmapArr, length, err := b.decodeBitmap(dbData)
370 if err != nil {
371 return nil, 0, err
372 }
373 return bitmapArr, length, nil
374 }
375}
376
377// setBitmapToDB stores the data into the database.
378func (b *BitMapStructure) setBitmapToDB(key string, bm []byte, length uint) error {

Callers 8

SetBitMethod · 0.95
SetBitsMethod · 0.95
GetBitMethod · 0.95
GetBitsMethod · 0.95
BitCountMethod · 0.95
BitOpMethod · 0.95
BitDelMethod · 0.95
BitDelsMethod · 0.95

Calls 2

decodeBitmapMethod · 0.95
GetMethod · 0.65

Tested by

no test coverage detected