diff --git a/com.ibm.wala.core/src/com/ibm/wala/util/intset/IntSetUtil.java b/com.ibm.wala.core/src/com/ibm/wala/util/intset/IntSetUtil.java index b368649ec..773a91c86 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/util/intset/IntSetUtil.java +++ b/com.ibm.wala.core/src/com/ibm/wala/util/intset/IntSetUtil.java @@ -20,7 +20,26 @@ import com.ibm.wala.util.debug.Trace; */ public class IntSetUtil { - private static MutableIntSetFactory defaultIntSetFactory = new MutableSharedBitVectorIntSetFactory(); + public static final String INT_SET_FACTORY_CONFIG_PROPERTY_NAME = "com.ibm.wala.mutableIntSetFactory"; + + private static MutableIntSetFactory defaultIntSetFactory; + + static { + MutableIntSetFactory defaultFactory = new MutableSharedBitVectorIntSetFactory(); + if (System.getProperties().containsKey(INT_SET_FACTORY_CONFIG_PROPERTY_NAME)) { + try { + Class intSetFactoryClass = Class.forName(System.getProperty(INT_SET_FACTORY_CONFIG_PROPERTY_NAME)); + MutableIntSetFactory intSetFactory = (MutableIntSetFactory) intSetFactoryClass.newInstance(); + setDefaultIntSetFactory(intSetFactory); + } catch (Exception e) { + Trace.println("Cannot use int set factory " + System.getProperty(INT_SET_FACTORY_CONFIG_PROPERTY_NAME)); + setDefaultIntSetFactory(defaultFactory); + } + } else { + setDefaultIntSetFactory(defaultFactory); + } + assert defaultIntSetFactory != null; + } public static MutableIntSet make() { return defaultIntSetFactory.make(); @@ -44,6 +63,12 @@ public class IntSetUtil { return BimodalMutableIntSet.makeCopy(set); } else if (set instanceof MutableSharedBitVectorIntSet) { return new MutableSharedBitVectorIntSet((MutableSharedBitVectorIntSet) set); + } else if (set instanceof SemiSparseMutableIntSet) { + return new SemiSparseMutableIntSet((SemiSparseMutableIntSet) set); + } else if (set instanceof DebuggingMutableIntSet) { + MutableIntSet pCopy = makeMutableCopy(((DebuggingMutableIntSet)set).primaryImpl); + MutableIntSet sCopy = makeMutableCopy(((DebuggingMutableIntSet)set).secondaryImpl); + return new DebuggingMutableIntSet(pCopy, sCopy); } else { Assertions.UNREACHABLE(set.getClass().toString()); return null; diff --git a/com.ibm.wala.core/src/com/ibm/wala/util/intset/MutableSharedBitVectorIntSet.java b/com.ibm.wala.core/src/com/ibm/wala/util/intset/MutableSharedBitVectorIntSet.java index e2e3d08dc..5fd7c706a 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/util/intset/MutableSharedBitVectorIntSet.java +++ b/com.ibm.wala.core/src/com/ibm/wala/util/intset/MutableSharedBitVectorIntSet.java @@ -335,6 +335,8 @@ public class MutableSharedBitVectorIntSet implements MutableIntSet { return that.sameValue(makeSparseCopy()); } else if (that instanceof BitVectorIntSet) { return sameValue((BitVectorIntSet) that); + } else if (that instanceof SemiSparseMutableIntSet) { + return that.sameValue(this); } else { Assertions.UNREACHABLE("unexpected class " + that.getClass()); return false; diff --git a/com.ibm.wala.core/src/com/ibm/wala/util/intset/SemiSparseMutableIntSet.java b/com.ibm.wala.core/src/com/ibm/wala/util/intset/SemiSparseMutableIntSet.java index fa0fc6196..354060cd9 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/util/intset/SemiSparseMutableIntSet.java +++ b/com.ibm.wala.core/src/com/ibm/wala/util/intset/SemiSparseMutableIntSet.java @@ -22,6 +22,14 @@ public class SemiSparseMutableIntSet implements MutableIntSet { private int sparseInsertCount = 0; + public SemiSparseMutableIntSet() { + // this space intentionally left blank + } + + public SemiSparseMutableIntSet(SemiSparseMutableIntSet set) { + copySet(set); + } + private void fixAfterSparseInsert() { if (sparseInsertCount++ > SPARSE_INSERT_THRESHOLD) { sparseInsertCount = 0; @@ -58,7 +66,7 @@ public class SemiSparseMutableIntSet implements MutableIntSet { } if (maxOffset != -1) { - densePart = new OffsetBitVector(maxOffset, maxMax); + densePart = new OffsetBitVector(maxOffset, maxMax-maxOffset); sparseBits = sparsePart.intIterator(); while ((sparseBits.next()) != maxOffset) ; @@ -215,7 +223,7 @@ public class SemiSparseMutableIntSet implements MutableIntSet { public int next() { int next = densePart.nextSetBit(i + 1); - i = next + 1; + i = next; return next; } } @@ -488,4 +496,13 @@ public class SemiSparseMutableIntSet implements MutableIntSet { return change; } + + public String toString() { + StringBuffer sb = new StringBuffer("["); + if (densePart != null) { + sb.append("densePart: ").append(densePart.toString()).append(" "); + } + sb.append("sparsePart: ").append(sparsePart.toString()).append("]"); + return sb.toString(); + } }