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

Method SetBitAtIndex

pkg/util/bitarray/bitarray.go:560–575  ·  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

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

Callers

nothing calls this directly

Calls 3

CloneMethod · 0.95
WithCandidateCodeFunction · 0.92
BitLenMethod · 0.80

Tested by

no test coverage detected