struct
(** This an implementation of an almost bijection: 'a -> int
It compares values structurally (with (=) ), and assigns an
integer, unique over the execution of the program.
It replaces |
type e = E: 'a -> e
let count = ref 0
let nodes : (e * int) list ref = ref []
let get v =
match List.find !nodes ~f:(fun (ee, _) -> ee = E v) with
| Some (_, i) -> i
| None ->
incr count;
nodes := (E v, !count) :: !nodes;
!count
end