MCPcopy Create free account
hub / github.com/dolthub/doltgresql / GetBitAtIndex

Method GetBitAtIndex

postgres/parser/utils/bitarray.go:558–571  ·  view source on GitHub ↗

GetBitAtIndex extract bit at given index in the BitArray.

(index int)

Source from the content-addressed store, hash-verified

556
557// GetBitAtIndex extract bit at given index in the BitArray.
558func (d BitArray) GetBitAtIndex(index int) (int, error) {
559 // Check whether index asked is inside BitArray.
560 if index < 0 || uint(index) >= d.BitLen() {
561 err := fmt.Errorf("GetBitAtIndex: bit index %d out of valid range (0..%d)", index, int(d.BitLen())-1)
562 return 0, pgerror.WithCandidateCode(err, pgcode.ArraySubscript)
563 }
564 // To extract bit at the given index, we have to determine the
565 // position within words array, i.e. index/numBitsPerWord after
566 // that checked the bit at residual index.
567 if d.words[index/numBitsPerWord]&(word(1)<<(numBitsPerWord-1-uint(index)%numBitsPerWord)) != 0 {
568 return 1, nil
569 }
570 return 0, nil
571}
572
573// SetBitAtIndex returns the BitArray with an updated bit at a given index.
574func (d BitArray) SetBitAtIndex(index, toSet int) (BitArray, error) {

Callers

nothing calls this directly

Calls 3

BitLenMethod · 0.95
WithCandidateCodeFunction · 0.92
ErrorfMethod · 0.65

Tested by

no test coverage detected