Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Searcher v
- build :: CaseSensitivity -> [Text] -> Searcher ()
- buildWithValues :: Hashable v => CaseSensitivity -> [(Text, v)] -> Searcher v
- needles :: Searcher v -> [(Text, v)]
- numNeedles :: Searcher v -> Int
- automaton :: Searcher v -> AcMachine v
- caseSensitivity :: Searcher v -> CaseSensitivity
- containsAny :: Searcher () -> Text -> Bool
- setSearcherCaseSensitivity :: CaseSensitivity -> Searcher v -> Searcher v
Documentation
A set of needles with associated values, and an Aho-Corasick automaton to efficiently find those needles.
INVARIANT: searcherAutomaton = Aho.build . searcherNeedles To enforce this invariant, the fields are not exposed from this module. There is a separate constructor function.
The purpose of this wrapper is to have a type that is Hashable and Eq, so we can derive those for types that embed the searcher, whithout requiring the automaton itself to be Hashable or Eq, which would be both wasteful and tedious. Because the automaton is fully determined by the needles and associated values, it is sufficient to implement Eq and Hashable in terms of the needles only.
We also use Hashed to cache the hash of the needles.
Instances
build :: CaseSensitivity -> [Text] -> Searcher () Source #
Builds the Searcher for a list of needles The caller is responsible that the needles are lower case in case the IgnoreCase is used for case sensitivity
buildWithValues :: Hashable v => CaseSensitivity -> [(Text, v)] -> Searcher v Source #
The caller is responsible that the needles are lower case in case the IgnoreCase is used for case sensitivity
numNeedles :: Searcher v -> Int Source #
caseSensitivity :: Searcher v -> CaseSensitivity Source #
containsAny :: Searcher () -> Text -> Bool Source #
Return whether the haystack contains any of the needles. Case sensitivity depends on the properties of the searcher This function is marked noinline as an inlining boundary. Aho.runText is marked inline, so this function will be optimized to report only whether there is a match, and not construct a list of matches. We don't want this function be inline, to make sure that the conditions of the caller don't affect how this function is optimized. There is little to gain from additional inlining. The pragma is not an optimization in itself, rather it is a defence against fragile optimizer decisions.
setSearcherCaseSensitivity :: CaseSensitivity -> Searcher v -> Searcher v Source #
Updates the case sensitivity of the searcher. Does not change the capitilization of the needles. The caller should be certain that if IgnoreCase is passed, the needles are already lower case.