addSymbol
will always return the same string
reference.
The symbol table performs the same task as String.intern()
with the following differences:
SymbolHash
Modifier and Type | Class and Description |
---|---|
protected static class | SymbolTable.
This class is a symbol table entry. |
Modifier and Type | Field and Description |
---|---|
protected SymbolTable. | fBuckets
Buckets. |
protected final int | fCollisionThreshold
A new hash function is selected and the table is rehashed when the number of keys in the bucket exceeds this threshold. |
protected transient int | fCount
The total number of entries in the hash table. |
protected int[] | fHashMultipliers
Array of randomly selected hash function multipliers or |
protected float | fLoadFactor
The load factor for the SymbolTable. |
protected int | fTableSize
actual table size |
protected int | fThreshold
The table is rehashed when its size exceeds this threshold. |
protected static final int | MAX_HASH_COLLISIONS
Maximum hash collisions per bucket for a table with load factor == 1. |
protected static final int | |
protected static final int | |
protected static final int | TABLE_SIZE
Default table size. |
Access | Constructor and Description |
---|---|
public | SymbolTable(int
the initial capacity of the SymbolTable. initialCapacity, float the load factor of the SymbolTable. loadFactor)Constructs a new, empty SymbolTable with the specified initial capacity and the specified load factor. |
public | SymbolTable(int
the initial capacity of the hashtable. initialCapacity)Constructs a new, empty SymbolTable with the specified initial capacity and default load factor, which is 0.75. |
public | SymbolTable()
Constructs a new, empty SymbolTable with a default initial capacity (101) and load factor, which is 0.75. |
Modifier and Type | Method and Description |
---|---|
public String | |
public String | addSymbol(char[]
The buffer containing the new symbol. buffer, int The offset into the buffer of the new symbol. offset, int The length of the new symbol in the buffer. length)Adds the specified symbol to the symbol table and returns a reference to the unique symbol. |
private String | |
private String | |
public boolean | containsSymbol(String
The symbol to look for. symbol)Returns true if the symbol table already contains the specified symbol. |
public boolean | containsSymbol(char[]
The buffer containing the symbol to look for. buffer, int The offset into the buffer. offset, int The length of the symbol in the buffer. length)Returns true if the symbol table already contains the specified symbol. |
public int | |
public int | hash(char[]
The character buffer containing the symbol. buffer, int The offset into the character buffer of the start
of the symbol. offset, int The length of the symbol. length)Returns a hashcode value for the specified symbol information. |
private int | |
private int | |
protected void | rebalance()
Randomly selects a new hash function and reorganizes this SymbolTable in order to more evenly distribute its entries across the table. |
protected void | rehash()
Increases the capacity of and internally reorganizes this SymbolTable, in order to accommodate and access its entries more efficiently. |
private void |
fBuckets | back to summary |
---|---|
protected SymbolTable. Buckets. |
fCollisionThreshold | back to summary |
---|---|
protected final int fCollisionThreshold A new hash function is selected and the table is rehashed when the number of keys in the bucket exceeds this threshold. |
fCount | back to summary |
---|---|
protected transient int fCount The total number of entries in the hash table. |
fHashMultipliers | back to summary |
---|---|
protected int[] fHashMultipliers Array of randomly selected hash function multipliers or |
fLoadFactor | back to summary |
---|---|
protected float fLoadFactor The load factor for the SymbolTable. |
fTableSize | back to summary |
---|---|
protected int fTableSize actual table size |
fThreshold | back to summary |
---|---|
protected int fThreshold The table is rehashed when its size exceeds this threshold. (The value of this field is (int)(capacity * loadFactor).) |
MAX_HASH_COLLISIONS | back to summary |
---|---|
protected static final int MAX_HASH_COLLISIONS Maximum hash collisions per bucket for a table with load factor == 1. |
MULTIPLIERS_MASK | back to summary |
---|---|
protected static final int MULTIPLIERS_MASK |
MULTIPLIERS_SIZE | back to summary |
---|---|
protected static final int MULTIPLIERS_SIZE |
TABLE_SIZE | back to summary |
---|---|
protected static final int TABLE_SIZE Default table size. |
SymbolTable | back to summary |
---|---|
public SymbolTable(int initialCapacity, float loadFactor) Constructs a new, empty SymbolTable with the specified initial capacity and the specified load factor.
|
SymbolTable | back to summary |
---|---|
public SymbolTable(int initialCapacity) Constructs a new, empty SymbolTable with the specified initial capacity and default load factor, which is 0.75.
|
SymbolTable | back to summary |
---|---|
public SymbolTable() Constructs a new, empty SymbolTable with a default initial capacity (101) and load factor, which is 0.75. |
addSymbol | back to summary |
---|---|
public String addSymbol(String symbol) Adds the specified symbol to the symbol table and returns a reference to the unique symbol. If the symbol already exists, the previous symbol reference is returned instead, in order guarantee that symbol references remain unique.
|
addSymbol | back to summary |
---|---|
public String addSymbol(char[] buffer, int offset, int length) Adds the specified symbol to the symbol table and returns a reference to the unique symbol. If the symbol already exists, the previous symbol reference is returned instead, in order guarantee that symbol references remain unique.
|
addSymbol0 | back to summary |
---|---|
private String addSymbol0(String symbol, int bucket, int collisionCount) |
addSymbol0 | back to summary |
---|---|
private String addSymbol0(char[] buffer, int offset, int length, int bucket, int collisionCount) |
containsSymbol | back to summary |
---|---|
public boolean containsSymbol(String symbol) Returns true if the symbol table already contains the specified symbol.
|
containsSymbol | back to summary |
---|---|
public boolean containsSymbol(char[] buffer, int offset, int length) Returns true if the symbol table already contains the specified symbol.
|
hash | back to summary |
---|---|
public int hash(String symbol) Returns a hashcode value for the specified symbol. The value
returned by this method must be identical to the value returned
by the
|
hash | back to summary |
---|---|
public int hash(char[] buffer, int offset, int length) Returns a hashcode value for the specified symbol information.
The value returned by this method must be identical to the value
returned by the
|
hash0 | back to summary |
---|---|
private int hash0(String symbol) |
hash0 | back to summary |
---|---|
private int hash0(char[] buffer, int offset, int length) |
rebalance | back to summary |
---|---|
protected void rebalance() Randomly selects a new hash function and reorganizes this SymbolTable in order to more evenly distribute its entries across the table. This method is called automatically when the number keys in one of the SymbolTable's buckets exceeds the given collision threshold. |
rehash | back to summary |
---|---|
protected void rehash() Increases the capacity of and internally reorganizes this SymbolTable, in order to accommodate and access its entries more efficiently. This method is called automatically when the number of keys in the SymbolTable exceeds this hashtable's capacity and load factor. |
rehashCommon | back to summary |
---|---|
private void rehashCommon(final int newCapacity) |
Modifier and Type | Field and Description |
---|---|
public final char[] | characters
Symbol characters. |
public SymbolTable. | next
The next entry. |
public final String | symbol
Symbol. |
Access | Constructor and Description |
---|---|
public | Entry(String symbol, SymbolTable.
Constructs a new entry from the specified symbol and next entry reference. |
public | Entry(char[] ch, int offset, int length, SymbolTable.
Constructs a new entry from the specified symbol information and next entry reference. |
characters | back to summary |
---|---|
public final char[] characters Symbol characters. This information is duplicated here for comparison performance. |
next | back to summary |
---|---|
public SymbolTable. The next entry. |
symbol | back to summary |
---|---|
public final String symbol Symbol. |
Entry | back to summary |
---|---|
public Entry(String symbol, SymbolTable. Constructs a new entry from the specified symbol and next entry reference. |
Entry | back to summary |
---|---|
public Entry(char[] ch, int offset, int length, SymbolTable. Constructs a new entry from the specified symbol information and next entry reference. |