mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
updated PersistentHashtbl
This commit is contained in:
parent
f25d3bf7b5
commit
61ab1ab2cd
4 changed files with 43 additions and 18 deletions
1
_oasis
1
_oasis
|
|
@ -84,6 +84,7 @@ Executable benchs
|
|||
Path: tests/
|
||||
Install: false
|
||||
CompiledObject: native
|
||||
Build$: flag(bench)
|
||||
MainIs: benchs.ml
|
||||
BuildDepends: containers,bench
|
||||
|
||||
|
|
|
|||
|
|
@ -69,11 +69,15 @@ module type S = sig
|
|||
val fold : ('b -> key -> 'a -> 'b) -> 'b -> 'a t -> 'b
|
||||
(** Fold over bindings *)
|
||||
|
||||
val of_gen : ?init:'a t -> (key * 'a) Gen.t -> 'a t
|
||||
(** Add (replace) bindings from the generator to the table *)
|
||||
val of_seq : ?init:'a t -> (key * 'a) Sequence.t -> 'a t
|
||||
(** Add (replace) bindings from the sequence to the table *)
|
||||
|
||||
val to_gen : 'a t -> (key * 'a) Gen.t
|
||||
(** Generator on the bindings of the table *)
|
||||
val of_list : ?init:'a t -> (key * 'a) list -> 'a t
|
||||
|
||||
val to_seq : 'a t -> (key * 'a) Sequence.t
|
||||
(** Sequence of the bindings of the table *)
|
||||
|
||||
val to_list : 'a t -> (key * 'a) list
|
||||
end
|
||||
|
||||
(** {2 Implementation} *)
|
||||
|
|
@ -123,7 +127,9 @@ module Make(H : HashedType) : S with type key = H.t = struct
|
|||
Table.remove tbl key;
|
||||
k tbl)
|
||||
in
|
||||
reroot t (fun x -> x)
|
||||
match !t with
|
||||
| Table tbl -> tbl
|
||||
| _ -> reroot t (fun x -> x)
|
||||
|
||||
let is_empty t =
|
||||
match !t with
|
||||
|
|
@ -196,17 +202,27 @@ module Make(H : HashedType) : S with type key = H.t = struct
|
|||
| _ -> reroot t in
|
||||
Table.fold (fun k v acc -> f acc k v) tbl acc
|
||||
|
||||
let of_gen ?init gen =
|
||||
let of_seq ?init seq =
|
||||
let tbl = match init with
|
||||
| None -> Table.create 5
|
||||
| Some t -> Table.copy (reroot t) in
|
||||
Gen.iter (fun (k,v) -> Table.replace tbl k v) gen;
|
||||
Sequence.iter (fun (k,v) -> Table.replace tbl k v) seq;
|
||||
ref (Table tbl)
|
||||
|
||||
let to_gen t =
|
||||
(* not efficient at the moment... *)
|
||||
let of_list ?init l =
|
||||
of_seq ?init (Sequence.of_list l)
|
||||
|
||||
let to_list t =
|
||||
let tbl = reroot t in
|
||||
let bindings = Table.fold (fun k v acc -> (k,v)::acc) tbl [] in
|
||||
Gen.of_list bindings
|
||||
bindings
|
||||
|
||||
let to_seq t =
|
||||
fun k ->
|
||||
let tbl = match !t with
|
||||
| Table tbl -> tbl
|
||||
| _ -> reroot t
|
||||
in
|
||||
Table.iter (fun x y -> k (x,y)) tbl
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -69,11 +69,15 @@ module type S = sig
|
|||
val fold : ('b -> key -> 'a -> 'b) -> 'b -> 'a t -> 'b
|
||||
(** Fold over bindings *)
|
||||
|
||||
val of_gen : ?init:'a t -> (key * 'a) Gen.t -> 'a t
|
||||
(** Add (replace) bindings from the generator to the table *)
|
||||
val of_seq : ?init:'a t -> (key * 'a) Sequence.t -> 'a t
|
||||
(** Add (replace) bindings from the sequence to the table *)
|
||||
|
||||
val to_gen : 'a t -> (key * 'a) Gen.t
|
||||
(** Generator on the bindings of the table *)
|
||||
val of_list : ?init:'a t -> (key * 'a) list -> 'a t
|
||||
|
||||
val to_seq : 'a t -> (key * 'a) Sequence.t
|
||||
(** Sequence of the bindings of the table *)
|
||||
|
||||
val to_list : 'a t -> (key * 'a) list
|
||||
end
|
||||
|
||||
(** {2 Implementation} *)
|
||||
|
|
|
|||
12
setup.ml
12
setup.ml
|
|
@ -1,7 +1,7 @@
|
|||
(* setup.ml generated for the first time by OASIS v0.3.0 *)
|
||||
|
||||
(* OASIS_START *)
|
||||
(* DO NOT EDIT (digest: 55272ba3562c49c9ccb909d630d508a8) *)
|
||||
(* DO NOT EDIT (digest: c9341580de424a256871dd6b43247845) *)
|
||||
(*
|
||||
Regenerated by OASIS v0.3.0
|
||||
Visit http://oasis.forge.ocamlcore.org for more information and
|
||||
|
|
@ -6071,7 +6071,11 @@ let setup_t =
|
|||
cs_plugin_data = [];
|
||||
},
|
||||
{
|
||||
bs_build = [(OASISExpr.EBool true, true)];
|
||||
bs_build =
|
||||
[
|
||||
(OASISExpr.EBool true, false);
|
||||
(OASISExpr.EFlag "bench", true)
|
||||
];
|
||||
bs_install = [(OASISExpr.EBool true, false)];
|
||||
bs_path = "tests/";
|
||||
bs_compiled_object = Native;
|
||||
|
|
@ -6219,7 +6223,7 @@ let setup_t =
|
|||
};
|
||||
oasis_fn = Some "_oasis";
|
||||
oasis_version = "0.3.0";
|
||||
oasis_digest = Some "\177\020\012#dJ\255\130\019K\237\025\237\016l\020";
|
||||
oasis_digest = Some "H\2095\254\2336\164\1606\140\2459^6o\218";
|
||||
oasis_exec = None;
|
||||
oasis_setup_args = [];
|
||||
setup_update = false;
|
||||
|
|
@ -6227,6 +6231,6 @@ let setup_t =
|
|||
|
||||
let setup () = BaseSetup.setup setup_t;;
|
||||
|
||||
# 6231 "setup.ml"
|
||||
# 6235 "setup.ml"
|
||||
(* OASIS_STOP *)
|
||||
let () = setup ();;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue