ntaz.patch 1.47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
diff --git a/src/LRijkstra.ml b/src/LRijkstra.ml
index 0d65fbd..92701fe 100644
--- a/src/LRijkstra.ml
+++ b/src/LRijkstra.ml
@@ -408,17 +408,18 @@ module E : sig
 
 end = struct
 
-  (* For now, we implement a mapping of [s, nt, a, z] to [w]. *)
+  (* For now, we implement a mapping of [s] to [nt, a, z] to [w]. *)
+
+  let pack nt a z : int =
+    (Nonterminal.n2i nt lsl 16) lor
+    (Terminal.t2i a lsl 8) lor
+    (Terminal.t2i z)
 
   module M =
     MySet.Make(struct
-      type t = Nonterminal.t * Terminal.t * Terminal.t * W.word
-      let compare (nt1, a1, z1, _w1) (nt2, a2, z2, _w2) =
-        let c = Nonterminal.compare nt1 nt2 in
-        if c <> 0 then c else
-        let c = Terminal.compare a1 a2 in
-        if c <> 0 then c else
-        Terminal.compare z1 z2
+      type t = int * W.word
+      let compare (ntaz1, _w1) (ntaz2, _w2) =
+        Pervasives.compare (ntaz1 : int) ntaz2
     end)
 
   let table =
@@ -430,7 +431,7 @@ end = struct
     let i = Lr1.number s in
     let m = table.(i) in
     let a = W.first w z in
-    let m' = M.add (nt, a, z, w) m in
+    let m' = M.add (pack nt a z, w) m in
     m != m' && begin
       incr count;
       table.(i) <- m';
@@ -441,8 +442,8 @@ end = struct
     let i = Lr1.number s in
     let m = table.(i) in
     let dummy = W.epsilon in
-    match M.find (nt, a, z, dummy) m with
-    | (_, _, _, w) -> f w
+    match M.find (pack nt a z, dummy) m with
+    | (_, w) -> f w
     | exception Not_found -> ()
 
   let verbose () =