]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_kernel/nUri.ml
New licence used uniformly everywhere.
[helm.git] / helm / software / components / ng_kernel / nUri.ml
1 (*
2     ||M||  This file is part of HELM, an Hypertextual, Electronic        
3     ||A||  Library of Mathematics, developed at the Computer Science     
4     ||T||  Department, University of Bologna, Italy.                     
5     ||I||                                                                
6     ||T||  HELM is free software; you can redistribute it and/or         
7     ||A||  modify it under the terms of the GNU General Public License   
8     \   /  version 2 or (at your option) any later version.      
9      \ /   This software is distributed as is, NO WARRANTY.     
10       V_______________________________________________________________ *)
11
12 (* $Id$ *)
13
14 type uri = int * string (* shareno, URI *)
15
16 let string_of_uri (_, uri) = uri;;
17
18 module OrderedStrings =
19  struct
20   type t = string
21   let compare (s1 : t) (s2 : t) = compare s1 s2
22  end
23 ;;
24
25 module MapStringsToUri = Map.Make(OrderedStrings);;
26
27 let set_of_uri = ref MapStringsToUri.empty;;
28
29 let uri_of_string = 
30   let counter = ref 0 in 
31   let c () = incr counter; !counter in 
32 fun s ->
33   try MapStringsToUri.find s !set_of_uri
34   with Not_found ->
35     let new_uri = c(), s in
36     set_of_uri := MapStringsToUri.add s new_uri !set_of_uri;
37     new_uri
38 ;;
39
40 let eq = (==);;
41 let compare (n1,_) (n2,_) = n2 - n1;;
42
43 module HT = struct
44         type t = uri
45         let equal = eq
46         let compare = compare
47         let hash (n,_) = n;;
48 end;;
49
50 module UriHash = Hashtbl.Make(HT);;
51
52 let ouri_of_nuri u = UriManager.uri_of_string (string_of_uri u);;
53 let nuri_of_ouri o = uri_of_string (UriManager.string_of_uri o);;
54