add IntVector.getMaxIndex()
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1821 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
3efa160e7a
commit
516adf98aa
|
@ -19,15 +19,13 @@ import com.ibm.wala.util.debug.VerboseAction;
|
||||||
*/
|
*/
|
||||||
public interface IntVector extends VerboseAction {
|
public interface IntVector extends VerboseAction {
|
||||||
|
|
||||||
/**
|
|
||||||
* @param x
|
|
||||||
*/
|
|
||||||
int get(int x);
|
int get(int x);
|
||||||
|
|
||||||
/**
|
|
||||||
* @param x
|
|
||||||
* @param value
|
|
||||||
*/
|
|
||||||
void set(int x, int value);
|
void set(int x, int value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return max i s.t set(i) was called.
|
||||||
|
*/
|
||||||
|
public abstract int getMaxIndex();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,14 +25,13 @@ public class SimpleIntVector implements IntVector {
|
||||||
private final static float GROWTH_FACTOR = 1.5f;
|
private final static float GROWTH_FACTOR = 1.5f;
|
||||||
|
|
||||||
private final static int INITIAL_SIZE = 1;
|
private final static int INITIAL_SIZE = 1;
|
||||||
|
|
||||||
|
int maxIndex = -1;
|
||||||
|
|
||||||
int[] store;
|
int[] store;
|
||||||
|
|
||||||
final int defaultValue;
|
final int defaultValue;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param defaultValue
|
|
||||||
*/
|
|
||||||
public SimpleIntVector(int defaultValue) {
|
public SimpleIntVector(int defaultValue) {
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
store = new int[getInitialSize()];
|
store = new int[getInitialSize()];
|
||||||
|
@ -74,6 +73,7 @@ public class SimpleIntVector implements IntVector {
|
||||||
if (Assertions.verifyAssertions) {
|
if (Assertions.verifyAssertions) {
|
||||||
Assertions._assert(x >= 0);
|
Assertions._assert(x >= 0);
|
||||||
}
|
}
|
||||||
|
maxIndex = Math.max(maxIndex,x);
|
||||||
if (value == defaultValue) {
|
if (value == defaultValue) {
|
||||||
if (x >= store.length) {
|
if (x >= store.length) {
|
||||||
return;
|
return;
|
||||||
|
@ -121,5 +121,9 @@ public class SimpleIntVector implements IntVector {
|
||||||
int count = count1;
|
int count = count1;
|
||||||
return (double) count / (double) store.length;
|
return (double) count / (double) store.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxIndex() {
|
||||||
|
return maxIndex;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -26,6 +26,7 @@ public class SparseIntVector implements IntVector {
|
||||||
|
|
||||||
private final static int INITIAL_SIZE = 5;
|
private final static int INITIAL_SIZE = 5;
|
||||||
private final double EXPANSION = 1.5;
|
private final double EXPANSION = 1.5;
|
||||||
|
int maxIndex = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if indices[i] = x, then data[i] == get(x)
|
* if indices[i] = x, then data[i] == get(x)
|
||||||
|
@ -57,6 +58,7 @@ public class SparseIntVector implements IntVector {
|
||||||
* @see com.ibm.wala.util.intset.IntVector#set(int, int)
|
* @see com.ibm.wala.util.intset.IntVector#set(int, int)
|
||||||
*/
|
*/
|
||||||
public void set(int x, int value) {
|
public void set(int x, int value) {
|
||||||
|
maxIndex = Math.max(maxIndex,x);
|
||||||
int index = indices.getIndex(x);
|
int index = indices.getIndex(x);
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
indices.add(x);
|
indices.add(x);
|
||||||
|
@ -84,6 +86,10 @@ public class SparseIntVector implements IntVector {
|
||||||
Trace.println(getClass() + " stats: ");
|
Trace.println(getClass() + " stats: ");
|
||||||
Trace.println("data.length " + data.length);
|
Trace.println("data.length " + data.length);
|
||||||
Trace.println("indices.size() " + indices.size());
|
Trace.println("indices.size() " + indices.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getMaxIndex() {
|
||||||
|
return maxIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -25,6 +25,8 @@ public class TwoLevelIntVector implements IntVector {
|
||||||
private static final int PAGE_SIZE = 4096;
|
private static final int PAGE_SIZE = 4096;
|
||||||
|
|
||||||
private static final int LOG_PAGE_SIZE = Logs.log2(PAGE_SIZE);
|
private static final int LOG_PAGE_SIZE = Logs.log2(PAGE_SIZE);
|
||||||
|
|
||||||
|
int maxIndex = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array of IntVector: data.get(i) holds data[i*PAGE_SIZE] ...
|
* Array of IntVector: data.get(i) holds data[i*PAGE_SIZE] ...
|
||||||
|
@ -72,6 +74,7 @@ public class TwoLevelIntVector implements IntVector {
|
||||||
* @see com.ibm.wala.util.intset.IntVector#set(int, int)
|
* @see com.ibm.wala.util.intset.IntVector#set(int, int)
|
||||||
*/
|
*/
|
||||||
public void set(int x, int value) {
|
public void set(int x, int value) {
|
||||||
|
maxIndex = Math.max(maxIndex,x);
|
||||||
int page = getPageNumber(x);
|
int page = getPageNumber(x);
|
||||||
IntVector v = findOrCreatePage(page);
|
IntVector v = findOrCreatePage(page);
|
||||||
int localX = toLocalIndex(x, page);
|
int localX = toLocalIndex(x, page);
|
||||||
|
@ -101,5 +104,10 @@ public class TwoLevelIntVector implements IntVector {
|
||||||
Trace.println("stats of " + getClass());
|
Trace.println("stats of " + getClass());
|
||||||
Trace.println("data: size = " + data.size());
|
Trace.println("data: size = " + data.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getMaxIndex() {
|
||||||
|
return maxIndex;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue