(* * colormap.sml - Color map signature plus a colormap generator * Ronald Garcia * $Id: color_map.sml,v 1.3 2003/08/08 22:15:34 garcia Exp $ *) use "property_map.sml"; use "graph.sml"; signature ColorMapSig = sig (* include ReadWritePropertyMapSig *) type data_t eqtype color_t type key_t val black : unit -> color_t val gray : unit -> color_t val white : unit -> color_t val get : data_t -> key_t -> color_t val put : data_t -> key_t -> color_t -> unit end functor MakeColorMap( structure VIMap : ReadablePropertyMapSig where type value_t = int; structure Graph : VertexListGraphSig) = struct datatype color_t = White | Gray | Black type data_t = VIMap.data_t * color_t Array.array type key_t = Graph.vertex_t fun black() = Black fun gray() = Gray fun white() = White fun create(vimap,graph) = (vimap,Array.array(List.length(Graph.vertices(graph)),White)) fun get (vimap,cmap) key = Array.sub(cmap,(VIMap.get vimap key)) fun put (vimap,cmap) key color = Array.update(cmap,(VIMap.get vimap key),color) end