]> matita.cs.unibo.it Git - helm.git/blob - components/ng_kernel/nUri.ml
tagged 0.5.0-rc1
[helm.git] / components / ng_kernel / nUri.ml
1 type uri = int * string (* shareno, URI *)
2
3 let string_of_uri (_, uri) = uri;;
4
5 module OrderedStrings =
6  struct
7   type t = string
8   let compare (s1 : t) (s2 : t) = compare s1 s2
9  end
10 ;;
11
12 module MapStringsToUri = Map.Make(OrderedStrings);;
13
14 let set_of_uri = ref MapStringsToUri.empty;;
15
16 let uri_of_string = 
17   let counter = ref 0 in 
18   let c () = incr counter; !counter in 
19 fun s ->
20   try MapStringsToUri.find s !set_of_uri
21   with Not_found ->
22     let new_uri = c(), s in
23     set_of_uri := MapStringsToUri.add s new_uri !set_of_uri;
24     new_uri
25 ;;
26
27 let eq = (==);;
28 let compare (n1,_) (n2,_) = n2 - n1;;
29
30 module HT = struct
31         type t = uri
32         let equal = eq
33         let compare = compare
34         let hash (n,_) = n;;
35 end;;
36
37 module UriHash = Hashtbl.Make(HT);;
38
39 let ouri_of_nuri u = UriManager.uri_of_string (string_of_uri u);;
40 let nuri_of_ouri o = uri_of_string (UriManager.string_of_uri o);;
41