hashcons.mli 2.81 KB
Newer Older
Jean-Christophe Filliâtre's avatar
Jean-Christophe Filliâtre committed
1 2
(**************************************************************************)
(*                                                                        *)
Jean-Christophe Filliâtre's avatar
headers  
Jean-Christophe Filliâtre committed
3 4
(*  Copyright (C) Francois Bobot, Jean-Christophe Filliatre,              *)
(*  Johannes Kanig and Andrei Paskevich.                                  *)
Jean-Christophe Filliâtre's avatar
Jean-Christophe Filliâtre committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
(*                                                                        *)
(*  This software is free software; you can redistribute it and/or        *)
(*  modify it under the terms of the GNU Library General Public           *)
(*  License version 2.1, with the special exception on linking            *)
(*  described in file LICENSE.                                            *)
(*                                                                        *)
(*  This software is distributed in the hope that it will be useful,      *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  *)
(*                                                                        *)
(**************************************************************************)

(*s Hash tables for hash consing. 

    Hash consed values are of the
    following type [hash_consed]. The field [tag] contains a unique
    integer (for values hash consed with the same table). The field
    [hkey] contains the hash key of the value (without modulo) for
    possible use in other hash tables (and internally when hash
    consing tables are resized). The field [node] contains the value
    itself. 

    Hash consing tables are using weak pointers, so that values that are no
    more referenced from anywhere else can be erased by the GC. *)

module type HashedType =
  sig
    type t
33 34 35
    val equal : t -> t -> bool
    val hash : t -> int
    val tag : int -> t -> t
Jean-Christophe Filliâtre's avatar
Jean-Christophe Filliâtre committed
36 37 38 39 40 41
  end

module type S =
  sig
    type t

42
    val hashcons : t -> t
Jean-Christophe Filliâtre's avatar
Jean-Christophe Filliâtre committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
      (** [hashcons n f] hash-cons the value [n] using function [f] i.e. returns
	  any existing value in the table equal to [n], if any; 
	  otherwise, creates a new value with function [f], stores it
	  in the table and returns it. Function [f] is passed
	  the node [n] as first argument and the unique id as second argument.
      *)

    val iter : (t -> unit) -> unit
      (** [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,
	  smallest bucket length, median bucket length, biggest 
	  bucket length. *)
  end

59
module Make(H : HashedType) : (S with type t = H.t)
60 61 62 63 64 65 66 67 68 69


(* helpers *)

val combine : int -> int -> int
val combine2 : int -> int -> int -> int
val combine3 : int -> int -> int -> int -> int
val combine_list : ('a -> int) -> int -> 'a list -> int