* Hashtable of {char[] --> Object }
*/
public final class HashtableOfObject implements Cloneable {
-
+
// to avoid using Enumerations, walk the individual tables skipping nulls
public char[] keyTable[];
+
public Object valueTable[];
public int elementSize; // number of elements in the table
+
int threshold;
public HashtableOfObject() {
public HashtableOfObject(int size) {
this.elementSize = 0;
- this.threshold = size; // size represents the expected number of elements
+ this.threshold = size; // size represents the expected number of
+ // elements
int extraRoom = (int) (size * 1.75f);
if (this.threshold == extraRoom)
extraRoom++;
char[] currentKey;
while ((currentKey = keyTable[index]) != null) {
if (currentKey.length == keyLength
- && CharOperation.prefixEquals(currentKey, key))
+ && CharOperation.prefixEquals(currentKey, key))
return true;
index = (index + 1) % keyTable.length;
}
char[] currentKey;
while ((currentKey = keyTable[index]) != null) {
if (currentKey.length == keyLength
- && CharOperation.prefixEquals(currentKey, key))
+ && CharOperation.prefixEquals(currentKey, key))
return valueTable[index];
index = (index + 1) % keyTable.length;
}
char[] currentKey;
while ((currentKey = keyTable[index]) != null) {
if (currentKey.length == keyLength
- && CharOperation.prefixEquals(currentKey, key))
+ && CharOperation.prefixEquals(currentKey, key))
return valueTable[index] = value;
index = (index + 1) % keyTable.length;
}
char[] currentKey;
while ((currentKey = keyTable[index]) != null) {
if (currentKey.length == keyLength
- && CharOperation.prefixEquals(currentKey, key)) {
- Object value = valueTable[index];
- elementSize--;
- keyTable[index] = null;
- valueTable[index] = null;
- rehash();
- return value;
- }
+ && CharOperation.prefixEquals(currentKey, key)) {
+ Object value = valueTable[index];
+ elementSize--;
+ keyTable[index] = null;
+ valueTable[index] = null;
+ rehash();
+ return value;
+ }
index = (index + 1) % keyTable.length;
}
return null;
private void rehash() {
- HashtableOfObject newHashtable = new HashtableOfObject(elementSize * 2); // double the number of expected elements
+ HashtableOfObject newHashtable = new HashtableOfObject(elementSize * 2); // double
+ // the
+ // number
+ // of
+ // expected
+ // elements
char[] currentKey;
for (int i = keyTable.length; --i >= 0;)
if ((currentKey = keyTable[i]) != null)
Object object;
for (int i = 0, length = valueTable.length; i < length; i++)
if ((object = valueTable[i]) != null)
- s += new String(keyTable[i]) + " -> " + object.toString() + "\n"; //$NON-NLS-2$ //$NON-NLS-1$
+ s += new String(keyTable[i])
+ + " -> " + object.toString() + "\n"; //$NON-NLS-2$ //$NON-NLS-1$
return s;
}
}