Some performance improvements in the FA generation.

This commit is contained in:
bringert
2005-12-22 23:16:15 +00:00
parent cb9769788e
commit 5c12a73dae
6 changed files with 92 additions and 53 deletions

View File

@@ -13,7 +13,7 @@
-----------------------------------------------------------------------------
module GF.Speech.Graph ( Graph(..), Node, Edge, Incoming, Outgoing
, newGraph, nodes, edges
, nmap, emap, newNode, newEdge, newEdges
, nmap, emap, newNode, newNodes, newEdge, newEdges
, incoming, outgoing, getOutgoing
, getFrom, getTo, getLabel
, reverseGraph, renameNodes
@@ -52,6 +52,11 @@ emap f (Graph c ns es) = Graph c ns [(x,y,f l) | (x,y,l) <- es]
newNode :: a -> Graph n a b -> (Graph n a b,n)
newNode l (Graph (c:cs) ns es) = (Graph cs ((c,l):ns) es, c)
newNodes :: [a] -> Graph n a b -> (Graph n a b,[Node n a])
newNodes ls (Graph cs ns es) = (Graph cs' (ns'++ns) es, ns')
where (xs,cs') = splitAt (length ls) cs
ns' = zip xs ls
newEdge :: Edge n b -> Graph n a b -> Graph n a b
newEdge e (Graph c ns es) = Graph c ns (e:es)