## graph-snapshot-g.pkg
#
# This combinator allows you to get a cached copy of a graph.
#
# -- Allen Leung
# Compiled by:
#
src/lib/graph/graphs.lib# See also:
# src/lib/compiler/back/low/doc/latex/graphs.tex
stipulate
package odg = oop_digraph; # oop_digraph is from
src/lib/graph/oop-digraph.pkgherein
api Graph_Snapshot {
#
snapshot: odg::Digraph(N,E,G) # Here N,E,G stand stead for the types of client-package-supplied records associated with (respectively) nodes, edges and graphs.
->
{ picture: odg::Digraph(N,E,G),
button: Void -> Void
};
};
end;
# This is a naive implementation.
#
stipulate
package odg = oop_digraph; # oop_digraph is from
src/lib/graph/oop-digraph.pkgherein
generic package graph_snapshot_g (
#
meg: Make_Empty_Graph # Make_Empty_Graph is from
src/lib/graph/make-empty-graph.api )
: (weak) Graph_Snapshot # Graph_Snapshot is from
src/lib/graph/graph-snapshot-g.pkg {
fun snapshot (odg::DIGRAPH graph)
=
{ picture, button }
where
my picture as odg::DIGRAPH graph'
=
meg::make_empty_graph
{
graph_name => graph.name, # Arbitrary client name for graph, for human-display purposes.
graph_info => graph.graph_info, # Arbitrary client value to associate with graph.
expected_node_count => graph.capacity () # Hint for initial sizing of internal graph vectors. This is not a hard limit.
};
fun clear ()
=
graph'.forall_nodes (\\ (n, _) => graph'.remove_node n; end );
fun copy ()
=
{ graph.forall_nodes graph'.add_node;
graph.forall_edges graph'.add_edge;
graph'.set_entries (graph.entries ());
graph'.set_exits (graph.exits ());
};
fun button ()
=
{ clear ();
copy ();
};
copy();
end;
};
end;