(* Distributed under the terms of the LGPL (see LICENCE) *)
(******************************************************************************)
-let collect_tags v =
- let rec aux acc v =
- if Tree.Binary.is_node v
- then
- let tag = Tree.Binary.tag v
- in
- let acc = aux (Ptset.add tag acc) (Tree.Binary.first_child v)
- in
- aux (Ptset.add tag acc) (Tree.Binary.next_sibling v)
- else acc
- in
- aux Ptset.empty v
-;;
if Array.length (Sys.argv) <> 2
let doc =
- try
- Tree.Binary.parse_xml_uri Sys.argv.(1)
- with
- | _ ->
- Printf.printf "Error parsing document\n";
- exit 2
-;;
-let _ = Tag.init (Tree.Binary.tag_pool doc)
-;;
-let tags = (Ptset.add (Tag.tag "foo") (collect_tags doc))
+ try
+ Tree.load Sys.argv.(1)
+ with
+ | _ ->
+ ( try
+ Tree.parse_xml_uri Sys.argv.(1)
+ with
+ | _ ->(
+
+ Printf.printf "Error parsing document\n";
+ exit 2))
;;
-let _ = Tree.Binary.test_xml_tree Format.std_formatter tags doc
+
+let full_traversal tree =
+ let rec loop t =
+ if Tree.is_node t
+ then
+ begin
+ (*ignore (Tree.tag t); *)
+ loop (Tree.node_child t);
+ loop (Tree.node_sibling t);
+ end
+ in loop tree
;;
+
+
+let _ = Tag.init (Tree.tag_pool doc)
+let time f x =
+ let t1 = Unix.gettimeofday () in
+ let r = f x in
+ let t2 = Unix.gettimeofday () in
+ let t = (1000. *.(t2 -. t1)) in
+ Printf.eprintf " %fms\n%!" t ;
+ r
+;;
+let _ = Printf.eprintf "Timing traversal ... ";;
+let _ = time (full_traversal) doc
+;;