From b1e2c5acd6b74a8bb6f2282904243f46849ae8f7 Mon Sep 17 00:00:00 2001 From: Alain Frisch Date: Thu, 10 Mar 2016 15:10:02 +0100 Subject: [PATCH] Add non-regression test for previous commit. --- testsuite/tests/lib-hashtbl/htbl.ml | 11 +++++++++++ testsuite/tests/lib-hashtbl/htbl.reference | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/testsuite/tests/lib-hashtbl/htbl.ml b/testsuite/tests/lib-hashtbl/htbl.ml index b96ac81c4..1fa88f870 100644 --- a/testsuite/tests/lib-hashtbl/htbl.ml +++ b/testsuite/tests/lib-hashtbl/htbl.ml @@ -250,3 +250,14 @@ let _ = TWSL.test (list_data d); printf "-- Weak Kn -- Arrays of strings\n%!"; TWSA.test (Array.map (fun (l,i) -> (Array.of_list l,i)) (list_data d)) + + +let () = + let h = Hashtbl.create 16 in + for i = 1 to 1000 do Hashtbl.add h i (i * 2) done; + Printf.printf "%i elements\n" (Hashtbl.length h); + Hashtbl.filter_map_inplace (fun k v -> if k mod 100 = 0 then ((*Hashtbl.add h v v;*) Some (v / 100)) else None) h; + let l = Hashtbl.fold (fun k v acc -> (k, v) :: acc) h [] in + let l = List.sort compare l in + List.iter (fun (k, v) -> Printf.printf "%i,%i\n" k v) l; + Printf.printf "%i elements\n" (Hashtbl.length h) diff --git a/testsuite/tests/lib-hashtbl/htbl.reference b/testsuite/tests/lib-hashtbl/htbl.reference index 9f42ee4bc..653fbc561 100644 --- a/testsuite/tests/lib-hashtbl/htbl.reference +++ b/testsuite/tests/lib-hashtbl/htbl.reference @@ -42,3 +42,15 @@ Removal: passed Insertion: passed Insertion: passed Removal: passed +1000 elements +100,2 +200,4 +300,6 +400,8 +500,10 +600,12 +700,14 +800,16 +900,18 +1000,20 +10 elements