From 34b02ee2b293ff779eb1231b189ee38ea747c6ff Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Wed, 1 Jun 2005 11:05:19 +0000 Subject: [PATCH] fixed classical non-C programmer misunderstooding of pointers --- helm/ocaml/urimanager/uriManager.ml | 39 ++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/helm/ocaml/urimanager/uriManager.ml b/helm/ocaml/urimanager/uriManager.ml index a4d260485..0697fb73b 100644 --- a/helm/ocaml/urimanager/uriManager.ml +++ b/helm/ocaml/urimanager/uriManager.ml @@ -33,10 +33,9 @@ type uri = string array;; let eq uri1 uri2 = - uri1 == uri2 + uri1 == uri2 ;; - let string_of_uri uri = match uri.(Array.length uri - 1) with | "" -> @@ -45,7 +44,6 @@ let string_of_uri uri = String.concat "#" [ uri.(Array.length uri - 3); uri.(Array.length uri - 1) ] - let name_of_uri uri = uri.(Array.length uri - 2);; let buri_of_uri uri = uri.(Array.length uri - 4);; let depth_of_uri uri = Array.length uri - 3;; @@ -65,6 +63,24 @@ module SetOfStrings = Map.Make(OrderedStrings);; let set_of_uri = ref SetOfStrings.empty;; let set_of_prefixes = ref SetOfStrings.empty;; + +(* hash conses an uri *) +let add_to_uriset ?suri uri = + let lookup_suri suri = + try + SetOfStrings.find suri !set_of_uri + with Not_found -> assert false + in + let suri = + match suri with + | None -> string_of_uri uri + | Some suri -> suri + in + if not(SetOfStrings.mem suri !set_of_uri) then + set_of_uri := SetOfStrings.add suri uri !set_of_uri; + lookup_suri suri + + (* similar to uri_of_string, but used for prefixes of uris *) let normalize prefix = try @@ -116,17 +132,16 @@ let uri_of_string str = with Not_found -> let uri = Array.of_list (mk_prefixes base xpointer) in - set_of_uri := SetOfStrings.add str uri !set_of_uri ; - uri + add_to_uriset ~suri:str uri ;; let strip_xpointer uri = let stripped_uri = Array.copy uri in stripped_uri.(Array.length uri - 1) <- ""; (* reset xpointer field *) - let stripped_uri_str = string_of_uri stripped_uri in - set_of_uri := SetOfStrings.add stripped_uri_str stripped_uri !set_of_uri; - stripped_uri + let suri = string_of_uri stripped_uri in + add_to_uriset ~suri stripped_uri + let cicuri_of_uri uri = let completeuri = string_of_uri uri in let newcompleteuri = @@ -138,7 +153,7 @@ let cicuri_of_uri uri = else let newuri = Array.copy uri in newuri.(Array.length uri - 3) <- newcompleteuri ; - newuri + add_to_uriset newuri ;; let annuri_of_uri uri = @@ -148,7 +163,7 @@ let annuri_of_uri uri = else let newuri = Array.copy uri in newuri.(Array.length uri - 3) <- completeuri ^ ".ann" ; - newuri + add_to_uriset newuri ;; let uri_is_annuri uri = @@ -160,7 +175,7 @@ let bodyuri_of_uri uri = if Str.string_match (Str.regexp ".*\\.con$") (string_of_uri uri) 0 then let newuri = Array.copy uri in newuri.(Array.length uri - 3) <- struri ^ ".body" ; - Some newuri + Some (add_to_uriset newuri) else None ;; @@ -169,7 +184,7 @@ let innertypesuri_of_uri uri = let cicuri = cicuri_of_uri uri in let newuri = Array.copy cicuri in newuri.(Array.length cicuri - 3) <- (string_of_uri cicuri) ^ ".types" ; - newuri + add_to_uriset newuri ;; type uriref = uri * (int list) -- 2.39.2