From 947486007e49b672e179b9e855d3dddcd170964a Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Sun, 16 Dec 2018 17:26:49 +0100 Subject: [PATCH] Fix Hashtbl.Make.of_seq creating randomized tables Book-keeping error only - although it does potentially initialise the PRNG unnecessarily. --- Changes | 3 ++- stdlib/ephemeron.ml | 12 ++++++++++++ stdlib/hashtbl.ml | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 7a826b3fe..812fba757 100644 --- a/Changes +++ b/Changes @@ -356,7 +356,8 @@ OCaml 4.08.0 (Pierre Weis, Richard Bonichon, review by Florian Angeletti) - GPR#2202: Correct Hashtbl.MakeSeeded.{add_seq,replace_seq,of_seq} to use - functor hash function instead of default hash function. + functor hash function instead of default hash function. Hashtbl.Make.of_seq + shouldn't create randomized hash tables. (David Allsopp, review by Alain Frisch) ### Other libraries: diff --git a/stdlib/ephemeron.ml b/stdlib/ephemeron.ml index 24bd1e701..b630c15b9 100644 --- a/stdlib/ephemeron.ml +++ b/stdlib/ephemeron.ml @@ -482,6 +482,10 @@ module K1 = struct let hash (_seed: int) x = H.hash x end) let create sz = create ~random:false sz + let of_seq i = + let tbl = create 16 in + replace_seq tbl i; + tbl end end @@ -570,6 +574,10 @@ module K2 = struct let hash (_seed: int) x = H2.hash x end) let create sz = create ~random:false sz + let of_seq i = + let tbl = create 16 in + replace_seq tbl i; + tbl end end @@ -670,5 +678,9 @@ module Kn = struct let hash (_seed: int) x = H.hash x end) let create sz = create ~random:false sz + let of_seq i = + let tbl = create 16 in + replace_seq tbl i; + tbl end end diff --git a/stdlib/hashtbl.ml b/stdlib/hashtbl.ml index 34f64c80c..82ee9db79 100644 --- a/stdlib/hashtbl.ml +++ b/stdlib/hashtbl.ml @@ -599,4 +599,8 @@ module Make(H: HashedType): (S with type key = H.t) = let hash (_seed: int) x = H.hash x end) let create sz = create ~random:false sz + let of_seq i = + let tbl = create 16 in + replace_seq tbl i; + tbl end