add CCPersistentHashtbl.stats

This commit is contained in:
Simon Cruanes 2015-10-21 22:48:51 +02:00
parent 15d5da628d
commit 54c2e4541e
2 changed files with 25 additions and 0 deletions

View file

@ -129,6 +129,10 @@ module type S = sig
val pp : key printer -> 'a printer -> 'a t printer val pp : key printer -> 'a printer -> 'a t printer
val print : key formatter -> 'a formatter -> 'a t formatter val print : key formatter -> 'a formatter -> 'a t formatter
val stats : _ t -> Hashtbl.statistics
(** Statistics on the internal table.
@since NEXT_RELEASE *)
end end
(*$inject (*$inject
@ -625,5 +629,22 @@ module Make(H : HashedType) : S with type key = H.t = struct
Format.fprintf fmt "%a -> %a" pp_k k pp_v v Format.fprintf fmt "%a -> %a" pp_k k pp_v v
); );
Format.pp_print_string fmt "}" Format.pp_print_string fmt "}"
let stats t =
let a = reroot_ t in
let max_bucket_length =
Array.fold_left (fun n b -> max n (buck_length_ b)) 0 a in
let bucket_histogram = Array.make (max_bucket_length+1) 0 in
Array.iter
(fun b ->
let l = buck_length_ b in
bucket_histogram.(l) <- bucket_histogram.(l) + 1
) a;
{Hashtbl.
num_bindings=t.length;
num_buckets=Array.length a;
max_bucket_length;
bucket_histogram;
}
end end

View file

@ -136,6 +136,10 @@ module type S = sig
val pp : key printer -> 'a printer -> 'a t printer val pp : key printer -> 'a printer -> 'a t printer
val print : key formatter -> 'a formatter -> 'a t formatter val print : key formatter -> 'a formatter -> 'a t formatter
val stats : _ t -> Hashtbl.statistics
(** Statistics on the internal table.
@since NEXT_RELEASE *)
end end
(** {2 Implementation} *) (** {2 Implementation} *)