(* * utils.sml - Useful functionality for testing in general. * Ronald Garcia * $Id: utils.sml,v 1.2 2003/05/02 20:03:41 jewillco Exp $ *) (* Copyright 2003, Trustees of Indiana University * Please see the license in the file ../LICENSE *) structure NumberMap (* : ReadWritePropertyMapSig *) = struct type data_t = int Array.array type key_t = int type value_t = int fun create n = Array.array(n,0) fun get data key = Array.sub(data,key) fun put data key value = Array.update(data,key,value) end structure EdgeMap (* : ReadWritePropertyMapSig *) = struct type data_t = ((int * int) * int) list ref type key_t = (int * int) type value_t = int fun create():data_t = ref([]) exception Doh of int * int fun get data key = case List.find (fn (e,v) => e = key) (!data) of NONE => raise Doh key | SOME (e,v) => v fun put data key value = data := (key,value)::(!data) end structure NumberMatrix (* : BasicMatrix *) = struct type data_t = (int Array.array) Array.array type key_t = int type value_t = int fun create (n,m) = let val data = Array.array(n,(Array.array(1,0))) val i = ref 0 in while !i < n do ( Array.update(data,!i,Array.array(m,0)); i := !i + 1); data end fun get data (key1,key2) = Array.sub(Array.sub(data,key1),key2) fun put data (key1,key2) value = Array.update(Array.sub(data,key1),key2,value) end structure NCompare = struct type data_t = unit type arg_t = int type first_t = int type second_t = int fun create() = () fun go () lhs rhs = lhs < rhs end structure NCombine = struct type data_t = unit type result_t = int type first_t = int type second_t = int fun create() = () fun go () lhs rhs = lhs + rhs end structure IndexMap = struct type data_t = unit type value_t = ALGraph.vertex_t type key_t = ALGraph.vertex_t fun create() = () fun get () b = b end