/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* (C) Copyright Taligent, Inc. 1996,1997 - All Rights Reserved
* (C) Copyright IBM Corp. 1996, 1997 - All Rights Reserved
*/
/** Simple internal class for doing hash mapping. Much, much faster than the
* standard Hashtable for integer to integer mappings,
* and doesn't require object creation.<br>
* If a key is not found, the defaultValue is returned.
* Note: the keys are limited to values above Integer.MIN_VALUE+1.<br>
*/
public final class IntHashtable {
public IntHashtable () {
initialize(3);
}
}
public int size() {
return count;
}
public boolean isEmpty() {
return count == 0;
}
if (count > highWaterMark) {
rehash();
}
++count;
}
}
}
--count;
if (count < lowWaterMark) {
rehash();
}
}
}
public int getDefaultValue() {
return defaultValue;
}
rehash();
}
return false;
}
return false;
}
return true;
}
public int hashCode() {
// NOTE: This function isn't actually used anywhere in this package, but it's here
// in case this class is ever used to make sure we uphold the invariants about
// hashCode() and equals()
// WARNING: This function hasn't undergone rigorous testing to make sure it actually
// gives good distribution. We've eyeballed the results, and they appear okay, but
// you copy this algorithm (or these seed and multiplier values) at your own risk.
// --rtg 8/17/99
// this line just scrambles the bits as each value is added into the
// has value. This helps to make sure we affect all the bits and that
// the same values in a different order will produce a different hash value
}
}
return result;
}
throws CloneNotSupportedException {
return result;
}
// =======================PRIVATES============================
// the tables have to have prime-number lengths. Rather than compute
// primes, we just keep a table, with the current index we are using.
private int primeIndex;
// highWaterFactor determines the maximum number of elements before
// a rehash. Can be tuned for different performance/storage characteristics.
private int highWaterMark;
// lowWaterFactor determines the minimum number of elements before
// a rehash. Can be tuned for different performance/storage characteristics.
private int lowWaterMark;
private int count;
// we use two arrays to minimize allocations
private int[] values;
private int[] keyList;
if (primeIndex < 0) {
primeIndex = 0;
// throw new java.util.IllegalArgumentError();
}
this.primeIndex = primeIndex;
values = new int[initialSize];
keyList = new int[initialSize];
for (int i = 0; i < initialSize; ++i) {
values[i] = defaultValue;
}
count = 0;
}
private void rehash() {
int[] oldkeyList = keyList;
int newPrimeIndex = primeIndex;
if (count > highWaterMark) {
} else if (count < lowWaterMark) {
newPrimeIndex -= 2;
}
int key = oldkeyList[i];
if (key > MAX_UNUSED) {
}
}
}
++count;
}
}
if (key <= MAX_UNUSED)
throw new IllegalArgumentException("key can't be less than 0xFFFFFFFE");
while (true) {
return index;
// ignore
if (firstDeleted >= 0) {
}
return index;
}
++jump;
}
if (index == firstDeleted) {
// We've searched all entries for the given key.
return index;
}
}
}
int i;
break;
}
}
return (i == 0) ? 0 : (i - 1);
}
// This list is the result of buildList below. Can be tuned for different
// performance/storage characteristics.
private static final int[] PRIMES = {
17, 37, 67, 131, 257,
521, 1031, 2053, 4099, 8209, 16411, 32771, 65537,
131101, 262147, 524309, 1048583, 2097169, 4194319, 8388617, 16777259,
33554467, 67108879, 134217757, 268435459, 536870923, 1073741827, 2147483647
};
}