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

Method SetBitAtIndex

postgres/parser/utils/bitarray.go:574–589  ·  view source on GitHub ↗

SetBitAtIndex returns the BitArray with an updated bit at a given index.

(index, toSet int)

Source from the content-addressed store, hash-verified

572
573// SetBitAtIndex returns the BitArray with an updated bit at a given index.
574func (d BitArray) SetBitAtIndex(index, toSet int) (BitArray, error) {
575 res := d.Clone()
576 // Check whether index asked is inside BitArray.
577 if index < 0 || uint(index) >= res.BitLen() {
578 err := fmt.Errorf("SetBitAtIndex: bit index %d out of valid range (0..%d)", index, int(res.BitLen())-1)
579 return BitArray{}, pgerror.WithCandidateCode(err, pgcode.ArraySubscript)
580 }
581 // To update bit at the given index, we have to determine the
582 // position within words array, i.e. index/numBitsPerWord after
583 // that updated the bit at residual index.
584 // Forcefully making bit at the index to 0.
585 res.words[index/numBitsPerWord] &= ^(word(1) << (numBitsPerWord - 1 - uint(index)%numBitsPerWord))
586 // Updating value at the index to toSet.
587 res.words[index/numBitsPerWord] |= word(toSet) << (numBitsPerWord - 1 - uint(index)%numBitsPerWord)
588 return res, nil
589}

Callers

nothing calls this directly

Calls 4

CloneMethod · 0.95
WithCandidateCodeFunction · 0.92
BitLenMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected