Skip to content

Instantly share code, notes, and snippets.

@linasm
Last active January 17, 2020 13:25
Show Gist options
  • Save linasm/f7a3a0c21d1c34e6076d591ff665994b to your computer and use it in GitHub Desktop.
Save linasm/f7a3a0c21d1c34e6076d591ff665994b to your computer and use it in GitHub Desktop.
Bit mask precomputing for Shifting Bit Mask string search algorithm
def computeBitMasks(needle: Array[Byte]): Array[Long] = {
require(needle.length <= 64, "Maximum supported search pattern length is 64.")
val bitMasks = Array.ofDim[Long](256)
var bit = 1L
for (c <- needle) {
bitMasks(toUnsignedInt(c)) |= bit
bit <<= 1
}
bitMasks
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment