mirror of
https://github.com/bloeys/nset.git
synced 2025-12-29 06:28:19 +00:00
Fix NSet.SetBits in GetDifference
This commit is contained in:
6
nset.go
6
nset.go
@ -257,7 +257,13 @@ func (n *NSet[T]) GetDifference(otherSet *NSet[T]) *NSet[T] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if b1.StorageUnitCount > b2.StorageUnitCount {
|
if b1.StorageUnitCount > b2.StorageUnitCount {
|
||||||
|
|
||||||
copy(newB.Data[b2.StorageUnitCount:], b1.Data[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)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -126,7 +126,7 @@ func TestNSet(t *testing.T) {
|
|||||||
|
|
||||||
nDiff1.AddMany(1, 2, 3, 4, 5, math.MaxUint32)
|
nDiff1.AddMany(1, 2, 3, 4, 5, math.MaxUint32)
|
||||||
nDiff3 = nDiff1.GetDifference(nDiff2)
|
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) {
|
func TestNSetFullRange(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user