X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2Ftree.ml;h=9b3d4bc52bdcecdc0685053ccbad4ef8268cdfea;hb=ecec752325cb3d207894a4f8d772936bd7ad9f4a;hp=0b2070b8c644491a6797734f97fd98e822d25c45;hpb=74aa5cc3aa21c5719a75358303e2daad12f8502c;p=SXSI%2Fxpathcomp.git diff --git a/src/tree.ml b/src/tree.ml index 0b2070b..9b3d4bc 100644 --- a/src/tree.ml +++ b/src/tree.ml @@ -170,10 +170,22 @@ end type bit_vector = string external bool_of_int : int -> bool = "%identity" +external int_of_bool : bool -> int = "%identity" let bit_vector_unsafe_get v i = bool_of_int (((Char.code (String.unsafe_get v (i lsr 3))) lsr (i land 7)) land 1) +let chr (c:int) : char = Obj.magic (c land 0xff) +let bit_vector_unsafe_set v i b = + let j = i lsr 3 in + let c = Char.code v.[j] in + let bit = int_of_bool b in + let mask = bit lsl (i land 7) in + if b then v.[j] <- chr (c lor mask) else v.[j] <- (chr (c land (lnot mask))) + +let bit_vector_create n = + let len = if n <= 0 then 0 else (n - 1) / 8 + 1 in + String.make len '\000' type t = { doc : tree; @@ -247,7 +259,6 @@ external tree_last_child : tree -> [`Tree] Node.t -> [`Tree] Node.t = "caml_xml_ let last_child t n = tree_last_child t.doc n - external tree_next_sibling : tree -> [`Tree] Node.t -> [`Tree] Node.t = "caml_xml_tree_next_sibling" "noalloc" let next_sibling t n = tree_next_sibling t.doc n @@ -688,17 +699,17 @@ type query_result = { bv : bit_vector; external tree_flush : tree -> Unix.file_descr -> unit = "caml_xml_tree_flush" let flush t fd = tree_flush t.doc fd -external text_prefix : tree -> string -> query_result = "caml_text_collection_prefix_bv" -let text_prefix t s = text_prefix t.doc s +external text_prefix : tree -> string -> bool -> query_result = "caml_text_collection_prefix_bv" +let text_prefix t s b = text_prefix t.doc s b -external text_suffix : tree -> string -> query_result = "caml_text_collection_suffix_bv" -let text_suffix t s = text_suffix t.doc s +external text_suffix : tree -> string -> bool -> query_result = "caml_text_collection_suffix_bv" +let text_suffix t s b = text_suffix t.doc s b -external text_equals : tree -> string -> query_result = "caml_text_collection_equals_bv" -let text_equals t s = text_equals t.doc s +external text_equals : tree -> string -> bool -> query_result = "caml_text_collection_equals_bv" +let text_equals t s b = text_equals t.doc s b -external text_contains : tree -> string -> query_result = "caml_text_collection_contains_bv" -let text_contains t s = text_contains t.doc s +external text_contains : tree -> string -> bool -> query_result = "caml_text_collection_contains_bv" +let text_contains t s b = text_contains t.doc s b module Predicate = Hcons.Make ( @@ -727,7 +738,7 @@ let query_fun = function let _pred_cache = Hashtbl.create 17 ;; let mk_pred query s = - let f = query_fun query in + let f = query_fun query in let memo = ref (fun _ _ -> failwith "Undefined") in memo := begin fun tree node -> let results = @@ -735,7 +746,7 @@ let mk_pred query s = Not_found -> time ~count:1 ~msg:(Printf.sprintf "Computing text query %s(%s)" (string_of_query query) s) - (f tree) s + (f tree) s true in let bv = results.bv in memo := begin fun _ n -> @@ -752,15 +763,15 @@ let mk_pred query s = Predicate.make memo -let full_text_prefix t s = (text_prefix t s).pos +let full_text_prefix t s = (text_prefix t s true).pos -let full_text_suffix t s = (text_suffix t s).pos +let full_text_suffix t s = (text_suffix t s true).pos -let full_text_equals t s = (text_equals t s).pos +let full_text_equals t s = (text_equals t s true).pos -let full_text_contains t s = (text_contains t s).pos +let full_text_contains t s = (text_contains t s true).pos let full_text_query q t s = - let res = (query_fun q) t s in + let res = (query_fun q) t s true in Hashtbl.replace _pred_cache (q,s) res; res.pos