1 (******************************************************************************)
2 (* SXSI : XPath evaluator *)
3 (* Kim Nguyen (Kim.Nguyen@nicta.com.au) *)
4 (* Copyright NICTA 2008 *)
5 (* Distributed under the terms of the LGPL (see LICENCE) *)
6 (******************************************************************************)
7 (* maybe utf8 string... *)
12 (* special tag which denotes attribute nodes, should not be a valid
15 (* Likewise for strings *)
18 let compare : t -> t -> int = String.compare
21 let rec loop acc = function
23 | n -> loop (( acc lsl 6 ) + (acc lsl 16) - acc + (Char.code s.[n])) (n-1)
26 loop 0 ((String.length s)-1)
28 let equal x y = compare x y == 0
31 module HMap = Map.Make (struct type t = int let compare x y = x - y end)
35 let attribute = T.hash T.attribute
36 let pcdata = T.hash T.pcdata
37 let pool = ref HMap.empty
40 let hash = T.hash s in
41 pool := HMap.add hash s !pool
54 let hash = T.hash s in
56 let s' = HMap.find hash !pool
59 failwith (Printf.sprintf "hash conflict s1=%s, s2=%s, %i" s s' hash)
66 let compare x y = x - y
70 Format.fprintf fmt "%s" (
74 Not_found -> failwith (Printf.sprintf "%i not found!" t))
75 let to_string x = HMap.find x !pool
81 let attribute = T.attribute
83 external tag : string -> t = "%identity"
84 external clear_pool : unit -> unit = "%identity"
85 let compare = String.compare
87 let print fmt s = Format.fprintf fmt "%s" s
88 external to_string : t -> string = "%identity"
93 let _ = Callback.register "caml_hash_tag" tag