static void | store(java.util.Vector keyList, java.util.Vector valueList, long key, java.lang.Object value)Support method. Maintains a list, valueList, where each element in
the list has a corresponding key (of type Long) stored in keyList.
This method inserts "value" into "valueList" with the following
postconditions:
- keyList.size() == valueList.size()
- keyList[i] corresponds to valueList[i] (0 <= i < keyList.size())
- keyList is in ascending order of keys
- keyList contains key
- valueList contains value
- key corresponds to value
The following are preconditions:
- keyList.size() == valueList.size()
- keyList[i] corresponds to valueList[i] (0 <= i < keyList.size())
- keyList is in ascending order of keys
In order to maintain the arrays correctly, the objects passed as keyList
and valueList should only be modified by this method.
Preconditions are not verified by this method.
// do a binary chop search for the index before which to
// insert value
int lowerBound = 0;
int upperBound = keyList.size();
while (lowerBound != upperBound) {
int index = lowerBound + (upperBound - lowerBound) / 2;
long indexKey =
((Long) keyList.elementAt(index)).longValue();
if (indexKey > key) {
if (index == upperBound) {
upperBound --;
} else {
upperBound = index;
}
} else {
if (index == lowerBound) {
lowerBound ++;
} else {
lowerBound = index;
}
}
}
keyList.insertElementAt(new Long(key), lowerBound);
valueList.insertElementAt(value, lowerBound);
|