Commit a9f5a585 authored by Mike Ledger's avatar Mike Ledger

add keys

parent f6777c2e
Pipeline #50132961 failed with stage
in 19 seconds
......@@ -238,6 +238,7 @@ makeStore ''RadixTree
-- Parsers from 'RadixTree's
class RadixParsing radixtree where
keys :: radixtree a -> [(Text, a)]
parse :: CharParsing m => (Text -> a -> r) -> radixtree a -> m r
lookup :: radixtree a -> Text -> Maybe (Text, a)
......@@ -265,6 +266,12 @@ lookup_ :: RadixParsing r => r a -> Text -> Maybe Text
lookup_ r t = fst <$> Data.RadixTree.lookup r t
instance RadixParsing RadixTree where
{-# INLINE keys #-}
keys = go []
where
go nil (RadixAccept l xs a) = (l,a) : V.foldr (\(RadixNode _ x) xs' -> go xs' x) nil xs
go nil (RadixSkip xs) = V.foldr (\(RadixNode _ x) xs' -> go xs' x) nil xs
{-# INLINE parse #-}
-- | Parse from a 'RadixTree'
parse :: CharParsing m => (Text -> a -> r) -> RadixTree a -> m r
......@@ -304,6 +311,17 @@ instance RadixParsing RadixTree where
| otherwise = Nothing
instance RadixParsing CompressedRadixTree where
{-# INLINE keys #-}
keys (CompressedRadixTree arr crt) = go [] crt
where
fromSlice (TextSlice offs len) = TI.text arr offs len
go nil (CompressedRadixAccept l xs a) =
(fromSlice l, a) : V.foldr (\(CompressedRadixNode _ x) xs' -> go xs' x) nil xs
go nil (CompressedRadixSkip xs) =
V.foldr (\(CompressedRadixNode _ x) xs' -> go xs' x) nil xs
{-# INLINE parse #-}
-- | Parse from a 'RadixTree'
parse :: CharParsing m => (Text -> a -> r) -> CompressedRadixTree a -> m r
......
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