# printgraph.pkg
# Print a graph
# -- Allen Leung
# Compiled by:
#
src/lib/graph/graphs.lib### "The wise speak only of what they know."
###
### -- Gandalf
stipulate
package odg = oop_digraph; # oop_digraph is from
src/lib/graph/oop-digraph.pkgherein
api Print_Graph {
#
to_string: odg::Digraph(N,E,G) -> String; # Here N,E,G stand stead for the types of client-package-supplied records associated with (respectively) nodes, edges and graphs.
};
end;
stipulate
package odg = oop_digraph; # oop_digraph is from
src/lib/graph/oop-digraph.pkgherein
package print_graph
: (weak) Print_Graph # Print_Graph is from
src/lib/graph/printgraph.pkg {
fun to_string (odg::DIGRAPH graph)
=
{ fun show_edges es
=
string::cat (map' es (\\ (i, j, _) = int::to_string i + " -> " + int::to_string j + "\n"));
fun show_nodes ns
=
string::cat (map' ns (\\ n = int::to_string n + " ")) + "\n";
graph.name + "\n" +
"nodes: " + show_nodes (map #1 (graph.nodes ())) +
"edges:\n" + show_edges (graph.edges ()) +
"entry edges:\n" +
show_edges (list::cat (map (graph.entry_edges o #1) (graph.nodes ()))) +
"exit edges:\n" +
show_edges (list::cat (map (graph.exit_edges o #1) (graph.nodes ()))) +
"entries: " + show_nodes (graph.entries ()) +
"exits: " + show_nodes (graph.exits ());
};
};
end;