Skip to content

Commit cc750a0

Browse files
committed
added comments
1 parent d231880 commit cc750a0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

bitset.go

+6
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,11 @@ func (b *BitSet) DeleteAt(i uint) *BitSet {
525525
//
526526
// See also [BitSet.AsSlice] and [BitSet.NextSetMany].
527527
func (b *BitSet) AppendTo(buf []uint) []uint {
528+
// In theory, we could overflow uint, but in practice, we will not.
528529
for idx, word := range b.set {
529530
for word != 0 {
531+
// In theory idx<<log2WordSize could overflow, but it will not overflow
532+
// in practice.
530533
buf = append(buf, uint(idx<<log2WordSize+bits.TrailingZeros64(word)))
531534

532535
// clear the rightmost set bit
@@ -548,6 +551,8 @@ func (b *BitSet) AsSlice(buf []uint) []uint {
548551
for idx, word := range b.set {
549552
for ; word != 0; size++ {
550553
// panics if capacity of buf is exceeded.
554+
// In theory idx<<log2WordSize could overflow, but it will not overflow
555+
// in practice.
551556
buf[size] = uint(idx<<log2WordSize + bits.TrailingZeros64(word))
552557

553558
// clear the rightmost set bit
@@ -615,6 +620,7 @@ func (b *BitSet) NextSet(i uint) (uint, bool) {
615620
// However if Count() is large, it might be preferable to
616621
// use several calls to NextSetMany for memory reasons.
617622
func (b *BitSet) NextSetMany(i uint, buffer []uint) (uint, []uint) {
623+
// In theory, we could overflow uint, but in practice, we will not.
618624
capacity := cap(buffer)
619625
result := buffer[:capacity]
620626

0 commit comments

Comments
 (0)