X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=tree.ml;h=cbb267af982745f9d8bcec7d3ce47055404f30f1;hb=25a3fa55f6de1835d2407283eeb43b01819543f6;hp=b19a3aaa1faa835de69df291bf265454a854db3c;hpb=dc91851aaeac91a71eba2c266d0227adea0c5815;p=SXSI%2Fxpathcomp.git diff --git a/tree.ml b/tree.ml index b19a3aa..cbb267a 100644 --- a/tree.ml +++ b/tree.ml @@ -60,6 +60,7 @@ sig val print_id : Format.formatter -> t -> unit val test_xml_tree : Format.formatter -> Ptset.t -> t -> unit val init_contains : t -> string -> unit + val init_naive_contains : t -> string -> unit val mk_nil : t -> t val test_jump : t -> Tag.t -> unit end @@ -310,6 +311,31 @@ struct Array.fast_sort (compare) a; contains_array := a + let init_naive_contains t s = + let i,j = Tree.doc_ids t.doc (Tree.root t.doc) + in + let regexp = Str.regexp_string s in + let matching arg = + try + let _ = Str.search_forward regexp arg 0; + in true + with _ -> false + in + let rec loop n acc l = + if n >= j then acc,l + else + let s = (*Printf.eprintf "%i \n%!" n;*)Text.get_cached_text t.doc n + in + if matching s + then loop (n+1) (n::acc) (l+1) + else loop (n+1) acc l + in + let acc,l = loop i [] 0 in + let a = Array.create l Text.nil in + let _ = List.fold_left (fun cpt e -> a.(cpt) <- e; (cpt-1)) (l-1) acc + in + contains_array := a + module DocIdSet = struct @@ -558,16 +584,17 @@ struct | _ -> { t with node=Nil } + let last_idx = ref 0 let array_find a i j = let l = Array.length a in let rec loop idx x y = if x > y || idx >= l then Text.nil else - if a.(idx) >= x then if a.(idx) > y then Text.nil else a.(idx) + if a.(idx) >= x then if a.(idx) > y then Text.nil else (last_idx := idx;a.(idx)) else loop (idx+1) x y in if a.(0) > j || a.(l-1) < i then Text.nil - else loop 0 i j + else loop !last_idx i j let text_below t =