Class SymbolHash
- java.lang.Object
-
- org.smooks.engine.delivery.sax.ng.org.apache.xerces.util.SymbolHash
-
public class SymbolHash extends Object
This class is an unsynchronized hash table primary used for String to Object mapping.The hash code uses the same algorithm as SymbolTable class.
- Version:
- $Id$
- Author:
- Elena Litani
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
SymbolHash.Entry
This class is a key table entry.
-
Field Summary
Fields Modifier and Type Field Description protected SymbolHash.Entry[]
fBuckets
Buckets.protected int[]
fHashMultipliers
Array of randomly selected hash function multipliers ornull
if the default String.hashCode() function should be used.protected int
fNum
Number of elements.protected int
fTableSize
Actual table sizeprotected static int
MAX_HASH_COLLISIONS
Maximum hash collisions per bucket.protected static int
MULTIPLIERS_MASK
protected static int
MULTIPLIERS_SIZE
protected static int
TABLE_SIZE
Default table size.
-
Constructor Summary
Constructors Constructor Description SymbolHash()
Constructs a key table with the default size.SymbolHash(int size)
Constructs a key table with a given size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Remove all key/value association.Object
get(Object key)
Get the value associated with the given key.Object[]
getEntries()
Return key/value pairs of all entries in the mapint
getLength()
Get the number of key/value pairs stored in this table.int
getValues(Object[] elements, int from)
Add all values to the given array.protected int
hash(Object key)
Returns a hashcode value for the specified key.SymbolHash
makeClone()
Make a clone of this object.void
put(Object key, Object value)
Adds the key/value mapping to the key table.protected void
rebalance()
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
search(Object key, int bucket)
-
-
-
Field Detail
-
TABLE_SIZE
protected static final int TABLE_SIZE
Default table size.- See Also:
- Constant Field Values
-
MAX_HASH_COLLISIONS
protected static final int MAX_HASH_COLLISIONS
Maximum hash collisions per bucket.- See Also:
- Constant Field Values
-
MULTIPLIERS_SIZE
protected static final int MULTIPLIERS_SIZE
- See Also:
- Constant Field Values
-
MULTIPLIERS_MASK
protected static final int MULTIPLIERS_MASK
- See Also:
- Constant Field Values
-
fTableSize
protected int fTableSize
Actual table size
-
fBuckets
protected SymbolHash.Entry[] fBuckets
Buckets.
-
fNum
protected int fNum
Number of elements.
-
fHashMultipliers
protected int[] fHashMultipliers
Array of randomly selected hash function multipliers ornull
if the default String.hashCode() function should be used.
-
-
Method Detail
-
put
public void put(Object key, Object value)
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
public Object get(Object key)
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
public int getValues(Object[] elements, int from)
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
public Object[] getEntries()
Return key/value pairs of all entries in the map
-
makeClone
public SymbolHash 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
protected SymbolHash.Entry search(Object key, int bucket)
-
hash
protected int hash(Object key)
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.
-
-