open Table
-
+let compteur = ref 0
let all_nodes tree = let root = Naive_tree.root tree in
eval_axis tree [root] (Descendant true)
and compile_single_path_rev p =
match p with
- | Absolute p | Relative p -> compile_step_list_rev (List.rev p)
+ | Absolute p | Relative p -> compile_step_list_rev p (*(List.rev p)*)
and compile_step_list_rev p = match p with
| [] -> Dom (*assert false*) (*on fait rien , mais comment signifer ???*)
let open Xpath.Ast in
match a with
Self -> Self
- | Attribute -> assert false
+ | Attribute -> Parent
| Child -> Parent
| Descendant b ->
if not b then (Ancestor false)
else diff_list t ll1 ll2
-let do_debug = ref true
+let do_debug = ref false
let debug tree q l =
if !do_debug then begin
Format.pp_print_flush Format.std_formatter ();
end
+let table_query_tree = Hashtbl.create 97
+
let rec eval_query_tree tree start q =
let resultat =
- match q with
- | Start -> start
- | Dom -> all_nodes tree
- | Tag t -> element_by_tag tree t
- | Axis (a,q1) -> let ls = eval_query_tree tree start q1 in
- eval_axis tree ls a
- | Binop (op,q1,q2)-> begin
- let ls1 = eval_query_tree tree start q1 in
- let ls2 = eval_query_tree tree start q2 in
- match op with
- | Union -> union_list tree ls1 ls2
- | Inter -> inter_list tree ls1 ls2
- | Diff -> diff_list tree ls1 ls2
- end
+ begin
+ try
+ Hashtbl.find table_query_tree q
+ with Not_found ->
+ let res =
+ match q with
+ | Start -> start
+ | Dom -> all_nodes tree
+ | Tag t -> element_by_tag tree t
+ | Axis (a,q1) -> let ls = eval_query_tree tree start q1 in
+ eval_axis tree ls a
+ | Binop (op,q1,q2)-> begin
+ let ls1 = eval_query_tree tree start q1 in
+ let ls2 = eval_query_tree tree start q2 in
+ match op with
+ | Union -> union_list tree ls1 ls2
+ | Inter -> inter_list tree ls1 ls2
+ | Diff -> diff_list tree ls1 ls2
+ end
+ in
+ Hashtbl.add table_query_tree q res;
+ compteur := !compteur + (List.length res);
+ res
+ end
in
debug tree q resultat;
resultat
-