add BitVector.get(int,int)
authormegacz <adam@megacz.com>
Tue, 30 Dec 2008 01:42:58 +0000 (17:42 -0800)
committermegacz <adam@megacz.com>
Tue, 30 Dec 2008 01:42:58 +0000 (17:42 -0800)
src/edu/berkeley/fleet/api/BitVector.java

index d54b2bc..9c111b6 100644 (file)
@@ -69,6 +69,18 @@ public class BitVector {
         return bits[bit];
     }
 
+    /** get a sub-BitVector of a BitVector */
+    public BitVector get(int high, int low) {
+        if (low < 0 || high < 0 || high>low)
+            throw new RuntimeException("attempt to invoke BitVector("+high+","+low+")");
+        if (high > length()-1)
+            throw new RuntimeException("attempt to invoke BitVector("+high+","+low+") on an "+length()+"-bit BitVector");
+        BitVector ret = new BitVector(1+high-low);
+        for(int i=low; i<=high; i++)
+            ret.set(i-low, get(i));
+        return ret;
+    }
+
     public String toString() {
         StringBuffer ret = new StringBuffer();
         ret.append(length()+"");