added equals() and hashCode() to BitVector
[fleet.git] / src / edu / berkeley / fleet / api / BitVector.java
index e7b3061..c883b3b 100644 (file)
@@ -48,6 +48,24 @@ public class BitVector {
     public void setImmutable() {
         immutable = true;
     }
+
+    public int hashCode() {
+        int ret = 0;
+        for(int i=0; i<length(); i++)
+            if (get(i))
+                ret ^= (1L << (i % 32));
+        return ret;
+    }
+
+    public boolean equals(Object o) {
+        if (o==null || !(o instanceof BitVector)) return false;
+        BitVector bv = (BitVector)o;
+        if (bv.bits.length != bits.length) return false;
+        for(int i=0; i<bits.length; i++)
+            if (bits[i] != bv.bits[i])
+                return false;
+        return true;
+    }
 }