GetBitAtIndex extract bit at given index in the BitArray.
(index int)
| 542 | |
| 543 | // GetBitAtIndex extract bit at given index in the BitArray. |
| 544 | func (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. |
| 560 | func (d BitArray) SetBitAtIndex(index, toSet int) (BitArray, error) { |
nothing calls this directly
no test coverage detected