com.sosnoski.util.hashmap
Class StringIntHashMap

java.lang.Object
  |
  +--com.sosnoski.util.ObjectHashBase
        |
        +--com.sosnoski.util.hashmap.ObjectKeyBase
              |
              +--com.sosnoski.util.hashmap.StringIntHashMap

public class StringIntHashMap
extends ObjectKeyBase

Hash map using String values as keys mapped to primitive int values. This implementation is unsynchronized in order to provide the best possible performance for typical usage scenarios, so explicit synchronization must be implemented by a wrapper class or directly by the application in cases where instances are modified in a multithreaded environment. See the base classes for other details of the implementation.

Version:
1.1
Author:
Dennis M. Sosnoski

Field Summary
static int DEFAULT_NOT_FOUND
          Default value returned when key not found in table.
protected  java.lang.String[] m_keyTable
          Array of key table slots.
protected  int m_notFoundValue
          Value returned when key not found in table.
protected  int[] m_valueTable
          Array of value table slots.
 
Fields inherited from class com.sosnoski.util.ObjectHashBase
DEFAULT_FILL, IDENTITY_COMP, IDENTITY_HASH, m_arraySize, m_entryCount, m_entryLimit, m_fillFraction, m_hitOffset, m_identCompare, m_identHash, MINIMUM_SIZE, STANDARD_HASH
 
Constructor Summary
StringIntHashMap()
          Default constructor.
StringIntHashMap(int count)
          Constructor with only size supplied.
StringIntHashMap(int count, double fill)
          Constructor with size and fill fraction specified.
StringIntHashMap(int count, double fill, int miss, java.lang.Object tech)
          Constructor with full specification.
StringIntHashMap(int count, java.lang.Object tech)
          Constructor with only size and hash technique supplied.
StringIntHashMap(java.lang.Object tech)
          Constructor with hash technique specified.
StringIntHashMap(StringIntHashMap base)
          Copy (clone) constructor.
 
Method Summary
 int add(java.lang.String key, int value)
          Add an entry to the table.
protected  int assignSlot(java.lang.String key, int value)
          Assign slot for entry.
 java.lang.Object clone()
          Construct a copy of the table.
 boolean containsKey(java.lang.String key)
          Check if an entry is present in the table.
 int get(java.lang.String key)
          Find an entry in the table.
protected  java.lang.Object[] getKeyArray()
          Get the backing array of keys.
protected  java.lang.Object getValueArray()
          Get the backing array of values.
protected  boolean reinsert(int slot)
          Reinsert an entry into the hash map.
 int remove(java.lang.String key)
          Remove an entry from the table.
protected  void restructure(java.lang.Object karray, java.lang.Object varray)
          Restructure the table.
protected  void setKeyArray(java.lang.Object array)
          Set the backing array of keys.
protected  void setValueArray(java.lang.Object array)
          Set the backing array of values.
 
Methods inherited from class com.sosnoski.util.hashmap.ObjectKeyBase
clear, internalRemove, iterator, reallocate
 
Methods inherited from class com.sosnoski.util.ObjectHashBase
ensureCapacity, freeSlot, growCapacity, size, standardFind, standardSlot, stepSlot
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_NOT_FOUND

public static final int DEFAULT_NOT_FOUND
Default value returned when key not found in table.

m_keyTable

protected java.lang.String[] m_keyTable
Array of key table slots.

m_valueTable

protected int[] m_valueTable
Array of value table slots.

m_notFoundValue

protected int m_notFoundValue
Value returned when key not found in table.
Constructor Detail

StringIntHashMap

public StringIntHashMap(int count,
                        double fill,
                        int miss,
                        java.lang.Object tech)
Constructor with full specification.
Parameters:
count - number of values to assume in initial sizing of table
fill - fraction full allowed for table before growing
miss - value returned when key not found in table
tech - hash technique specifier (one of STANDARD_HASH, IDENTITY_COMP, or IDENTITY_HASH, inherited from ObjectHashBase)

StringIntHashMap

public StringIntHashMap(int count,
                        double fill)
Constructor with size and fill fraction specified. Uses default hash technique and value returned when key not found in table.
Parameters:
count - number of values to assume in initial sizing of table
fill - fraction full allowed for table before growing

StringIntHashMap

public StringIntHashMap(int count,
                        java.lang.Object tech)
Constructor with only size and hash technique supplied. Uses default values for fill fraction and value returned when key not found in table.
Parameters:
count - number of values to assume in initial sizing of table
tech - hash technique specifier (one of STANDARD_HASH, IDENTITY_COMP, or IDENTITY_HASH, inherited from ObjectHashBase)

StringIntHashMap

public StringIntHashMap(int count)
Constructor with only size supplied. Uses default hash technique and values for fill fraction and value returned when key not found in table.
Parameters:
count - number of values to assume in initial sizing of table

StringIntHashMap

public StringIntHashMap(java.lang.Object tech)
Constructor with hash technique specified. Uses standard default values for size, fill fraction, and value returned when key not found in table.
Parameters:
tech - hash technique specifier (one of STANDARD_HASH, IDENTITY_COMP, or IDENTITY_HASH, inherited from ObjectHashBase)

StringIntHashMap

public StringIntHashMap()
Default constructor.

StringIntHashMap

public StringIntHashMap(StringIntHashMap base)
Copy (clone) constructor.
Parameters:
base - instance being copied
Method Detail

getKeyArray

protected final java.lang.Object[] getKeyArray()
Get the backing array of keys. This implementation of an abstract method is used by the type-agnostic base class code to access the array used for type-specific storage by the child class.
Overrides:
getKeyArray in class ObjectHashBase
Returns:
backing key array object

setKeyArray

protected final void setKeyArray(java.lang.Object array)
Set the backing array of keys. This implementation of an abstract method is used by the type-agnostic base class code to set the array used for type-specific storage by the child class.
Overrides:
setKeyArray in class ObjectHashBase
Parameters:
array - backing key array object

getValueArray

protected final java.lang.Object getValueArray()
Get the backing array of values. This implementation of an abstract method is used by the type-agnostic base class code to access the array used for type-specific storage by the child class.
Overrides:
getValueArray in class ObjectKeyBase
Returns:
backing key array object

setValueArray

protected final void setValueArray(java.lang.Object array)
Set the backing array of values. This implementation of an abstract method is used by the type-agnostic base class code to set the array used for type-specific storage by the child class.
Overrides:
setValueArray in class ObjectKeyBase
Parameters:
array - backing value array object

reinsert

protected final boolean reinsert(int slot)
Reinsert an entry into the hash map. This implementation of an abstract method is used when the table is being directly modified by the base class, and does not adjust the count present or check the table capacity.
Overrides:
reinsert in class ObjectKeyBase
Parameters:
slot - position of entry to be reinserted into hash map
Returns:
true if the slot number used by the entry has has changed, false if not

restructure

protected void restructure(java.lang.Object karray,
                           java.lang.Object varray)
Restructure the table. This implementation of an abstract method is used when the table is increasing or decreasing in size, and works directly with the old table representation arrays. It inserts pairs from the old arrays directly into the table without adjusting the count present or checking the table size.
Overrides:
restructure in class ObjectKeyBase
Parameters:
karray - array of keys
varray - array of values

assignSlot

protected int assignSlot(java.lang.String key,
                         int value)
Assign slot for entry. Starts at the slot found by the hashed key value. If this slot is already occupied, it steps the slot number and checks the resulting slot, repeating until an unused slot is found. This method does not check for duplicate keys, so it should only be used for internal reordering of the tables.
Parameters:
key - to be added to table
value - associated value for key
Returns:
slot at which entry was added

add

public int add(java.lang.String key,
               int value)
Add an entry to the table. If the key is already present in the table, this replaces the existing value associated with the key.
Parameters:
key - key to be added to table (non-null)
value - associated value for key
Returns:
value previously associated with key, or reserved not found value if key not previously present in table

containsKey

public final boolean containsKey(java.lang.String key)
Check if an entry is present in the table. This method is supplied to support the use of values matching the reserved not found value.
Parameters:
key - key for entry to be found
Returns:
true if key found in table, false if not

get

public final int get(java.lang.String key)
Find an entry in the table.
Parameters:
key - key for entry to be returned
Returns:
value for key, or reserved not found value if key not found

remove

public int remove(java.lang.String key)
Remove an entry from the table. If multiple entries are present with the same key value, only the first one found will be removed.
Parameters:
key - key to be removed from table
Returns:
value associated with removed key, or reserved not found value if key not found in table

clone

public java.lang.Object clone()
Construct a copy of the table.
Overrides:
clone in class java.lang.Object
Returns:
shallow copy of table


Company Web Site

XML Benchmark Home