File tree 1 file changed +17
-2
lines changed
1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,10 @@ func andSparseWithSparseBitArray(sba, other *sparseBitArray) BitArray {
71
71
}
72
72
73
73
func andSparseWithDenseBitArray (sba * sparseBitArray , other * bitArray ) BitArray {
74
+ if other .IsEmpty () {
75
+ return newSparseBitArray ()
76
+ }
77
+
74
78
// Use a duplicate of the sparse array to store the results of the
75
79
// bitwise and. More memory-efficient than allocating a new dense bit
76
80
// array.
@@ -89,15 +93,26 @@ func andSparseWithDenseBitArray(sba *sparseBitArray, other *bitArray) BitArray {
89
93
// The dense bit array has been exhausted. This is the
90
94
// annoying case because we have to trim the sparse
91
95
// array to the size of the dense array.
92
- ba .blocks = ba .blocks [:selfIndex ]
93
- ba .indices = ba .indices [:selfIndex ]
96
+ ba .blocks = ba .blocks [:selfIndex - 1 ]
97
+ ba .indices = ba .indices [:selfIndex - 1 ]
94
98
95
99
// once this is done, there are no more comparisons.
96
100
// We're ready to return
97
101
break
98
102
}
99
103
ba .blocks [selfIndex ] = ba .blocks [selfIndex ].and (
100
104
other .blocks [selfValue ])
105
+
106
+ }
107
+
108
+ // Ensure any zero'd blocks in the resulting sparse
109
+ // array are deleted
110
+ for i := 0 ; i < len (ba .blocks ); i ++ {
111
+ if ba .blocks [i ] == 0 {
112
+ ba .blocks .deleteAtIndex (int64 (i ))
113
+ ba .indices .deleteAtIndex (int64 (i ))
114
+ i --
115
+ }
101
116
}
102
117
103
118
return ba
You can’t perform that action at this time.
0 commit comments