* complement number using the number of bits allocated in the
* BitVector.
*/
-public class BitVector {
+public class BitVector implements DeferredBitVector {
private final boolean[] bits;
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");
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;
+ }
}