exthtbl.mli 2.33 KB
Newer Older
1 2 3
(********************************************************************)
(*                                                                  *)
(*  The Why3 Verification Platform   /   The Why3 Development Team  *)
4
(*  Copyright 2010-2015   --   INRIA - CNRS - Paris-Sud University  *)
5 6 7 8 9 10
(*                                                                  *)
(*  This software is distributed under the terms of the GNU Lesser  *)
(*  General Public License version 2.1, with the special exception  *)
(*  on linking described in file LICENSE.                           *)
(********************************************************************)

11 12
(** Association tables over hashable types *)

13
val hash : 'a -> int
14
  (** the same as Hashtbl.hash *)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

module type S =
sig
  include Hashtbl.S

  val find_def : 'a t -> 'a -> key -> 'a
  (** return the first binding or the given value if none found *)

  val find_opt : 'a t -> key -> 'a option
  (** return the first binding or None if none found *)

  val find_exn : 'a t -> exn -> key -> 'a
  (** return the first binding or raise the given exception if none found *)

  val map : (key -> 'a -> 'b) -> 'a t -> 'b t
  (** a shortcut less efficient than possible *)

  val memo : int -> (key -> 'a) -> key -> 'a
  (** convenience function, memoize a function *)

  val is_empty : 'a t -> bool
  (** test if the hashtbl is empty *)
end

module type Private =
sig
  (** Private Hashtbl *)
  type 'a t
  type key

  val find : 'a t -> key -> 'a
  (** Same as {!Hashtbl.find} *)

  val find_def : 'a t -> 'a -> key -> 'a
  (** return the first binding or the given value if none found *)

  val find_opt : 'a t -> key -> 'a option
  (** return the first binding or None if none found *)

  val find_exn : 'a t -> exn -> key -> 'a
  (** return the first binding or raise the given exception if none found *)

  val map : (key -> 'a -> 'b) -> 'a t -> 'b t
  (** a shortcut less efficient than possible *)

  val iter : (key -> 'a -> unit) -> 'a t -> unit
  (** Same as {!Hashtbl.iter} *)

  val fold : (key -> 'a -> 'acc -> 'acc) -> 'a t -> 'acc -> 'acc
  (** Same as {!Hashtbl.fold} *)

  val mem : 'a t -> key -> bool
  (** Same as {!Hashtbl.mem} *)

  val length : 'a t -> int
  (** Same as {!Hashtbl.length} *)

  val is_empty : 'a t -> bool
  (** test if the hashtbl is empty *)
end

module Make (X:Hashtbl.HashedType) : S with type key = X.t