File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 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 {
7171}
7272
7373func andSparseWithDenseBitArray (sba * sparseBitArray , other * bitArray ) BitArray {
74+ if other .IsEmpty () {
75+ return newSparseBitArray ()
76+ }
77+
7478 // Use a duplicate of the sparse array to store the results of the
7579 // bitwise and. More memory-efficient than allocating a new dense bit
7680 // array.
@@ -89,15 +93,26 @@ func andSparseWithDenseBitArray(sba *sparseBitArray, other *bitArray) BitArray {
8993 // The dense bit array has been exhausted. This is the
9094 // annoying case because we have to trim the sparse
9195 // 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 ]
9498
9599 // once this is done, there are no more comparisons.
96100 // We're ready to return
97101 break
98102 }
99103 ba .blocks [selfIndex ] = ba .blocks [selfIndex ].and (
100104 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+ }
101116 }
102117
103118 return ba
You can’t perform that action at this time.
0 commit comments