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 + ")";
|
return super.toString() + "(offset:" + offset + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void growCapacity(float fraction) {
|
||||||
|
expand(offset, (int) fraction*(bits.length<<LOG_BITS_PER_UNIT));
|
||||||
|
}
|
||||||
|
|
||||||
public int getOffset() {
|
public int getOffset() {
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,7 @@ public class SemiSparseMutableIntSet implements MutableIntSet {
|
||||||
int newOffset = -1;
|
int newOffset = -1;
|
||||||
int newCount = -1;
|
int newCount = -1;
|
||||||
int newLength = -1;
|
int newLength = -1;
|
||||||
|
boolean swallowTail = false;
|
||||||
|
|
||||||
// push stuff just below dense part into it, if it saves space
|
// push stuff just below dense part into it, if it saves space
|
||||||
if (thisBit < densePart.getOffset()) {
|
if (thisBit < densePart.getOffset()) {
|
||||||
|
@ -145,8 +146,11 @@ public class SemiSparseMutableIntSet implements MutableIntSet {
|
||||||
thisBit = sparseBits.next();
|
thisBit = sparseBits.next();
|
||||||
count++;
|
count++;
|
||||||
bits = (thisBit + 1 - densePart.length());
|
bits = (thisBit + 1 - densePart.length());
|
||||||
newLength = ((32*count) > bits) ? thisBit : newLength;
|
if ((32*count) > bits) {
|
||||||
newCount = ((32*count) > bits) ? count : newCount;
|
newLength = thisBit;
|
||||||
|
newCount = count;
|
||||||
|
swallowTail = ! sparseBits.hasNext();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (newLength > -1) {
|
if (newLength > -1) {
|
||||||
moveCount += newCount;
|
moveCount += newCount;
|
||||||
|
@ -167,7 +171,16 @@ public class SemiSparseMutableIntSet implements MutableIntSet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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]);
|
sparsePart.remove(bits[i]);
|
||||||
densePart.set(bits[i]);
|
densePart.set(bits[i]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue