1 package polyglot.util; 2 3 4 public class BitVector 5 { 6 private int size; 7 private boolean[] bits; 8 9 public BitVector() 10 { 11 this( 32); 12 } 13 14 public BitVector( int initialSize) 15 { 16 size = initialSize; 17 bits = new boolean[ size]; 18 } 19 20 public final void setBit( int which, boolean value) 21 { 22 if( which >= size) { 23 size += 32; 24 boolean[] newBits = new boolean[ size ]; 25 for( int i = 0; i < bits.length; i++) 26 newBits[i] = bits[i]; 27 bits = newBits; 28 } 29 30 bits[ which] = value; 31 } 32 33 public final boolean getBit( int which) 34 { 35 if( which >= size) { 36 return false; 37 } 38 else { 39 return bits[ which]; 40 } 41 } 42 } 43 44 | Popular Tags |