Methods Summary |
---|
public int | getID(components.UnicodeConstant str, components.StringConstant parameter)
Str2ID head = this;
int index;
int hash = hashString(str.string);
int phash = hash & 0x7fffffff;
int secondaryHash = (hash & 7) + 1;
Str2ID chain = head;
for ( ; ; ) {
index = chain.unsignedMod(hash);
while (chain.strings[index] != null) {
if ((chain.hashbits[index] == phash) &&
chain.strings[index].string.equals(str.string)) {
// We found the string, calculate the ID
return chain.baseId + index;
}
index -= secondaryHash;
if (index < 0) {
index += chain.hashTableSize;
}
}
// Didn't find the string in this chain. . . .
if (chain.next == null) {
break;
} else {
chain = chain.next;
}
}
if (locked) {
throw new NullPointerException(
Localizer.getString("str2id.attempting_to_add_to_table_when_locked", str));
}
if (chain.used >= chain.overflowPoint) {
chain.next = new Str2ID();
chain.next.baseId = chain.baseId + chain.hashTableSize;
chain = chain.next;
index = chain.unsignedMod(hash);
}
chain.strings[index] = str;
chain.hashbits[index] = phash;
if (parameter != null ){
if ( chain.parameters == null ){
chain.parameters = new StringConstant[chain.hashTableSize];
}
chain.parameters[index] = parameter;
}
chain.used++;
return chain.baseId + index;
|
public int | getID(java.lang.String str)
return getID( new UnicodeConstant( str ), (StringConstant)null );
|
public int | getID(components.UnicodeConstant name, components.UnicodeConstant sig)
return (getID( name, (StringConstant)null) << 16) + getID( sig, (StringConstant)null);
|
public int | getID(java.lang.String name, java.lang.String sig)
return (getID(name) << 16) + getID(sig);
|
static int | hashString(java.lang.String str)
int result = 0;
for (int i = 0; i < str.length(); i++) {
result = result * 37 + (int) str.charAt(i);
}
return result;
|
static boolean | isPrime(int n)
if ((n % 2) == 0)
return false;
int sqrt = (int) Math.sqrt(n);
for (int i = 3; i <= sqrt; i += 2) {
if ((n % i) == 0)
return false;
}
return true;
|
public jcc.Str2ID | rehash()
Str2ID newchain, chain;
int count = 0;
for (chain = this; chain != null; chain = chain.next) {
count += chain.used;
}
newchain = new Str2ID((int)Math.ceil(1.25 * count));
for (chain = this; chain != null; chain = chain.next) {
UnicodeConstant strings[] = chain.strings;
StringConstant parameters[] = chain.parameters;
for (int i = chain.hashTableSize; --i >= 0; ) {
UnicodeConstant string = strings[i];
if (string != null)
newchain.getID(string, parameters == null ? null : parameters[i]);
}
}
return newchain;
|
public void | setLocked(boolean lock)
this.locked = lock;
|
int | unsignedMod(int val)
// Treat val as an unsigned quantity and do the MOD operation
if (val >= 0) {
return val % hashTableSize;
} else {
return (int)(((long)val&0xffffffffL) % (long)hashTableSize);
}
|