| 1 |
(* |
| 2 |
* Print a graph |
| 3 |
* |
| 4 |
* -- Allen |
| 5 |
*) |
| 6 |
|
| 7 |
signature PRINT_GRAPH = |
| 8 |
sig |
| 9 |
|
| 10 |
val toString : ('n,'e,'g) Graph.graph -> string |
| 11 |
|
| 12 |
end |
| 13 |
|
| 14 |
structure PrintGraph : PRINT_GRAPH = |
| 15 |
struct |
| 16 |
|
| 17 |
structure G = Graph |
| 18 |
|
| 19 |
fun toString (G.GRAPH G) = |
| 20 |
let fun showEdges es = |
| 21 |
String.concat( |
| 22 |
map (fn (i,j,_) => Int.toString i^" -> "^Int.toString j^"\n") es) |
| 23 |
fun showNodes ns = |
| 24 |
String.concat(map (fn n => Int.toString n^" ") ns)^"\n" |
| 25 |
in |
| 26 |
#name G ^ "\n" ^ |
| 27 |
"nodes: "^showNodes(map #1 (#nodes G ()))^ |
| 28 |
"edges:\n"^showEdges(#edges G ())^ |
| 29 |
"entry edges:\n"^ |
| 30 |
showEdges(List.concat(map (#entry_edges G o #1) (#nodes G ())))^ |
| 31 |
"exit edges:\n"^ |
| 32 |
showEdges(List.concat(map (#exit_edges G o #1) (#nodes G ())))^ |
| 33 |
"entries: "^showNodes(#entries G ())^ |
| 34 |
"exits: "^showNodes(#exits G ()) |
| 35 |
end |
| 36 |
end |
| 37 |
|