Methods Summary |
---|
public void | addEntry(java.lang.Object x)
if (closed) {
throw new Error("Hashtable is closed");
}
// Don't do anything if we've already seen this guy.
if (seen.get(x) != null) {
return;
}
checkType(x);
seen.put(x, x);
int bucket = (int)(hash(x) % size);
if (bucket < 0) {
System.out.println("Bad bucket?? " + this);
}
// Add this guy to the beginning of his bucket.
Object oldNext = firstEntry[bucket];
firstEntry[bucket] = x;
if (oldNext != null) {
nextEntry.put(x, oldNext);
}
addNewEntryCallback(bucket, x);
|
public void | addNewEntryCallback(int bucket, java.lang.Object neww)
|
public void | chainPrefix(CCodeWriter c)
|
public void | chainSuffix(CCodeWriter c)
|
private void | checkType(java.lang.Object x)
if (!type.isAssignableFrom(x.getClass())) {
throw new Error(x.getClass() + " is not assignable to " + type);
}
|
public java.util.Enumeration | enumerate()
return seen.keys();
|
protected java.lang.Object | getFirst(int bucket)
return firstEntry[bucket];
|
protected int | getKey(java.lang.Object x)
Integer Key = (Integer)keys.get(x);
if (Key == null) {
addEntry(x);
Key = (Integer)keys.get(x);
}
return Key.intValue();
|
protected java.lang.Object | getNext(java.lang.Object x)
checkType(x);
return nextEntry.get(x);
|
protected java.lang.Object | getObject(int key)
return keys.get(new Integer(key));
|
int | getSize()
return size;
|
abstract long | hash(java.lang.Object x)
|
protected void | setKey(java.lang.Object x, int key)
checkType(x);
Integer Key = new Integer(key);
Object oldKey = keys.put(x, Key);
Object oldVal = keys.put(Key, x);
if (oldKey != null) {
System.out.println("Changing key(" + x + ") from " + oldKey + " to "
+ Key);
}
if (oldVal != null) {
System.out.println("Both " + x + " and " + oldVal
+ " have the same key value " + Key);
}
|
public static long | stringHash(java.lang.String string)
int raw_hash = 0;
for (int i = 0; i < string.length(); i++) {
raw_hash = raw_hash * 37 + string.charAt(i);
}
long result = (((long)raw_hash) << 32) >>> 32;
return result;
|
abstract java.lang.Object | tableChain(CCodeWriter c, int bucket, java.lang.Object[] chain)
|
abstract void | tableEntry(CCodeWriter c, int bucket, java.lang.Object token)
|
void | writeTable(CCodeWriter out, java.lang.String tableName)
closed = true;
chainPrefix(out);
Vector list = new Vector();
Object tokens[] = new Object[size];
for (int i = 0; i < size; i++) {
list.setSize(0);
for (Object item = firstEntry[i]; item != null;
item = nextEntry.get(item)) {
list.addElement(item);
}
Object[] listArray = new Object[list.size()];
list.copyInto(listArray);
tokens[i] = tableChain(out, i, listArray);
}
chainSuffix(out);
out.println("static HASHTABLE_X(" + size + ") " + tableName + "Data = {");
out.println("\tHASHTABLE_HEADER(" + size + ", " + seen.size() + "),");
out.println("\t{");
for (int i = 0; i < size; i++) {
if (tokens[i] == null) {
out.print("\t\tNULL,\n");
} else {
out.print("\t\t((void *)");
tableEntry(out, i, tokens[i]);
out.print("),\n");
}
}
out.println("\t}");
out.println("};\n");
out.println("#if !RELOCATABLE_ROM");
out.println("HASHTABLE " + tableName + " = (HASHTABLE)&" + tableName + "Data;\n");
out.println("#endif");
|