Skip to content

Instantly share code, notes, and snippets.

@drchaos
Created July 31, 2023 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drchaos/b64b048258a756e3b0fd48bddcf78155 to your computer and use it in GitHub Desktop.
Save drchaos/b64b048258a756e3b0fd48bddcf78155 to your computer and use it in GitHub Desktop.
generic Boyer-Moore
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