checkpoint
[sbp.git] / src / edu / berkeley / sbp / GSS.java
index 2154731..02f521e 100644 (file)
@@ -159,33 +159,27 @@ class GSS {
         }
 
         public void inhibit(int p, Sequence s) {
+            if (inhibited.contains(p, s)) return;
+            inhibited.add(p, s);
             if (s.hated!=null)
                 for(Sequence s2 : s.hated)
-                    inhibited.remove(p, s2);
+                    uninhibit(p, s2);
+            if (s.needed!=null)
+                for(Sequence s2 : s.needed)
+                    if (performed.contains(p, s2))
+                        throw new Reset();
+            if (performed.contains(p, s)) throw new Reset();
         }
 
-        public void uninhibit(Position r, int p) {
-            if (r.owner().hated == null) return;
-            // remember that dead states are still allowed to shift -- just not allowed to reduce
-            boolean reset = false;
-            for(Sequence seq : r.owner().hated) {
-                if (performed.contains(p,seq)) {
+        public void uninhibit(Position r, int p) { uninhibit(p, r.owner()); }
+        public void uninhibit(int p, Sequence s) {
+            if (s.hated != null)
+                for(Sequence seq : s.hated)
                     inhibit(p, seq);
-                    //System.out.println("\nresetting due to " + r.owner() + " killing " + seq);
-                    //inhibited.clear();
-                    inhibited.add(p, seq);
-                    //inhibited = new HashMapBag<Integer,Sequence>();
-                    reset = true;
-                    resets++;
-                    throw new Reset();
-                }
-                inhibited.add(p, seq);
-                expectedInhibit.remove(p, seq);
-            }
         }
         
         /** perform all reduction operations */
-        public void reduce() throws ParseFailed{
+        public void reduce() throws ParseFailed {
             try {
                 reducing = true;
                 if (reducing_list==null || reducing_list.length < hash.size())
@@ -202,11 +196,18 @@ class GSS {
                     reducing_list[i] = null;
                     n.performReductions();
                 }
+                /*
                 if (expectedInhibit.size() > 0) {
                     inhibited.removeAll(expectedInhibit);
                     System.out.println("\n!!!!\n");
                     throw new Reset();
                 }
+                */
+                if (reset) {
+                    reset = false;
+                    resets++;
+                    throw new Reset();
+                }                
             } catch (Reset r) {
                 reset();
                 reduce();