Commit 663e575f authored by POTTIER Francois's avatar POTTIER Francois

Modified the hash-consing service in [Misc] to print statistics.

parent b6734a0c
......@@ -605,6 +605,7 @@ let level = ref 0
let done_with_level () =
Printf.fprintf stderr "Done with level %d.\n" !level;
W.verbose();
T.verbose();
E.verbose();
Printf.fprintf stderr "Q stores %d facts.\n%!" (Q.cardinal q)
......
......@@ -275,7 +275,7 @@ module Terminal = struct
"the --coverage analysis supports at most 256 terminal symbols.\n\
The grammar has %d terminal symbols." n)
let intern : string -> string =
let (intern : string -> string), verbose =
Misc.new_intern 1023
type word =
......
......@@ -170,6 +170,9 @@ module Terminal : sig
val first: word -> t -> t
val elements: word -> t list
val print: word -> string
(* [verbose()] prints statistics about the use of the internal
hash-consing table so far. *)
val verbose: unit -> unit
end
......
......@@ -245,16 +245,26 @@ let map_opt f l =
| Some y -> y :: ys
) [] l))
let new_intern capacity : string -> string =
let new_intern capacity =
let module H = Hashtbl.Make(struct
type t = string
let equal = (=)
let hash = Hashtbl.hash
end) in
let table = H.create capacity in
fun s ->
let c = ref 0
and n = ref 0 in
let intern s =
c := !c + 1;
try
H.find table s
with Not_found ->
n := !n + 1;
H.add table s s;
s
and verbose () =
Printf.fprintf stderr
"%d calls to intern; %d unique strings.\n%!"
!c !n
in
intern, verbose
......@@ -150,6 +150,9 @@ val postincrement: int ref -> int
val map_opt : ('a -> 'b option) -> 'a list -> 'b list
(* [new_intern capacity] creates a new service for interning (hash-consing)
strings. [capacity] is the initial capacity of the internal hash table. *)
val new_intern: int -> (string -> string)
strings. [capacity] is the initial capacity of the internal hash table.
[new_intern] returns a pair [intern, verbose] where [intern] is the
hash-consing service and [verbose] prints statistics about the use of
the service so far. *)
val new_intern: int -> (string -> string) * (unit -> unit)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment