|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectoscript.util.OpenHashSymbolTable
A symbol table implementation based on a open hash map, using double hashing as a strategy to avoid collisions. Double hasing uses two hash functions to compute an index into the table:
Idx(i,k) := H1(k) + i * H2(k)where for a given key
k
, i
is incremented from
0
until an unused table slot is found.
Threading note: this class is not synchronized, but is designed to save to read from multiple threads, while write from a single thread context (at a time).
Field Summary |
Fields inherited from interface oscript.util.SymbolTable |
MIN_SYMBOL_ID |
Constructor Summary | |
OpenHashSymbolTable()
Class Constructor. |
|
OpenHashSymbolTable(int capacity,
float load)
Class Constructor. |
Method Summary | |
int |
create(int id)
Get the index that the specified symbol maps to, and create a new one if a mapping does not already exist. |
int |
get(int id)
Get the index that the specified symbol maps to. |
float |
getLoad()
|
static java.lang.String |
getStats()
|
void |
readExternal(java.io.ObjectInput in)
|
int |
size()
The number of mappings that exist in this table. |
java.util.Iterator |
symbols()
Return an iteration of the keys (symbols) into this table. |
void |
writeExternal(java.io.ObjectOutput out)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public OpenHashSymbolTable()
public OpenHashSymbolTable(int capacity, float load)
capacity
- the initial capacityload
- the loading factorMethod Detail |
public float getLoad()
public final int get(int id)
get
in interface SymbolTable
id
- the id of the symbol to get a mapping for
-1
if no mapping exists for the
specified symbolpublic int create(int id)
create
in interface SymbolTable
id
- the id of the symbol to get a mapping for
public static final java.lang.String getStats()
public int size()
size
in interface SymbolTable
public java.util.Iterator symbols()
Iterator
interface, each symbol is wrapped (boxed)
in a Integer
.
symbols
in interface SymbolTable
public void readExternal(java.io.ObjectInput in) throws java.io.IOException
readExternal
in interface java.io.Externalizable
java.io.IOException
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |