| 1 |
(* |
| 2 |
* This combinator allows you to get a cached copy of a graph. |
| 3 |
* |
| 4 |
* -- Allen |
| 5 |
*) |
| 6 |
|
| 7 |
signature GRAPH_SNAPSHOT = |
| 8 |
sig |
| 9 |
val snapshot : ('n,'e,'g) Graph.graph -> |
| 10 |
{ picture : ('n,'e,'g) Graph.graph, |
| 11 |
button : unit -> unit |
| 12 |
} |
| 13 |
end |
| 14 |
|
| 15 |
(* |
| 16 |
* This is a naive implementation. |
| 17 |
*) |
| 18 |
functor GraphSnapShot(GI : GRAPH_IMPLEMENTATION) : GRAPH_SNAPSHOT = |
| 19 |
struct |
| 20 |
|
| 21 |
structure G = Graph |
| 22 |
fun snapshot (G.GRAPH G) = |
| 23 |
let val pict as G.GRAPH G' = GI.graph(#name G,#graph_info G,#capacity G ()) |
| 24 |
fun clear() = #forall_nodes G' (fn (n,_) => #remove_node G' n) |
| 25 |
fun copy() = |
| 26 |
(#forall_nodes G (#add_node G'); |
| 27 |
#forall_edges G (#add_edge G'); |
| 28 |
#set_entries G' (#entries G ()); |
| 29 |
#set_exits G' (#exits G ()) |
| 30 |
) |
| 31 |
fun button() = (clear(); copy()) |
| 32 |
in copy(); |
| 33 |
{ picture = pict, button = button } |
| 34 |
end |
| 35 |
end |
| 36 |
|