MCPcopy Create free account
hub / github.com/distributedio/titan / SetBit

Method SetBit

db/string.go:193–214  ·  view source on GitHub ↗

SetBit key offset bitvalue return the off postion of value

(offset, on int)

Source from the content-addressed store, hash-verified

191// SetBit key offset bitvalue
192// return the off postion of value
193func (s *String) SetBit(offset, on int) (int, error) {
194 val := s.Meta.Value
195 bitoff := offset >> 3
196 llen := int(bitoff) - len(val) + 1
197 if llen > 0 {
198 val = append(val, make([]byte, llen)...)
199 }
200
201 /* Get current values */
202 byteval := int(val[bitoff])
203 bit := uint(7 - (offset & 0x7))
204 bitval := byteval & (1 << bit)
205
206 /* Update byte with new bit value and return original value */
207 byteval &= (^(1 << bit))
208 byteval = byteval | ((on & 0x1) << bit)
209 val[bitoff] = byte(byteval)
210 if err := s.Set(val); err != nil {
211 return 0, err
212 }
213 return bitval, nil
214}
215
216// GetBit key offset bitvalye
217// offset / 8 > the index of value

Callers 4

SetBitFunction · 0.80
TestStringSetBitFunction · 0.80
TestStringGetBitFunction · 0.80
TestStringCountBitFunction · 0.80

Calls 1

SetMethod · 0.95

Tested by 3

TestStringSetBitFunction · 0.64
TestStringGetBitFunction · 0.64
TestStringCountBitFunction · 0.64