summaryrefslogtreecommitdiff
path: root/src/GF/Speech/Graph.hs
diff options
context:
space:
mode:
authorbringert <bringert@cs.chalmers.se>2006-12-15 16:09:58 +0000
committerbringert <bringert@cs.chalmers.se>2006-12-15 16:09:58 +0000
commit215bf61115a1b78c6466830c89574091459bebdb (patch)
tree0c54ecb6ae408f316fea227ca6e202930fab5929 /src/GF/Speech/Graph.hs
parent1e1401472fdc55ba8f208baa7f07e2a4a3cb906c (diff)
Towards smaller SRGs when lots of variants are used.
Diffstat (limited to 'src/GF/Speech/Graph.hs')
-rw-r--r--src/GF/Speech/Graph.hs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/GF/Speech/Graph.hs b/src/GF/Speech/Graph.hs
index c23c5e384..1a0ebe0c0 100644
--- a/src/GF/Speech/Graph.hs
+++ b/src/GF/Speech/Graph.hs
@@ -14,7 +14,8 @@
module GF.Speech.Graph ( Graph(..), Node, Edge, NodeInfo
, newGraph, nodes, edges
, nmap, emap, newNode, newNodes, newEdge, newEdges
- , removeNodes
+ , insertEdgeWith
+ , removeNode, removeNodes
, nodeInfo
, getIncoming, getOutgoing, getNodeLabel
, inDegree, outDegree
@@ -82,6 +83,17 @@ newEdges es g = foldl' (flip newEdge) g es
-- lazy version:
-- newEdges es' (Graph c ns es) = Graph c ns (es'++es)
+insertEdgeWith :: Eq n =>
+ (b -> b -> b) -> Edge n b -> Graph n a b -> Graph n a b
+insertEdgeWith f e@(x,y,l) (Graph c ns es) = Graph c ns (h es)
+ where h [] = [e]
+ h (e'@(x',y',l'):es') | x' == x && y' == y = (x',y', f l l'):es'
+ | otherwise = e':h es'
+
+-- | Remove a node and all edges to and from that node.
+removeNode :: Ord n => n -> Graph n a b -> Graph n a b
+removeNode n = removeNodes (Set.singleton n)
+
-- | Remove a set of nodes and all edges to and from those nodes.
removeNodes :: Ord n => Set n -> Graph n a b -> Graph n a b
removeNodes xs (Graph c ns es) = Graph c ns' es'