signature HashedType =
sig
type t
val equal: t -> t -> bool
val hash: t -> int
end
The input signature of the functor MakeHash
.
t
is the type of keys.
equal
is the equality predicate used to compare keys.
hash
is a hashing function on keys, returning a non-negative
integer. It must be such that if two keys are equal according
to equal
, then they must have identical hash values as computed
by hash
.
Examples: suitable (equal
, hash
) pairs for arbitrary key
types include
((=)
, Hashtbl.hash
) for comparing objects by structure, and
((==)
, Hashtbl.hash
) for comparing objects by addresses
(e.g. for reference values or cyclic keys).
signature HASH =
sig
type key
type 'a t
val create: int -> 'a t
val clear: 'a t -> unit
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
end
functor MakeHash(H: HashedType): (HASH with type key = H.t)
The functor MakeHash
returns a structure containing
a type key
of keys and a type 'a t
of hash tables
associating data of type 'a
to keys of type key
.
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.