optimize resizing of dense parts of SemiSparseMutableIntSets
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@562 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
d33489f2a8
commit
5b97b9b888
|
@ -89,6 +89,10 @@ public final class OffsetBitVector extends BitVectorBase<OffsetBitVector> {
|
|||
return super.toString() + "(offset:" + offset + ")";
|
||||
}
|
||||
|
||||
void growCapacity(float fraction) {
|
||||
expand(offset, (int) fraction*(bits.length<<LOG_BITS_PER_UNIT));
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
|
|
@ -96,6 +96,7 @@ public class SemiSparseMutableIntSet implements MutableIntSet {
|
|||
int newOffset = -1;
|
||||
int newCount = -1;
|
||||
int newLength = -1;
|
||||
boolean swallowTail = false;
|
||||
|
||||
// push stuff just below dense part into it, if it saves space
|
||||
if (thisBit < densePart.getOffset()) {
|
||||
|
@ -145,8 +146,11 @@ public class SemiSparseMutableIntSet implements MutableIntSet {
|
|||
thisBit = sparseBits.next();
|
||||
count++;
|
||||
bits = (thisBit + 1 - densePart.length());
|
||||
newLength = ((32*count) > bits) ? thisBit : newLength;
|
||||
newCount = ((32*count) > bits) ? count : newCount;
|
||||
if ((32*count) > bits) {
|
||||
newLength = thisBit;
|
||||
newCount = count;
|
||||
swallowTail = ! sparseBits.hasNext();
|
||||
}
|
||||
}
|
||||
if (newLength > -1) {
|
||||
moveCount += newCount;
|
||||
|
@ -166,8 +170,17 @@ public class SemiSparseMutableIntSet implements MutableIntSet {
|
|||
bits[index++] = bit;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < moveCount; i++) {
|
||||
|
||||
if (swallowTail) {
|
||||
int base = densePart.getOffset();
|
||||
int currentSize = densePart.length() - base;
|
||||
float newSize = 1.1f * (bits[index-1] - base);
|
||||
float fraction = newSize / (float)currentSize;
|
||||
assert fraction > 1;
|
||||
densePart.growCapacity(fraction);
|
||||
}
|
||||
|
||||
for (int i = index-1; i >= 0; i--) {
|
||||
sparsePart.remove(bits[i]);
|
||||
densePart.set(bits[i]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue