MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / GetBitAtIndex

Method GetBitAtIndex

pkg/util/bitarray/bitarray.go:582–594  ·  view source on GitHub ↗

GetBitAtIndex extract bit at given index in the BitArray.

(index int)

Source from the content-addressed store, hash-verified

580
581// GetBitAtIndex extract bit at given index in the BitArray.
582func (d BitArray) GetBitAtIndex(index int) (int, error) {
583 // Check whether index asked is inside BitArray.
584 if index < 0 || uint(index) >= d.BitLen() {
585 return 0, pgerror.Newf(pgcode.ArraySubscript, "bit index %d out of valid range (0..%d)", index, int(d.BitLen())-1)
586 }
587 // To extract bit at the given index, we have to determine the
588 // position within words array, i.e. index/numBitsPerWord after
589 // that checked the bit at residual index.
590 if d.words[index/numBitsPerWord]&(word(1)<<(numBitsPerWord-1-uint(index)%numBitsPerWord)) != 0 {
591 return 1, nil
592 }
593 return 0, nil
594}
595
596// SetBitAtIndex returns the BitArray with an updated bit at a given index.
597func (d BitArray) SetBitAtIndex(index, toSet int) (BitArray, error) {

Callers

nothing calls this directly

Calls 2

BitLenMethod · 0.95
NewfFunction · 0.92

Tested by

no test coverage detected