diff --git a/pHashtbl.ml b/pHashtbl.ml index a54fe11b..bbb3b30b 100644 --- a/pHashtbl.ml +++ b/pHashtbl.ml @@ -92,7 +92,6 @@ let insert t key value = t.buckets.(j) <- Used (key, value, dist) | Used (key', _, _) when t.eq key key' -> (* insert here (erase old value) *) - t.size <- t.size + 1; t.buckets.(j) <- Used (key, value, dist) | Used (key', value', dist') when dist > dist' -> (* displace this key/value *) @@ -108,7 +107,7 @@ let insert t key value = (** Resize the array, by inserting its content into twice as large an array *) let resize t = let new_size = min (Array.length t.buckets * 2 + 1) Sys.max_array_length in - assert (new_size > Array.length t.buckets); + if not (new_size > Array.length t.buckets) then failwith "hashtbl is full"; let old_buckets = t.buckets in t.buckets <- Array.make new_size Empty; t.size <- 0; (* will be updated again *) diff --git a/tests/benchs.ml b/tests/benchs.ml index d8f6b6ca..5c6d4e9c 100644 --- a/tests/benchs.ml +++ b/tests/benchs.ml @@ -16,11 +16,9 @@ let hashtbl_add n = h let _ = - let n = 50000 in - let res = Bench.bench_funs + let res = Bench.bench_n ["phashtbl_add", (fun n -> ignore (phashtbl_add n)); "hashtbl_add", (fun n -> ignore (hashtbl_add n));] - n in Bench.summarize 1. res @@ -29,7 +27,7 @@ let phashtbl_replace n = for i = 0 to n do PHashtbl.replace h i i; done; - for i = 0 to n do + for i = n downto 0 do PHashtbl.replace h i i; done; h @@ -39,17 +37,15 @@ let hashtbl_replace n = for i = 0 to n do Hashtbl.replace h i i; done; - for i = 0 to n do + for i = n downto 0 do Hashtbl.replace h i i; done; h let _ = - let n = 50000 in - let res = Bench.bench_funs + let res = Bench.bench_n ["phashtbl_replace", (fun n -> ignore (phashtbl_replace n)); "hashtbl_replace", (fun n -> ignore (hashtbl_replace n));] - n in Bench.summarize 1. res