File: snap-shot.sml

package info (click to toggle)
mlton 20210117%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,464 kB
  • sloc: ansic: 27,682; sh: 4,455; asm: 3,569; lisp: 2,879; makefile: 2,347; perl: 1,169; python: 191; pascal: 68; javascript: 7
file content (36 lines) | stat: -rw-r--r-- 884 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(*
 * This combinator allows you to get a cached copy of a graph.
 *
 * -- Allen
 *)

signature GRAPH_SNAPSHOT =
sig
   val snapshot : ('n,'e,'g) Graph.graph -> 
        { picture : ('n,'e,'g) Graph.graph,
          button : unit -> unit
        }
end

(*
 * This is a naive implementation.
 *)
functor GraphSnapShot(GI : GRAPH_IMPLEMENTATION) : GRAPH_SNAPSHOT =
struct

   structure G = Graph
   fun snapshot (G.GRAPH G) =
   let val pict as G.GRAPH G' = GI.graph(#name G,#graph_info G,#capacity G ())
       fun clear() = #forall_nodes G' (fn (n,_) => #remove_node G' n)
       fun copy() =
          (#forall_nodes G (#add_node G');
           #forall_edges G (#add_edge G');
           #set_entries G' (#entries G ());
           #set_exits G' (#exits G ())
          )
       fun button() = (clear(); copy())
   in  copy();
       { picture = pict, button = button }
   end
end