Created
July 31, 2023 12:44
-
-
Save drchaos/b64b048258a756e3b0fd48bddcf78155 to your computer and use it in GitHub Desktop.
generic Boyer-Moore
This file contains 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
genericMatchUp :: [ByteString] -> ByteString -> Bool | |
genericMatchUp pats = isJust . foldr1 (>=>) . fmap strip pats | |
strip :: ByteString -> ByteString -> Maybe ByteString | |
strip pat | |
| null pat = Just | |
strip pat = breaker | |
where | |
!patLen = length pat | |
searcher = nonOverlappingIndices pat | |
breaker str = case searcher str of | |
[] -> Nothing | |
(i:_) -> Just $ snd $ splitAt (i + patLen) str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment