Commit e6aa84b8 authored by Mike Ledger's avatar Mike Ledger

search support

parent 389f7f19
Pipeline #15051446 passed with stage
in 21 minutes and 57 seconds
This diff is collapsed.
name: radixtree
version: 0.2.0.1
version: 0.3.0.0
homepage: https://gitlab.com/transportengineering/rnd/radixtree
license: BSD3
license-file: LICENSE
......@@ -27,7 +27,23 @@ library
benchmark radixtree-parsing
type: exitcode-stdio-1.0
hs-source-dirs: bench
main-is: RadixTree.hs
main-is: Parsing.hs
ghc-options: -O2
build-depends: base
, radixtree
, text
, QuasiText
, criterion
, attoparsec
, deepseq
, vector
default-language: Haskell2010
benchmark radixtree-search
type: exitcode-stdio-1.0
hs-source-dirs: bench
main-is: Search.hs
ghc-options: -O2
build-depends: base
, radixtree
......
......@@ -16,6 +16,7 @@ module Data.RadixTree
, compressBy
-- * Parsing with radix trees
, parse
, search
) where
import Control.Applicative
import Control.DeepSeq
......@@ -35,7 +36,7 @@ import qualified Data.Text.Internal as TI (Text (..), text)
import Data.Vector (Vector)
import qualified Data.Vector as V
import Lens.Micro
import Text.Parser.Char (CharParsing (text))
import Text.Parser.Char (CharParsing (anyChar, text))
import Text.Parser.Combinators (Parsing (try))
--------------------------------------------------------------------------------
......@@ -176,7 +177,19 @@ makeStore ''RadixTree
--------------------------------------------------------------------------------
-- Parsers from 'RadixTree's
{-# INLINE search #-}
-- | Find all occurences of the terms in a 'RadixTree' from this point on. This
-- will consume the entire remaining input. Can lazily produce results.
search :: (Monad m, CharParsing m) => RadixTree -> m [Text]
search r = go
where
go =
(parse r >>= \x -> (x:) <$> go) <|>
(anyChar >> go) <|>
return []
{-# INLINE parse #-}
-- | Parse from a 'RadixTree'
parse :: CharParsing m => RadixTree -> m Text
parse = go
where
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment