mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-10 21:23:57 -05:00
add CCHashtbl.Poly and fix issue in Containers (close #46)
This commit is contained in:
parent
edc488b909
commit
8ddacbb028
3 changed files with 185 additions and 175 deletions
|
|
@ -10,6 +10,7 @@ type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
(** {2 Polymorphic tables} *)
|
(** {2 Polymorphic tables} *)
|
||||||
|
|
||||||
|
module Poly = struct
|
||||||
let get tbl x =
|
let get tbl x =
|
||||||
try Some (Hashtbl.find tbl x)
|
try Some (Hashtbl.find tbl x)
|
||||||
with Not_found -> None
|
with Not_found -> None
|
||||||
|
|
@ -135,6 +136,9 @@ let print pp_k pp_v fmt m =
|
||||||
Format.pp_print_cut fmt ()
|
Format.pp_print_cut fmt ()
|
||||||
) m;
|
) m;
|
||||||
Format.fprintf fmt "}@]"
|
Format.fprintf fmt "}@]"
|
||||||
|
end
|
||||||
|
|
||||||
|
include Poly
|
||||||
|
|
||||||
(** {2 Functor} *)
|
(** {2 Functor} *)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,9 @@ type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
(** {2 Polymorphic tables} *)
|
(** {2 Polymorphic tables} *)
|
||||||
|
|
||||||
|
(** This sub-module contains the extension of the standard polymorphic hashtbl. *)
|
||||||
|
|
||||||
|
module Poly : sig
|
||||||
val get : ('a,'b) Hashtbl.t -> 'a -> 'b option
|
val get : ('a,'b) Hashtbl.t -> 'a -> 'b option
|
||||||
(** Safe version of {!Hashtbl.find} *)
|
(** Safe version of {!Hashtbl.find} *)
|
||||||
|
|
||||||
|
|
@ -102,6 +105,9 @@ val get_or_add : ('a, 'b) Hashtbl.t -> f:('a -> 'b) -> k:'a -> 'b
|
||||||
val print : 'a printer -> 'b printer -> ('a, 'b) Hashtbl.t printer
|
val print : 'a printer -> 'b printer -> ('a, 'b) Hashtbl.t printer
|
||||||
(** Printer for table
|
(** Printer for table
|
||||||
@since 0.13 *)
|
@since 0.13 *)
|
||||||
|
end
|
||||||
|
|
||||||
|
include module type of Poly
|
||||||
|
|
||||||
(** {2 Functor} *)
|
(** {2 Functor} *)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ module Hashtbl = struct
|
||||||
and module Make = Hashtbl.Make
|
and module Make = Hashtbl.Make
|
||||||
and type ('a,'b) t = ('a,'b) Hashtbl.t
|
and type ('a,'b) t = ('a,'b) Hashtbl.t
|
||||||
)
|
)
|
||||||
(* still unable to include CCHashtbl itself, for the polymorphic functions *)
|
include CCHashtbl.Poly
|
||||||
module type S' = CCHashtbl.S
|
module type S' = CCHashtbl.S
|
||||||
module Make' = CCHashtbl.Make
|
module Make' = CCHashtbl.Make
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue