Fix NSet.SetBits in GetDifference

This commit is contained in:
bloeys
2024-09-09 07:55:06 +04:00
parent 17b8c38162
commit ab047eb986
2 changed files with 7 additions and 1 deletions

View File

@ -257,7 +257,13 @@ func (n *NSet[T]) GetDifference(otherSet *NSet[T]) *NSet[T] {
}
if b1.StorageUnitCount > b2.StorageUnitCount {
copy(newB.Data[b2.StorageUnitCount:], b1.Data[b2.StorageUnitCount:])
for j := uint32(b2.StorageUnitCount); j < newB.StorageUnitCount; j++ {
storage := newB.Data[j]
outSet.SetBits += uint64(bits.OnesCount64(uint64(storage)))
}
}
}

View File

@ -126,7 +126,7 @@ func TestNSet(t *testing.T) {
nDiff1.AddMany(1, 2, 3, 4, 5, math.MaxUint32)
nDiff3 = nDiff1.GetDifference(nDiff2)
AllTrue(t, nDiff3.SetBits == 2, nDiff3.ContainsAll(2, 5, math.MaxUint32), !nDiff3.ContainsAny(1, 3, 4))
AllTrue(t, nDiff3.SetBits == 3, nDiff3.ContainsAll(2, 5, math.MaxUint32), !nDiff3.ContainsAny(1, 3, 4))
}
func TestNSetFullRange(t *testing.T) {