allow choice of int set factory with system property
bug fixes to semi sparse int sets git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@526 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
370a88e56d
commit
fbe230b164
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue