1 19 20 package soot.util; 21 22 public final class SharedBitSet { 23 BitVector value; 24 boolean own = true; 25 public SharedBitSet(int i) { 26 value = new BitVector( i ); 27 } 28 public SharedBitSet() { 29 this(32); 30 } 31 private void acquire() { 32 if( own ) return; 33 own = true; 34 value = (BitVector) value.clone(); 35 } 36 private void canonicalize() { 37 value = SharedBitSetCache.v().canonicalize( value ); 38 own = false; 39 } 40 public boolean set(int bit) { 41 acquire(); 42 return value.set(bit); 43 } 44 public void clear(int bit) { 45 acquire(); 46 value.clear(bit); 47 } 48 public boolean get(int bit) { 49 return value.get(bit); 50 } 51 public void and( SharedBitSet other ) { 52 if( own ) { 53 value.and( other.value ); 54 } else { 55 value = BitVector.and( value, other.value ); 56 own = true; 57 } 58 canonicalize(); 59 } 60 public void or( SharedBitSet other ) { 61 if( own ) { 62 value.or( other.value ); 63 } else { 64 value = BitVector.or( value, other.value ); 65 own = true; 66 } 67 canonicalize(); 68 } 69 public boolean orAndAndNot( SharedBitSet orset, SharedBitSet andset, SharedBitSet andnotset ) { 70 acquire(); 71 boolean ret = value.orAndAndNot( orset.value, andset.value, andnotset.value ); 72 canonicalize(); 73 return ret; 74 } 75 public boolean orAndAndNot( SharedBitSet orset, BitVector andset, SharedBitSet andnotset ) { 76 acquire(); 77 boolean ret = value.orAndAndNot( orset.value, andset, 78 andnotset == null ? null : andnotset.value ); 79 canonicalize(); 80 return ret; 81 } 82 public BitSetIterator iterator() { 83 return value.iterator(); 84 } 85 public String toString() { 86 StringBuffer b = new StringBuffer (); 87 for( BitSetIterator it = iterator(); it.hasNext(); ) { 88 b.append( it.next() ); 89 b.append( "," ); 90 } 91 return b.toString(); 92 } 93 } 94 | Popular Tags |