GetBit function retrieves a bit at the specified offset in the bitmap for the provided key
(k string, off uint)
| 148 | |
| 149 | // GetBit function retrieves a bit at the specified offset in the bitmap for the provided key |
| 150 | func (b *BitmapStructure) GetBit(k string, off uint) (bool, error) { |
| 151 | // Convert the key to bytes |
| 152 | key := stringToBytesWithKey(k) |
| 153 | // Get the bits from the database |
| 154 | value, err := b.db.Get(key) |
| 155 | if err != nil { |
| 156 | return false, err |
| 157 | } |
| 158 | // Create a new bitset |
| 159 | bit := bitset.New(1) |
| 160 | // Unmarshal the retrieved bits into the bitset |
| 161 | err = bit.UnmarshalBinary(value) |
| 162 | if err != nil { |
| 163 | return false, err |
| 164 | } |
| 165 | // Return the bit at the specified offset |
| 166 | return bit.Test(off), nil |
| 167 | } |
| 168 | |
| 169 | // DelBit function deletes a bit at the specified offset in the bitmap for the provided key |
| 170 | func (b *BitmapStructure) DelBit(k string, off uint) error { |