From 516adf98aa9f295621facaa6d3ff426be0249e91 Mon Sep 17 00:00:00 2001 From: sjfink Date: Thu, 4 Oct 2007 15:47:15 +0000 Subject: [PATCH] add IntVector.getMaxIndex() git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1821 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../src/com/ibm/wala/util/intset/IntVector.java | 12 +++++------- .../com/ibm/wala/util/intset/SimpleIntVector.java | 10 +++++++--- .../com/ibm/wala/util/intset/SparseIntVector.java | 8 +++++++- .../com/ibm/wala/util/intset/TwoLevelIntVector.java | 8 ++++++++ 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/com.ibm.wala.core/src/com/ibm/wala/util/intset/IntVector.java b/com.ibm.wala.core/src/com/ibm/wala/util/intset/IntVector.java index 0e5cce54a..6060a1bc0 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/util/intset/IntVector.java +++ b/com.ibm.wala.core/src/com/ibm/wala/util/intset/IntVector.java @@ -19,15 +19,13 @@ import com.ibm.wala.util.debug.VerboseAction; */ public interface IntVector extends VerboseAction { - /** - * @param x - */ int get(int x); - /** - * @param x - * @param value - */ void set(int x, int value); + + /** + * @return max i s.t set(i) was called. + */ + public abstract int getMaxIndex(); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/util/intset/SimpleIntVector.java b/com.ibm.wala.core/src/com/ibm/wala/util/intset/SimpleIntVector.java index ef82d9601..c72729a69 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/util/intset/SimpleIntVector.java +++ b/com.ibm.wala.core/src/com/ibm/wala/util/intset/SimpleIntVector.java @@ -25,14 +25,13 @@ public class SimpleIntVector implements IntVector { private final static float GROWTH_FACTOR = 1.5f; private final static int INITIAL_SIZE = 1; + + int maxIndex = -1; int[] store; final int defaultValue; - /** - * @param defaultValue - */ public SimpleIntVector(int defaultValue) { this.defaultValue = defaultValue; store = new int[getInitialSize()]; @@ -74,6 +73,7 @@ public class SimpleIntVector implements IntVector { if (Assertions.verifyAssertions) { Assertions._assert(x >= 0); } + maxIndex = Math.max(maxIndex,x); if (value == defaultValue) { if (x >= store.length) { return; @@ -121,5 +121,9 @@ public class SimpleIntVector implements IntVector { int count = count1; return (double) count / (double) store.length; } + + public int getMaxIndex() { + return maxIndex; + } } \ No newline at end of file diff --git a/com.ibm.wala.core/src/com/ibm/wala/util/intset/SparseIntVector.java b/com.ibm.wala.core/src/com/ibm/wala/util/intset/SparseIntVector.java index 7b0d16571..0ad67c86b 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/util/intset/SparseIntVector.java +++ b/com.ibm.wala.core/src/com/ibm/wala/util/intset/SparseIntVector.java @@ -26,6 +26,7 @@ public class SparseIntVector implements IntVector { private final static int INITIAL_SIZE = 5; private final double EXPANSION = 1.5; + int maxIndex = -1; /** * 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) */ public void set(int x, int value) { + maxIndex = Math.max(maxIndex,x); int index = indices.getIndex(x); if (index == -1) { indices.add(x); @@ -84,6 +86,10 @@ public class SparseIntVector implements IntVector { Trace.println(getClass() + " stats: "); Trace.println("data.length " + data.length); Trace.println("indices.size() " + indices.size()); - + } + + + public int getMaxIndex() { + return maxIndex; } } \ No newline at end of file diff --git a/com.ibm.wala.core/src/com/ibm/wala/util/intset/TwoLevelIntVector.java b/com.ibm.wala.core/src/com/ibm/wala/util/intset/TwoLevelIntVector.java index dbb9c8471..6caa0ca56 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/util/intset/TwoLevelIntVector.java +++ b/com.ibm.wala.core/src/com/ibm/wala/util/intset/TwoLevelIntVector.java @@ -25,6 +25,8 @@ public class TwoLevelIntVector implements IntVector { private static final int PAGE_SIZE = 4096; 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] ... @@ -72,6 +74,7 @@ public class TwoLevelIntVector implements IntVector { * @see com.ibm.wala.util.intset.IntVector#set(int, int) */ public void set(int x, int value) { + maxIndex = Math.max(maxIndex,x); int page = getPageNumber(x); IntVector v = findOrCreatePage(page); int localX = toLocalIndex(x, page); @@ -101,5 +104,10 @@ public class TwoLevelIntVector implements IntVector { Trace.println("stats of " + getClass()); Trace.println("data: size = " + data.size()); } + + + public int getMaxIndex() { + return maxIndex; + } } \ No newline at end of file