Commit 2a778d79 authored by Mike Ledger's avatar Mike Ledger

nix tweaks

parent 3bb8faea
Pipeline #43590764 failed with stage
in 1 minute and 7 seconds
use_nix -A env
import ../nix/haskellPackage.nix {
name = "radixtree";
path = ./.;
}
/nix/store/ffg7rspgw6yzd1nv7g87fk6b633al01l-radixtree-0.5.0.0
\ No newline at end of file
......@@ -14,10 +14,13 @@ module Data.RadixTree
, RadixNode (..)
, CompressedRadixTree
-- * Construction
, fromFoldable_
, fromFoldable
, compressBy
-- * Parsing with radix trees
, RadixParsing (..)
, parse_
, lookup_
, search
) where
import Control.Applicative
......@@ -26,7 +29,6 @@ import Data.Data (Data, Typeable)
import Data.Foldable (asum, foldr', toList)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as M
import Data.Monoid
import Data.Sequence (Seq)
import qualified Data.Sequence as Seq
import Data.Store ()
......@@ -112,7 +114,7 @@ compress = go . makeCompressable
data RadixNode a = RadixNode {-# UNPACK #-} !Text !(RadixTree a)
deriving (Eq, Show, Typeable, Data)
-- | A radixtree. Construct with 'fromFoldable', and use with 'parse'.
-- | A radixtree. Construct with 'fromFoldable_, and use with 'parse'.
data RadixTree a
= -- | Can terminate a parser successfully, returning the 'Text' value given.
RadixAccept
......@@ -218,6 +220,12 @@ compressBy full@(TI.Text arr _ _) rt =
recompressT (RadixSkip v) = CompressedRadixSkip <$> V.mapM recompressN v
recompressT (RadixAccept t v a) = CompressedRadixAccept <$> magic t <*> V.mapM recompressN v <*> pure a
-- | *Slow*. Same as 'fromFoldable', but you do not need to supply pairs of text
-- and values; they will default to '()'.
fromFoldable_ :: Foldable f => f Text -> RadixTree ()
fromFoldable_ =
fromTrie . foldr' (\t -> insert t t ()) (Trie (Skip M.empty))
-- | *Slow*
fromFoldable :: Foldable f => f (Text, a) -> RadixTree a
fromFoldable =
......@@ -248,6 +256,14 @@ search r = go
(anyChar >> go) <|>
return []
{-# INLINE parse_ #-}
parse_ :: (RadixParsing r, CharParsing m) => r a -> m Text
parse_ = Data.RadixTree.parse const
{-# INLINE lookup_ #-}
lookup_ :: RadixParsing r => r a -> Text -> Maybe Text
lookup_ r t = fst <$> Data.RadixTree.lookup r t
instance RadixParsing RadixTree where
{-# INLINE parse #-}
-- | Parse from a 'RadixTree'
......
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# http://docs.haskellstack.org/en/stable/yaml_configuration/
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
# resolver: ghcjs-0.1.0_ghc-7.10.2
# resolver:
# name: custom-snapshot
# location: "./custom-snapshot.yaml"
resolver: lts-11.0
# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# - location:
# git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# extra-dep: true
# subdirs:
# - auto-update
# - wai
#
# A package marked 'extra-dep: true' will only be built if demanded by a
# non-dependency (i.e. a user package), and its test suites and benchmarks
# will not be run. This is useful for tweaking upstream packages.
packages:
- '.'
# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
extra-deps: []
# Override default flag values for local packages and extra-deps
flags: {}
# Extra package databases containing global packages
extra-package-dbs: []
# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=1.2"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
......@@ -25,9 +25,9 @@ naiiveSameAsRadix doCompress =
forAll $ \(mkAlternatives -> alternatives) ->
let
rparse
| doCompress = R.parse $! R.fromFoldable alternatives
| otherwise = case R.compressBy (T.concat alternatives) (R.fromFoldable alternatives) of
Just crt -> R.parse $! crt
| doCompress = R.parse_ $! R.fromFoldable_ alternatives
| otherwise = case R.compressBy (T.concat alternatives) (R.fromFoldable_ alternatives) of
Just crt -> R.parse_ $! crt
Nothing -> error "could not compress radixtree!"
in forAll $ \(textS :: NonEmpty Char) ->
let text = T.pack (coerce textS)
......@@ -38,11 +38,11 @@ lookupSameishAsParse :: Property IO
lookupSameishAsParse =
forAll $ \alternatives ->
let
!rt = R.fromFoldable (mkAlternatives alternatives)
!p = R.parse rt <* endOfInput
!rt = R.fromFoldable_ (mkAlternatives alternatives)
!p = R.parse_ rt <* endOfInput
in forAll $ \(textS :: NonEmpty Char) ->
let text = T.pack (coerce textS)
in case (parseOnly p text, R.lookup rt text) of
in case (parseOnly p text, R.lookup_ rt text) of
(Right x1, Just x2) -> x1 == x2
(Left _ , Nothing) -> True
_ -> False
......
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