DelBit function deletes a bit at the specified offset in the bitmap for the provided key
(k string, off uint)
| 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 { |
| 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 |
| 202 | func (b *BitmapStructure) DelBits(k string, off ...uint) error { |