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;
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
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 (
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 =
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 ->
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