Open sjakobi opened 2 years ago
unionArrayBy and intersectionArrayBy currently use countTrailingZeros to detect set bits in bitmaps.
unionArrayBy
intersectionArrayBy
countTrailingZeros
Alternatively, lowest set bits can be isolated like this:
isolateLowestSetBit :: Word -> Word isolateLowestSetBit x = x .&. negate x
(Explanation in https://stackoverflow.com/a/12250963/1013393)
The latter technique is already being used in submapBitmapIndexed to create the initial bit mask.
submapBitmapIndexed
It would be good to consistently use only one technique, ideally by refactoring this pattern into a proper function like isolateLowestSetBit.
isolateLowestSetBit
clearLowestSetBit x = x .&. (x - 1) might be useful to simplify clearing the lowest set bit for the next iteration.
clearLowestSetBit x = x .&. (x - 1)
unionArrayBy
andintersectionArrayBy
currently usecountTrailingZeros
to detect set bits in bitmaps.Alternatively, lowest set bits can be isolated like this:
(Explanation in https://stackoverflow.com/a/12250963/1013393)
The latter technique is already being used in
submapBitmapIndexed
to create the initial bit mask.It would be good to consistently use only one technique, ideally by refactoring this pattern into a proper function like
isolateLowestSetBit
.