Commit 367307fe authored by Andrei Paskevich's avatar Andrei Paskevich

Hashcons: create unique objects

this may be useful if we want to have in an h-consed type
objects that cannot be equal to no other existing or future
value of that type (thus, this objects cannot be reconstructed).
This is more efficient than making comparison return false on
these objects, since we don't need to store them in a week set
at all.
parent 11e3593d
......@@ -24,6 +24,7 @@ module type S =
sig
type t
val hashcons : t -> t
val unique : t -> t
val iter : (t -> unit) -> unit
val stats : unit -> int * int * int * int * int * int
end
......@@ -44,6 +45,11 @@ struct
if o == d then incr next_tag;
o
let unique d =
let d = H.tag !next_tag d in
incr next_tag;
d
let iter f = WH.iter f htable
let stats () = WH.stats htable
......
......@@ -35,14 +35,20 @@ module type S =
type t
val hashcons : t -> t
(** [hashcons n] hash-cons the value [n] i.e. returns
any existing value in the table equal to [n], if any;
otherwise, creates a new value with function [tag], stores it
in the table and returns it.
*)
(** [hashcons n] hash-cons value [n] i.e. returns any existing
value in the table equal to [n], if any; otherwise, creates
a new value with function [tag], stores it in the table and
returns it. *)
val unique : t -> t
(** [unique n] registers the new value [n] without hash-consing.
This should be used in case where the value is guaranteed to
be unique, i.e. not equal to any other value, old or future.
Unique values are not visited by [iter]. *)
val iter : (t -> unit) -> unit
(** [iter f] iterates [f] over all elements of the table . *)
(** [iter f] iterates [f] over all elements of the table. *)
val stats : unit -> int * int * int * int * int * int
(** Return statistics on the table. The numbers are, in order:
table length, number of entries, sum of bucket lengths,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment