From ca737457a4df4fbca25fe1c94c358a5b3b8da173 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Mon, 29 Aug 2022 15:58:16 +0200 Subject: graph: Use node id when querying incoming/outcoming nodes/edges --- src/lib/Codec/Pesto/Graph.lhs | 8 ++++---- src/lib/Codec/Pesto/Lint.lhs | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/lib') diff --git a/src/lib/Codec/Pesto/Graph.lhs b/src/lib/Codec/Pesto/Graph.lhs index 27dd967..a238012 100644 --- a/src/lib/Codec/Pesto/Graph.lhs +++ b/src/lib/Codec/Pesto/Graph.lhs @@ -266,11 +266,11 @@ Find graph’s root node(s), that is a node without outgoing edges: Get all nodes with edges pointing towards nodeid -> incomingEdges edges (nodeid, _) = filter ((==) nodeid . snd) edges -> incomingNodes nodes edges n = map ((!!) nodes . fst) $ incomingEdges edges n +> incomingEdges edges nodeid = filter ((==) nodeid . snd) edges +> incomingNodes nodes edges nodeid = map ((!!) nodes . fst) $ incomingEdges edges nodeid -> outgoingEdges edges (nodeid, _) = filter ((==) nodeid . fst) edges -> outgoingNodes nodes edges n = map ((!!) nodes . snd) $ outgoingEdges edges n +> outgoingEdges edges nodeid = filter ((==) nodeid . fst) edges +> outgoingNodes nodes edges nodeid = map ((!!) nodes . snd) $ outgoingEdges edges nodeid > test = ["graph" ~: testGraph, "ref" ~: testRef, "extract" ~: testExtract] diff --git a/src/lib/Codec/Pesto/Lint.lhs b/src/lib/Codec/Pesto/Lint.lhs index 480d161..affea98 100644 --- a/src/lib/Codec/Pesto/Lint.lhs +++ b/src/lib/Codec/Pesto/Lint.lhs @@ -71,10 +71,10 @@ The graph’s root node must be a result. It contains yield (amount and unit) an title (object) of the recipe. > extractMetadata nodes edges = case walkRoot nodes edges of -> [n@(i, Result q@(Quantity _ _ title))] -> +> [(i, Result q@(Quantity _ _ title))] -> > Just $ (i, ("title", MetaStr title)) > :(i, ("yield", MetaQty q)) -> :foldl f [] (incomingNodes nodes edges n) +> :foldl f [] (incomingNodes nodes edges i) > _ -> Nothing > where @@ -196,7 +196,7 @@ minutes). More time annotations improve the software’s scheduling capabilities > timeAnnotatesAction nodes edges = foldl f [] nodes > where -> f xs n@(nodeid, Tool q) | isTime q && (not . allActions) (outgoingEdges edges n) = LintResult TimeAnnotatesAction [nodeid]:xs +> f xs (nodeid, Tool q) | isTime q && (not . allActions) (outgoingEdges edges nodeid) = LintResult TimeAnnotatesAction [nodeid]:xs > f xs _ = xs > toNodelist = (!!) nodes . snd > allActions = all (isAction . snd . toNodelist) @@ -273,7 +273,7 @@ all results and alternatives are referenced at some point. > referencesResolved nodes edges = foldl f [] nodes > where -> f xs n@(nodeid, Reference _) | null (incomingEdges edges n) = +> f xs (nodeid, Reference _) | null (incomingEdges edges nodeid) = > LintResult UndefinedReference [nodeid]:xs > f xs _ = xs @@ -311,7 +311,7 @@ only occur at the beginning of a recipe. > resultNonempty nodes edges = foldl f [] nodes > where -> f xs n@(nodeid, Result _) | null (incomingEdges edges n) = +> f xs (nodeid, Result _) | null (incomingEdges edges nodeid) = > LintResult TooFewChildren [nodeid]:xs > f xs _ = xs @@ -326,7 +326,7 @@ make the alternative pointless. > twoAlternatives nodes edges = foldl f [] nodes > where -> f xs n@(nodeid, Alternative _) | length (incomingEdges edges n) < 2 = +> f xs (nodeid, Alternative _) | length (incomingEdges edges nodeid) < 2 = > LintResult TooFewChildren [nodeid]:xs > f xs _ = xs -- cgit v1.2.3