From 712b113c9a9df516780e81c025d6a70afdb2812f Mon Sep 17 00:00:00 2001 From: krasimir Date: Thu, 15 Jul 2010 14:01:51 +0000 Subject: fix the algorithm for items cutting in the partial parser --- src/compiler/GF/Data/TrieMap.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/compiler') diff --git a/src/compiler/GF/Data/TrieMap.hs b/src/compiler/GF/Data/TrieMap.hs index a15c780ab..5392b6c0d 100644 --- a/src/compiler/GF/Data/TrieMap.hs +++ b/src/compiler/GF/Data/TrieMap.hs @@ -7,6 +7,7 @@ module GF.Data.TrieMap , lookup , null + , compose , decompose , insertWith @@ -15,6 +16,7 @@ module GF.Data.TrieMap , unions, unionsWith , elems + , toList ) where import Prelude hiding (lookup, null) @@ -36,6 +38,9 @@ null :: TrieMap k v -> Bool null (Tr Nothing m) = Map.null m null _ = False +compose :: Maybe v -> Map.Map k (TrieMap k v) -> TrieMap k v +compose mb_v m = Tr mb_v m + decompose :: TrieMap k v -> (Maybe v, Map.Map k (TrieMap k v)) decompose (Tr mb_v m) = (mb_v,m) @@ -70,3 +75,8 @@ elems :: TrieMap k v -> [v] elems tr = collect tr [] where collect (Tr mb_v m) xs = maybe id (:) mb_v (Map.fold collect xs m) + +toList :: TrieMap k v -> [([k],v)] +toList tr = collect [] tr [] + where + collect ks (Tr mb_v m) xs = maybe id (\v -> (:) (ks,v)) mb_v (Map.foldWithKey (\k -> collect (k:ks)) xs m) -- cgit v1.2.3