Add a compact tree model.
[tatoo.git] / src / tatoo.ml
index 485d8e1..5dec2f6 100644 (file)
@@ -50,7 +50,7 @@ let main () =
     | Some input ->
         let fd = open_in input in fd, fun () -> close_in fd
     in
-    let d = time Naive_tree.load_xml_file fd "parsing xml document" in
+    let d = time Compact_tree.load_xml_file fd "parsing xml document" in
     close_fd (); d
   in
   let queries =
@@ -104,9 +104,10 @@ let main () =
       Logger.msg `STATS "@[Automaton: @\n%a@]" Ata.print auto) auto_list;
   end;
 
-  let module Naive = Run.Make(Naive_tree) in
+  let module Naive = Run.Make(Compact_tree)(Compact_node_list) in
   let result_list =
-    let root = [ Naive_tree.root doc] in
+    let root = Compact_node_list.create () in
+    let () = Compact_node_list.add (Compact_tree.root doc) root in
     let f, msg =
       match !Options.parallel, !Options.compose with
         true, true ->
@@ -123,10 +124,13 @@ let main () =
   let s = Naive.stats () in
   Run.(
   Logger.msg `STATS
-    "@[tree size: %d@\ntraversals: %d@\ncache2 hit ratio: %f@\ncache5 hit ratio: %f@]"
-    s.tree_size s.run
-    (float s.cache2_hit /. float s.cache2_access)
-    (float s.cache5_hit /. float s.cache5_access));
+    "@[tree size: %d@\ntraversals: %d@\ntransition fetch cache miss ratio: %f@\ntransition eval cache miss ratio: %f@\nNumber of visited nodes per pass: %a@]"
+    s.tree_size s.pass
+    (float s.fetch_trans_cache_miss /. float s.fetch_trans_cache_access)
+    (float s.eval_trans_cache_miss /. float s.eval_trans_cache_access)
+    (let i = ref 0 in
+     Pretty.print_list ~sep:"," (fun fmt n -> Format.fprintf fmt "%i: %i" !i n;incr i))
+    s.nodes_per_run);
   time (fun () ->
     let count = ref 1 in
     List.iter (fun results ->
@@ -134,11 +138,11 @@ let main () =
       output_string output (string_of_int !count);
       output_string output "\" >\n";
       if !Options.count then begin
-        output_string output (string_of_int (List.length results));
+        output_string output (string_of_int (Compact_node_list.length results));
         output_char output '\n';
       end else
-        List.iter (fun n ->
-          Naive_tree.print_xml output doc n;
+        Compact_node_list.iter (fun n ->
+            Compact_tree.print_xml output doc n;
           output_char output '\n'
         ) results;
       output_string output "</xml_result>\n";
@@ -162,4 +166,6 @@ let () =
           Some s -> ("file " ^ s)
         | None -> "[stdin]") msg; exit 3
   | Xpath.Ulexer.Error (s, e, msg) -> eprintf "Error: character %i-%i: %s\n%!" s e msg; exit 4
-  | e -> eprintf "FATAL ERROR: %s\n%!" (Printexc.to_string e); exit 128
+(*  | e -> Printexc.print_backtrace stderr;
+    flush stderr;
+    eprintf "FATAL ERROR: %s\n%!" (Printexc.to_string e); exit 128 *)