ocaml-lib / term.ml

Diff from to
 
 type id = int (* >0 for terms, <0 for idents *)
 
-let h_term2id : (string,id) Hashtbl.t = Hashtbl.create 100
-let h_ident2id : (string,id) Hashtbl.t = Hashtbl.create 100
+let h_s2id : (string,id) Hashtbl.t = Hashtbl.create 100
     
 let h_id2s : (id,string) Hashtbl.t = Hashtbl.create 100
 
-let term_exists s = Hashtbl.mem h_term2id s
+let exists s = Hashtbl.mem h_s2id s
 
-let ident_exists s = Hashtbl.mem h_ident2id s
-
-let term2id s =
-  try Hashtbl.find h_term2id s
+let s2id s =
+  try Hashtbl.find h_s2id s
   with Not_found ->
     incr cpt;
     let id = !cpt in
-    Hashtbl.add h_term2id s id;
-    Hashtbl.add h_id2s id s;
-    id
-
-let ident2id s =
-  try Hashtbl.find h_ident2id s
-  with Not_found ->
-    incr cpt;
-    let id = - !cpt in
-    Hashtbl.add h_ident2id s id;
+    Hashtbl.add h_s2id s id;
     Hashtbl.add h_id2s id s;
     id
 
 (* rename a term/ident *)
 let rename : int -> string -> unit =
   fun id s ->
-    if id > 0
-    then begin
-      assert (not (Hashtbl.mem h_term2id s));
-      let old_term = Hashtbl.find h_id2s id in
-      Hashtbl.remove h_term2id old_term;
-      Hashtbl.add h_term2id s id;
-      Hashtbl.replace h_id2s id s end
-    else begin
-      assert (not (Hashtbl.mem h_ident2id s));
-      let old_ident = Hashtbl.find h_id2s id in
-      Hashtbl.remove h_ident2id old_ident;
-      Hashtbl.add h_ident2id s id;
-      Hashtbl.replace h_id2s id s
-    end
+    assert (not (Hashtbl.mem h_s2id s));
+    let old_s = Hashtbl.find h_id2s id in
+    Hashtbl.remove h_s2id old_s;
+    Hashtbl.add h_s2id s id;
+    Hashtbl.replace h_id2s id s
 
 (* load and save *)
 
 let init () =
   cpt := 0;
   Hashtbl.clear h_id2s;
-  Hashtbl.clear h_term2id;
-  Hashtbl.clear h_ident2id;
+  Hashtbl.clear h_s2id;
   Hashtbl.clear tbl
 
 let load (t : data) =
   List.iter
     (fun (id,s) ->
       Hashtbl.add h_id2s id s;
-      if id > 0
-      then Hashtbl.add h_term2id s id
-      else Hashtbl.add h_ident2id s id)
+      Hashtbl.add h_s2id s id)
     t.id2s;
   List.iter
     (fun (id,x) ->
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.