+module K =
+struct
+ type t = int * StateSet.t * StateSet.t
+ let hash (a,b,c) = HASHINT3(a, (b.StateSet.id :> int), (c.StateSet.id :> int))
+ let equal ((a1,b1,c1) as x) ((a2,b2,c2) as y) =
+ x == y || (a1 == a2 && b1 == b2 && c1 == c2)
+end
+
+module CTable = Hashtbl.Make (K)
+
+let ctable = CTable.create 20
+let rgb x =
+ let h = K.hash x in
+ let r = h land 0xff
+ and g = (h lsr 8) land 0xff
+ and b = (h lsr 16) land 0xff
+ in
+ r, g, b
+let color ((a,b,c) as x) =
+ try
+ CTable.find ctable x
+ with
+ Not_found ->
+ let r,g,b = rgb x in
+ let s = "rgb(" ^ (string_of_int r) ^ ","
+ ^ (string_of_int g) ^ ","
+ ^ (string_of_int b) ^ ")"
+ in
+ CTable.add ctable x s;
+ s
+let text_color x =
+ let r,g,b = rgb x in
+ let av = (r + g + b) / 3 in
+ if av > 128 then "rgb(0,0,0)"
+ else "rgb(255,255,255)"