Commit df7dc515 authored by POTTIER Francois's avatar POTTIER Francois

New signature [TWO_PHASE_NUMBERING].

New functors [ForOrderedType], [ForHashedType], and [ForType] in Numbering.
parent 41bf7ca8
......@@ -92,3 +92,12 @@ module Make (M : IMPERATIVE_MAPS) = struct
end
end
module ForOrderedType (T : OrderedType) =
Make(Glue.PersistentMapsToImperativeMaps(Map.Make(T)))
module ForHashedType (T : HashedType) =
Make(Glue.HashTablesAsImperativeMaps(T))
module ForType (T : TYPE) =
ForHashedType(Glue.TrivialHashedType(T))
......@@ -13,15 +13,32 @@
open Sigs
(* The functor [Make] requires an implementation of maps for the type [M.key]
and offers a numbering facility. A typical numbering process is organized
in two phases. During the first phase, the numbering is ongoing; one can
encode keys, but not decode. Applying the functor [Done()] ends the first
phase. A fixed numbering then becomes available, which gives access to the
total number [n] of encoded keys and to both [encode] and [decode]. The
function [decode] is backed by an array of size [n], therefore runs in
constant time. *)
module Make (M : IMPERATIVE_MAPS) : sig
include ONGOING_NUMBERING with type t = M.key
module Done () : NUMBERING with type t = M.key
end
and offers a two-phase numbering facility. The function [encode] is backed
by a map, therefore runs in logarithmic time or constant time, depending on
the type of map that is used. The function [decode] is backed by an array
of size [n], therefore runs in constant time. *)
module Make
(M : IMPERATIVE_MAPS)
: TWO_PHASE_NUMBERING with type t = M.key
(* [ForOrderedType] is a special case of [Make] where it suffices for
keys to be ordered. *)
module ForOrderedType
(T : OrderedType)
: TWO_PHASE_NUMBERING with type t = T.t
(* [ForHashedType] is a special case of [Make] where it suffices for
keys to be hashed. *)
module ForHashedType
(T : HashedType)
: TWO_PHASE_NUMBERING with type t = T.t
(* [ForType] is a special case of [Make] where keys can have arbitrary type.
OCaml's built-in generic equality and hash functions are used. *)
module ForType
(T : TYPE)
: TWO_PHASE_NUMBERING with type t = T.t
......@@ -229,6 +229,18 @@ module type NUMBERING = sig
val decode: int -> t
end
(* A combination of the above two signatures. According to this signature, a
numbering process is organized in two phases. During the first phase, the
numbering is ongoing; one can encode keys, but not decode. Applying the
functor [Done()] ends the first phase. A fixed numbering then becomes
available, which gives access to the total number [n] of encoded keys and
to both [encode] and [decode] functions. *)
module type TWO_PHASE_NUMBERING = sig
include ONGOING_NUMBERING
module Done () : NUMBERING with type t = t
end
(* -------------------------------------------------------------------------- *)
(* Injections. *)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment