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

Method GetBitAtIndex

pkg/util/bitarray/bitarray.go:544–557  ·  view source on GitHub ↗

GetBitAtIndex extract bit at given index in the BitArray.

(index int)

Source from the content-addressed store, hash-verified

542
543// GetBitAtIndex extract bit at given index in the BitArray.
544func (d BitArray) GetBitAtIndex(index int) (int, error) {
545 // Check whether index asked is inside BitArray.
546 if index < 0 || uint(index) >= d.BitLen() {
547 err := fmt.Errorf("GetBitAtIndex: bit index %d out of valid range (0..%d)", index, int(d.BitLen())-1)
548 return 0, pgerror.WithCandidateCode(err, pgcode.ArraySubscript)
549 }
550 // To extract bit at the given index, we have to determine the
551 // position within words array, i.e. index/numBitsPerWord after
552 // that checked the bit at residual index.
553 if d.words[index/numBitsPerWord]&(word(1)<<(numBitsPerWord-1-uint(index)%numBitsPerWord)) != 0 {
554 return 1, nil
555 }
556 return 0, nil
557}
558
559// SetBitAtIndex returns the BitArray with an updated bit at a given index.
560func (d BitArray) SetBitAtIndex(index, toSet int) (BitArray, error) {

Callers

nothing calls this directly

Calls 2

BitLenMethod · 0.95
WithCandidateCodeFunction · 0.92

Tested by

no test coverage detected