add IS_INTERRUPTIBLE mask (sort of a hack)
[fleet.git] / src / edu / berkeley / fleet / api / BitVector.java
index 9c111b6..92cb6a0 100644 (file)
@@ -19,7 +19,7 @@ package edu.berkeley.fleet.api;
  *  complement number using the number of bits allocated in the
  *  BitVector.
  */
-public class BitVector {
+public class BitVector implements DeferredBitVector {
 
     private final boolean[] bits;
 
@@ -44,6 +44,14 @@ public class BitVector {
         return this;
     }
 
+    public BitVector set(BitVector bv) {
+        if (immutable) throw new RuntimeException("attempt to modify an immutable BitVector");
+        if (length()!=bv.length()) throw new RuntimeException("attempt to copy between BitVectors of unequal sizes");
+        for(int i=0; i<length(); i++)
+            set(i, bv.get(i));
+        return this;
+    }
+
     /** copy the low-order bits of the argument into this BitVector and sign extend; returns <tt>this</tt> */
     public BitVector setAndSignExtend(long value) {
         if (immutable) throw new RuntimeException("attempt to modify an immutable BitVector");
@@ -135,6 +143,37 @@ public class BitVector {
                 ret |= (1L << i);
         return ret;
     }
+
+    public BitVector getBitVector() {
+        return this;
+    }
+
+    public BitVector and(BitVector bv) {
+        if (bv.length() != this.length())
+            throw new RuntimeException("attempt to invoke BitVector.and() on BitVectors "+
+                                       "of mismatched size: this="+this+", bv="+bv);
+        BitVector ret = new BitVector(length());
+        for(int i=0; i<length(); i++)
+            ret.set(i, get(i) && bv.get(i));
+        return ret;
+    }
+
+    public BitVector or(BitVector bv) {
+        if (bv.length() != this.length())
+            throw new RuntimeException("attempt to invoke BitVector.or() on BitVectors "+
+                                       "of mismatched size: this="+this+", bv="+bv);
+        BitVector ret = new BitVector(length());
+        for(int i=0; i<length(); i++)
+            ret.set(i, get(i) || bv.get(i));
+        return ret;
+    }
+
+    public BitVector not() {
+        BitVector ret = new BitVector(length());
+        for(int i=0; i<length(); i++)
+            ret.set(i, !get(i));
+        return ret;
+    }
 }