definition:
|
reachableGraph :: Graph -> [NodeID] -> Graph
reachableGraph (Graph nodes mx rt) initnids =
let rnodes = reachableNodes initnids
in Graph (filter ((`elem` rnodes) . fst) nodes) mx rt
where
reachableNodes nids =
let newts = nub . filter (`notElem` nids) . concatMap targets $ nids
in if null newts then nids else reachableNodes (newts ++ nids)
where
targets ni =
maybe (error $ "Node with id `" ++ show ni ++ "` not found!")
(\nd -> case nd of FuncNode _ ns -> ns
ConsNode _ ns -> ns
PartNode _ _ ns -> ns
ChoiceNode _ n1 n2 -> [n1,n2]
FreeNode -> [])
(lookup ni nodes)
|
demand:
|
argument 1
|
deterministic:
|
deterministic operation
|
documentation:
|
-- "Garbage collection" on a graph: remove all nodes (and their outgoing edges)
-- which are not reachable from a given list of nodes.
|
failfree:
|
(_, _)
|
indeterministic:
|
referentially transparent operation
|
infix:
|
no fixity defined
|
iotype:
|
{({Graph},_) |-> {Graph}}
|
name:
|
reachableGraph
|
precedence:
|
no precedence defined
|
result-values:
|
{Graph}
|
signature:
|
Graph -> [Prelude.Int] -> Graph
|
solution-complete:
|
operation might suspend on free variables
|
terminating:
|
possibly non-terminating
|
totally-defined:
|
possibly non-reducible on same data term
|