Improve backward compatibility for Hashtbl functorial interface:

Hashtbl.Make returns a "create" function without an optional seed parameter.
(Which would be ignored anyway.)
Hashtbl.MakeSeeded returns a "create" function with an optional seed parameter.


git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@11204 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Xavier Leroy 2011-09-18 09:35:27 +00:00
parent 958c48049f
commit 8e33ab4f2d
3 changed files with 75 additions and 14 deletions

View File

@ -220,7 +220,7 @@ module type S =
sig
type key
type 'a t
val create: ?seed:int -> int -> 'a t
val create: int -> 'a t
val clear: 'a t -> unit
val copy: 'a t -> 'a t
val add: 'a t -> key -> 'a -> unit
@ -235,7 +235,26 @@ module type S =
val stats: 'a t -> statistics
end
module MakeSeeded(H: SeededHashedType): (S with type key = H.t) =
module type SeededS =
sig
type key
type 'a t
val create : ?seed:int -> int -> 'a t
val clear : 'a t -> unit
val copy : 'a t -> 'a t
val add : 'a t -> key -> 'a -> unit
val remove : 'a t -> key -> unit
val find : 'a t -> key -> 'a
val find_all : 'a t -> key -> 'a list
val replace : 'a t -> key -> 'a -> unit
val mem : 'a t -> key -> bool
val iter : (key -> 'a -> unit) -> 'a t -> unit
val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
val length : 'a t -> int
val stats: 'a t -> statistics
end
module MakeSeeded(H: SeededHashedType): (SeededS with type key = H.t) =
struct
type key = H.t
type 'a hashtbl = (key, 'a) t
@ -327,8 +346,11 @@ module MakeSeeded(H: SeededHashedType): (S with type key = H.t) =
end
module Make(H: HashedType): (S with type key = H.t) =
MakeSeeded(struct
type t = H.t
let equal = H.equal
let hash (seed: int) x = H.hash x
end)
struct
include MakeSeeded(struct
type t = H.t
let equal = H.equal
let hash (seed: int) x = H.hash x
end)
let create sz = create ~seed:0 sz
end

View File

@ -155,7 +155,7 @@ module type S =
sig
type key
type 'a t
val create : ?seed:int -> int -> 'a t
val create : int -> 'a t
val clear : 'a t -> unit
val copy : 'a t -> 'a t
val add : 'a t -> key -> 'a -> unit
@ -179,8 +179,7 @@ module Make (H : HashedType) : S with type key = H.t
The operations perform similarly to those of the generic
interface, but use the hashing and equality functions
specified in the functor argument [H] instead of generic
equality and hashing. The optional [seed] argument to the
[create] function is ignored. *)
equality and hashing. *)
module type SeededHashedType =
sig
@ -198,7 +197,28 @@ module type SeededHashedType =
(** The input signature of the functor {!Hashtbl.MakeSeeded}.
@since 3.13.0 *)
module MakeSeeded (H : SeededHashedType) : S with type key = H.t
module type SeededS =
sig
type key
type 'a t
val create : ?seed:int -> int -> 'a t
val clear : 'a t -> unit
val copy : 'a t -> 'a t
val add : 'a t -> key -> 'a -> unit
val remove : 'a t -> key -> unit
val find : 'a t -> key -> 'a
val find_all : 'a t -> key -> 'a list
val replace : 'a t -> key -> 'a -> unit
val mem : 'a t -> key -> bool
val iter : (key -> 'a -> unit) -> 'a t -> unit
val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
val length : 'a t -> int
val stats: 'a t -> statistics
end
(** The output signature of the functor {!Hashtbl.MakeSeeded}.
@since 3.13.0 *)
module MakeSeeded (H : SeededHashedType) : SeededS with type key = H.t
(** Functor building an implementation of the hashtable structure.
The functor [Hashtbl.MakeSeeded] returns a structure containing
a type [key] of keys and a type ['a t] of hash tables
@ -206,8 +226,7 @@ module MakeSeeded (H : SeededHashedType) : S with type key = H.t
The operations perform similarly to those of the generic
interface, but use the seeded hashing and equality functions
specified in the functor argument [H] instead of generic
equality and hashing. The optional [seed] argument to the [create]
function is honored.
equality and hashing.
@since 3.13.0 *)

View File

@ -44,6 +44,26 @@ module Hashtbl : sig
module type HashedType = Hashtbl.HashedType
module type SeededHashedType = Hashtbl.SeededHashedType
module type S =
sig
type key
and 'a t
val create : int -> 'a t
val clear : 'a t -> unit
val copy : 'a t -> 'a t
val add : 'a t -> key:key -> data:'a -> unit
val remove : 'a t -> key -> unit
val find : 'a t -> key -> 'a
val find_all : 'a t -> key -> 'a list
val replace : 'a t -> key:key -> data:'a -> unit
val mem : 'a t -> key -> bool
val iter : f:(key:key -> data:'a -> unit) -> 'a t -> unit
val fold :
f:(key:key -> data:'a -> 'b -> 'b) ->
'a t -> init:'b -> 'b
val length : 'a t -> int
val stats: 'a t -> statistics
end
module type SeededS =
sig
type key
and 'a t
@ -64,7 +84,7 @@ module Hashtbl : sig
val stats: 'a t -> statistics
end
module Make : functor (H : HashedType) -> S with type key = H.t
module MakeSeeded (H : SeededHashedType) : S with type key = H.t
module MakeSeeded (H : SeededHashedType) : SeededS with type key = H.t
val hash : 'a -> int
val seeded_hash : int -> 'a -> int
val hash_param : int -> int -> 'a -> int