type uri = string;; let eq uri1 uri2 = uri1 == uri2 ;; let string_of_uri uri = uri;; let name_of_uri uri = let l = Str.split (Str.regexp "/") uri in let name_suf = List.nth l (List.length l - 1) in List.hd (Str.split (Str.regexp "\.") name_suf) ;; let depth_of_uri uri = List.length (Str.split (Str.regexp "/") uri) - 2 ;; module OrderedStrings = struct type t = string let compare (s1 : t) (s2 : t) = compare s1 s2 end ;; module SetOfStrings = Map.Make(OrderedStrings);; (* Invariant: the map is the identity function, *) (* i.e. (SetOfStrings.find str !set_of_uri) == str *) let set_of_uri = ref SetOfStrings.empty;; let uri_of_string str = try SetOfStrings.find str !set_of_uri with Not_found -> set_of_uri := SetOfStrings.add str str !set_of_uri ; str ;;