1 (***********************************************************************)
5 (* Kim Nguyen, LRI UMR8623 *)
6 (* Université Paris-Sud & CNRS *)
8 (* Copyright 2010-2012 Université Paris-Sud and Centre National de la *)
9 (* Recherche Scientifique. All rights reserved. This file is *)
10 (* distributed under the terms of the GNU Lesser General Public *)
11 (* License, with the special exception on linking described in file *)
14 (***********************************************************************)
16 (** Implementation of generic hashconsing. *)
18 module type Abstract =
21 (** The type of the data to be hashconsed *)
24 (** The type of hashconsed data *)
27 (** [make v] internalizes the value [v], making it an hashconsed
32 (** [node h] extract the original data from its hashconsed value
36 (** [hash h] returns a hash of [h], such that for every [h1] and
37 [h2], [equal h1 h2] implies [hash h1 = hash h2].
41 (** [uid h] returns a unique identifier *)
42 val equal : t -> t -> bool
43 (** Equality between hashconsed values. Equivalent to [==] *)
45 val init : unit -> unit
46 (** Initializes the internal storage. Any previously hashconsed
47 element is discarded. *)
50 (** Abstract signature of a module implementing an hashconsed datatype *)
55 type t = private { id : Uid.t;
58 include Abstract with type data := data and type t := t
61 (** Output signature of the functor {!Hcons.Make} *)
63 module Make (H : Sigs.HashedType) : S with type data = H.t
64 (** Functor building an implementation of hashconsed values for a given
65 implementation of {!Sigs.HashedType}. Hashconsed values are
66 persistent: the are kept in memory even if no external reference
67 remain. Calling [init()] explicitely will reclaim the space.
70 module Weak (H : Sigs.HashedType) : S with type data = H.t
71 (** Functor building an implementation of hashconsed values for a given
72 implementation of {!Sigs.HashedType}. Hashconsed values have a
73 weak semantics: they may be reclaimed as soon as no external
74 reference to them exists. The space may still be reclaimed
75 explicitely by calling [init].
78 module PosInt : Abstract with type data = int and type t = int
79 (** Compact implementation of hashconsed positive integer that
80 avoids boxing. [PosInt.make v] raises [Invalid_argument] if