summaryrefslogtreecommitdiff
path: root/src/GF/Data/Trie.hs
diff options
context:
space:
mode:
authormarkus <unknown>2003-11-11 11:59:21 +0000
committermarkus <unknown>2003-11-11 11:59:21 +0000
commit9b47b4aa128a5cbee74aa99e5494a0b76890ec4a (patch)
tree0a870fa527b8fea0c98d6906d90ebac72872504a /src/GF/Data/Trie.hs
parentb5685411125cb5cafe86c7761b0632b83c25f449 (diff)
Added a collapse function to Trie
Diffstat (limited to 'src/GF/Data/Trie.hs')
-rw-r--r--src/GF/Data/Trie.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/GF/Data/Trie.hs b/src/GF/Data/Trie.hs
index 0a0a4472b..724df0761 100644
--- a/src/GF/Data/Trie.hs
+++ b/src/GF/Data/Trie.hs
@@ -10,6 +10,7 @@
module Trie (
tcompile,
+ collapse,
Trie,
trieLookup,
decompose,
@@ -35,6 +36,14 @@ optimize :: TrieT -> Trie
optimize (TrieT (xs,res)) = Trie ([(c,optimize t) | (c,t) <- xs] |->+ empty,
res)
+collapse :: Trie -> [(String,[(Attr,String)])]
+collapse trie = collapse' trie []
+ where collapse' (Trie (map,(x:xs))) s = if (isEmpty map) then [(reverse s,(x:xs))]
+ else (reverse s,(x:xs)):
+ concat [ collapse' trie (c:s) | (c,trie) <- flatten map]
+ collapse' (Trie (map,[])) s
+ = concat [ collapse' trie (c:s) | (c,trie) <- flatten map]
+
tcompile :: [(String,[(Attr,String)])] -> Trie
tcompile xs = optimize $ build xs emptyTrie