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

Method SetBit

structure/bitmap_1.go:32–55  ·  view source on GitHub ↗

SetBit Set the bit at the specified offset in the bitmap to the specified value If the key does not exist, it will be created If the bitmap length is not sufficient, it will be extended

(key string, offset uint, value bool)

Source from the content-addressed store, hash-verified

30// If the key does not exist, it will be created
31// If the bitmap length is not sufficient, it will be extended
32func (b *BitMapStructure) SetBit(key string, offset uint, value bool) error {
33 // Get bitmap
34 bitmap, length, err := b.getBitmapFromDB(key, true)
35
36 if err != nil {
37 return err
38 }
39
40 // If the bitmap length is not sufficient and value is 1, extend it
41 if offset >= uint(length) {
42 if value {
43 length = offset + 1
44 newSize := len2Size(length)
45 newBitmap := make([]byte, newSize)
46 copy(newBitmap, bitmap)
47 bitmap = newBitmap
48 } else { // If the value is 0, no operation is needed
49 return nil
50 }
51 }
52 b.setBit(bitmap, offset, value)
53
54 return b.setBitmapToDB(key, bitmap, length)
55}
56
57// SetBits Set the bit at the specified offset in the bitmap to the specified value
58// If the key does not exist, it will be created

Callers 1

Calls 4

getBitmapFromDBMethod · 0.95
setBitMethod · 0.95
setBitmapToDBMethod · 0.95
len2SizeFunction · 0.85

Tested by 1