changes.
[IRC.git] / Robust / src / Util / Lattice.java
index bc024cfad9cd95f58d7b06bea451823bb879915b..16c8936940414b957c8a51d44ccd690e5e5f6e1a 100644 (file)
@@ -3,6 +3,7 @@ package Util;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Set;
 
 public class Lattice<T> {
@@ -19,6 +20,7 @@ public class Lattice<T> {
     this.bottom = bottom;
 
     table.put(top, new HashSet<T>());
+    table.put(bottom, new HashSet<T>());
 
   }
 
@@ -34,6 +36,10 @@ public class Lattice<T> {
     return table.keySet();
   }
 
+  public Map<T, Set<T>> getTable() {
+    return table;
+  }
+
   public boolean put(T key) {
     if (table.containsKey(key)) {
       return false;
@@ -66,7 +72,7 @@ public class Lattice<T> {
       size++;
       s.add(value);
 
-      if (!table.containsKey(value)) {
+      if ((!table.containsKey(value)) && (!value.equals(bottom))) {
         Set<T> lowerNeighbor = new HashSet<T>();
         lowerNeighbor.add(bottom);
         table.put(value, lowerNeighbor);
@@ -150,6 +156,13 @@ public class Lattice<T> {
 
   public boolean isGreaterThan(T a, T b) {
 
+    Set<T> visited = new HashSet<T>();
+    return isGreaterThan(a, b, visited);
+
+  }
+
+  public boolean isGreaterThan(T a, T b, Set<T> visited) {
+
     if (a.equals(b)) {
       return false;
     }
@@ -180,7 +193,10 @@ public class Lattice<T> {
       boolean reachable = false;
       for (Iterator<T> iterator = neighborSet.iterator(); iterator.hasNext();) {
         T neighbor = iterator.next();
-        reachable = reachable || isGreaterThan(neighbor, b);
+        if (!visited.contains(neighbor)) {
+          visited.add(neighbor);
+          reachable = reachable || isGreaterThan(neighbor, b, visited);
+        }
       }
       return reachable;
     }