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)
36 let attribute = T.hash T.attribute
37 let pcdata = T.hash T.pcdata
39 let pool = ref HMap.empty
43 let hash = T.hash s in
44 pool := HMap.add hash s !pool
58 let hash = T.hash s in
60 let s' = HMap.find hash !pool
63 failwith (Printf.sprintf "hash conflict s1=%s, s2=%s, %i" s s' hash)
70 let compare x y = x - y
74 Format.fprintf fmt "%s" (
78 Not_found -> failwith (Printf.sprintf "%i not found!" t))
79 let to_string x = HMap.find x !pool
85 let attribute = T.attribute
87 external tag : string -> t = "%identity"
88 external clear_pool : unit -> unit = "%identity"
90 let compare = String.compare
92 let print fmt s = Format.fprintf fmt "%s" s
93 external to_string : t -> string = "%identity"