packages feed

pred-trie 0.0.6 → 0.0.6.1

raw patch · 3 files changed

+32/−7 lines, 3 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Data.Trie.Pred.Unified: getFirst :: [Maybe a] -> Maybe a
+ Data.Trie.Pred.Unified: lookupNearestParent :: (Eq t) => [t] -> RUPTrie t x -> Maybe x
+ Data.Trie.Pred.Unified.Tail: lookupNearestParent :: Eq t => NonEmpty t -> UPTrie t x -> Maybe x

Files

pred-trie.cabal view
@@ -1,5 +1,5 @@ Name:                   pred-trie-Version:                0.0.6+Version:                0.0.6.1 Author:                 Athan Clark <athan.clark@gmail.com> Maintainer:             Athan Clark <athan.clark@gmail.com> License:                BSD3
src/Data/Trie/Pred/Unified.hs view
@@ -2,7 +2,7 @@  import Data.Trie.Pred.Unified.Tail import qualified Data.Trie.Pred.Unified.Tail as NU-import Data.Monoid+import Data.Monoid hiding (getFirst) import qualified Data.List.NonEmpty as NE  @@ -24,12 +24,15 @@ lookup :: (Eq t) => [t] -> RUPTrie t x -> Maybe x lookup [] (Rooted mx _) = mx lookup ts (Rooted _ xs) = getFirst $ map (NU.lookup $ NE.fromList ts) xs-  where-    getFirst :: [Maybe a] -> Maybe a-    getFirst [] = Nothing-    getFirst (Nothing:xs) = getFirst xs-    getFirst (Just x :xs) = Just x +lookupNearestParent :: (Eq t) => [t] -> RUPTrie t x -> Maybe x+lookupNearestParent [] (Rooted mx _) = mx+lookupNearestParent ts (Rooted mx xs) = getFirst $ map (NU.lookupNearestParent $ NE.fromList ts) xs++getFirst :: [Maybe a] -> Maybe a+getFirst [] = Nothing+getFirst (Nothing:xs) = getFirst xs+getFirst (Just x :xs) = Just x  litSingleton :: [t] -> x -> RUPTrie t x litSingleton [] x = Rooted (Just x) []
src/Data/Trie/Pred/Unified/Tail.hs view
@@ -5,6 +5,7 @@ module Data.Trie.Pred.Unified.Tail   ( UPTrie (..)   , lookup+  , lookupNearestParent   , merge   , areDisjoint   , litSingletonTail@@ -64,6 +65,27 @@     \r -> case ts of       [] -> ($ r) <$> mrx       _  -> ($ r) <$> (getFirst $ map (lookup $ NE.fromList ts) xrs)+++lookupNearestParent :: Eq t => NonEmpty t -> UPTrie t x -> Maybe x+lookupNearestParent tss@(t:|ts) trie@(UMore t' mx xs) = case lookup tss trie of+  Nothing -> if t == t'+               then case ts of+                      [] -> mx -- redundant; should have successful lookup+                      _  -> case getFirst $ map (lookupNearestParent $ NE.fromList ts) xs of+                              Nothing -> mx+                              justr   -> justr+               else Nothing+  justr -> justr+lookupNearestParent tss@(t:|ts) trie@(UPred t' p mrx xrs) = case lookup tss trie of+  Nothing -> p t >>=+               \r -> case ts of+                        [] -> ($ r) <$> mrx -- redundant; should have successful lookup+                        _  -> case getFirst $ map (lookupNearestParent $ NE.fromList ts) xrs of+                                Nothing -> ($ r) <$> mrx+                                justr   -> ($ r) <$> justr+  justr -> justr+   getFirst :: [Maybe a] -> Maybe a