Package org.apache.xerces.util
Class SymbolHash
java.lang.Object
org.apache.xerces.util.SymbolHash
This class is an unsynchronized hash table primarily used for String
to Object mapping.
The hash code uses the same algorithm as SymbolTable class.
- Version:
- $Id: SymbolHash.java 1867092 2019-09-18 03:54:53Z mukulg $
- Author:
- Elena Litani
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final class
This class is a key table entry. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected SymbolHash.Entry[]
Buckets.protected int[]
Array of randomly selected hash function multipliers ornull
if the default String.hashCode() function should be used.protected int
Number of elements.protected int
Actual table sizeprotected static final int
Maximum hash collisions per bucket.protected static final int
protected static final int
protected static final int
Default table size. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a key table with the default size.SymbolHash
(int size) Constructs a key table with a given size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Remove all key/value association.Get the value associated with the given key.Object[]
Return key/value pairs of all entries in the mapint
Get the number of key/value pairs stored in this table.int
Add all values to the given array.protected int
Returns a hashcode value for the specified key.Make a clone of this object.void
Adds the key/value mapping to the key table.protected void
Randomly selects a new hash function and reorganizes this SymbolHash in order to more evenly distribute its entries across the table.protected void
rehash()
Increases the capacity of and internally reorganizes this SymbolHash, in order to accommodate and access its entries more efficiently.protected SymbolHash.Entry
-
Field Details
-
TABLE_SIZE
protected static final int TABLE_SIZEDefault table size.- See Also:
-
MAX_HASH_COLLISIONS
protected static final int MAX_HASH_COLLISIONSMaximum hash collisions per bucket.- See Also:
-
MULTIPLIERS_SIZE
protected static final int MULTIPLIERS_SIZE- See Also:
-
MULTIPLIERS_MASK
protected static final int MULTIPLIERS_MASK- See Also:
-
fTableSize
protected int fTableSizeActual table size -
fBuckets
Buckets. -
fNum
protected int fNumNumber of elements. -
fHashMultipliers
protected int[] fHashMultipliersArray of randomly selected hash function multipliers ornull
if the default String.hashCode() function should be used.
-
-
Constructor Details
-
SymbolHash
public SymbolHash()Constructs a key table with the default size. -
SymbolHash
public SymbolHash(int size) Constructs a key table with a given size.- Parameters:
size
- the size of the key table.
-
-
Method Details
-
put
Adds the key/value mapping to the key table. If the key already exists, the previous value associated with this key is overwritten by the new value.- Parameters:
key
-value
-
-
get
Get the value associated with the given key.- Parameters:
key
-- Returns:
- the value associated with the given key.
-
getLength
public int getLength()Get the number of key/value pairs stored in this table.- Returns:
- the number of key/value pairs stored in this table.
-
getValues
Add all values to the given array. The array must have enough entry.- Parameters:
elements
- the array to store the elementsfrom
- where to start store element in the array- Returns:
- number of elements copied to the array
-
getEntries
Return key/value pairs of all entries in the map -
makeClone
Make a clone of this object. -
clear
public void clear()Remove all key/value association. This tries to save a bit of GC'ing by at least keeping the fBuckets array around. -
search
-
hash
Returns a hashcode value for the specified key.- Parameters:
key
- The key to hash.
-
rehash
protected void rehash()Increases the capacity of and internally reorganizes this SymbolHash, in order to accommodate and access its entries more efficiently. This method is called automatically when the number of keys in the SymbolHash exceeds its number of buckets. -
rebalance
protected void rebalance()Randomly selects a new hash function and reorganizes this SymbolHash in order to more evenly distribute its entries across the table. This method is called automatically when the number keys in one of the SymbolHash's buckets exceeds MAX_HASH_COLLISIONS.
-