Skip to content

Commit 2a576ed

Browse files
committed
drop zero-block values in sparse vs dense AND
1 parent f338bf4 commit 2a576ed

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

bitarray/and.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func andSparseWithDenseBitArray(sba *sparseBitArray, other *bitArray) BitArray {
8383

8484
// Run through the sparse array and attempt comparisons wherever
8585
// possible against the dense bit array.
86-
for selfIndex, selfValue := range ba.indices {
86+
for selfIndex, selfValue := range sba.indices {
8787

8888
if selfValue >= uint64(len(other.blocks)) {
8989
// The dense bit array has been exhausted. This is the
@@ -98,6 +98,11 @@ func andSparseWithDenseBitArray(sba *sparseBitArray, other *bitArray) BitArray {
9898
}
9999
ba.blocks[selfIndex] = ba.blocks[selfIndex].and(
100100
other.blocks[selfValue])
101+
102+
if ba.blocks[selfIndex] == 0 {
103+
ba.blocks.deleteAtIndex(int64(selfIndex))
104+
ba.indices.deleteAtIndex(int64(selfIndex))
105+
}
101106
}
102107

103108
return ba

0 commit comments

Comments
 (0)