Last active
January 17, 2020 13:25
-
-
Save linasm/f7a3a0c21d1c34e6076d591ff665994b to your computer and use it in GitHub Desktop.
Bit mask precomputing for Shifting Bit Mask string search algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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