diff options
| author | Pierre-Marie Pédrot | 2015-02-11 17:55:50 +0100 |
|---|---|---|
| committer | Pierre-Marie Pédrot | 2015-02-11 17:55:50 +0100 |
| commit | 37076a63ebd1491f26a6c5a3d67e054c106589b3 (patch) | |
| tree | 702d4be5c21408ce819b1265ac7cd4d5d2c2866d /lib/hashset.ml | |
| parent | 956b7c4304582b1e9e3ca0bb34944bcbac18c0cc (diff) | |
| parent | ac65eef8bbc2e405f1964f35c6a129dfa1755888 (diff) | |
Merge branch 'v8.5'
Diffstat (limited to 'lib/hashset.ml')
| -rw-r--r-- | lib/hashset.ml | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/hashset.ml b/lib/hashset.ml index 6bec81c756..1ca6cc6418 100644 --- a/lib/hashset.ml +++ b/lib/hashset.ml @@ -19,12 +19,20 @@ module type EqType = sig val equal : t -> t -> bool end +type statistics = { + num_bindings: int; + num_buckets: int; + max_bucket_length: int; + bucket_histogram: int array +} + module type S = sig type elt type t val create : int -> t val clear : t -> unit val repr : int -> elt -> t -> elt + val stats : t -> statistics end module Make (E : EqType) = @@ -185,6 +193,24 @@ module Make (E : EqType) = let ifnotfound index = add_aux t Weak.set (Some d) h index; d in find_or h t d ifnotfound + let stats t = + let fold accu bucket = max (count_bucket 0 bucket 0) accu in + let max_length = Array.fold_left fold 0 t.table in + let histogram = Array.make (max_length + 1) 0 in + let iter bucket = + let len = count_bucket 0 bucket 0 in + histogram.(len) <- succ histogram.(len) + in + let () = Array.iter iter t.table in + let fold (num, len, i) k = (num + k * i, len + k, succ i) in + let (num, len, _) = Array.fold_left fold (0, 0, 0) histogram in + { + num_bindings = num; + num_buckets = len; + max_bucket_length = Array.length histogram; + bucket_histogram = histogram; + } + end module Combine = struct |
