com.sosnoski.util.hashmap
Class IntStringHashMap

java.lang.Object
  |
  +--com.sosnoski.util.PrimitiveHashBase
        |
        +--com.sosnoski.util.hashmap.PrimitiveKeyBase
              |
              +--com.sosnoski.util.hashmap.IntStringHashMap

public class IntStringHashMap
extends PrimitiveKeyBase

Hash map using primitive int values as keys mapped to String 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 hash map implementation.

Version:
1.1
Author:
Dennis M. Sosnoski

Field Summary
protected  int[] m_keyTable
          Array of key table slots.
protected  java.lang.String[] m_valueTable
          Array of value table slots.
 
Fields inherited from class com.sosnoski.util.PrimitiveHashBase
DEFAULT_FILL, KEY_MULTIPLIER, m_entryCount, m_entryLimit, m_fillFraction, m_flagTable, m_hitOffset, MINIMUM_SIZE
 
Constructor Summary
IntStringHashMap()
          Default constructor.
IntStringHashMap(int count)
          Constructor with only size supplied.
IntStringHashMap(int count, double fill)
          Constructor with full specification.
IntStringHashMap(IntStringHashMap base)
          Copy (clone) constructor.
 
Method Summary
 java.lang.String add(int key, java.lang.String value)
          Add an entry to the table.
protected  int assignSlot(int key, java.lang.String value)
          Assign slot for entry.
 java.lang.Object clone()
          Construct a copy of the table.
protected  int computeSlot(int key)
          Compute the base slot for a key.
 boolean containsKey(int key)
          Check if an entry is present in the table.
 java.lang.String get(int 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  int internalFind(int key)
          Internal find key in table.
protected  boolean reinsert(int slot)
          Reinsert an entry into the hash map.
 java.lang.String remove(int key)
          Remove an entry from the table.
protected  void restructure(boolean[] flags, 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.
 java.util.Iterator valueIterator()
          Return an iterator for the value Objects in this map.
 
Methods inherited from class com.sosnoski.util.hashmap.PrimitiveKeyBase
clear, reallocate
 
Methods inherited from class com.sosnoski.util.PrimitiveHashBase
ensureCapacity, freeSlot, growCapacity, size, stepSlot
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_keyTable

protected int[] m_keyTable
Array of key table slots.

m_valueTable

protected java.lang.String[] m_valueTable
Array of value table slots.
Constructor Detail

IntStringHashMap

public IntStringHashMap(int count,
                        double fill)
Constructor with full specification.
Parameters:
count - number of values to assume in initial sizing of table
fill - fraction full allowed for table before growing

IntStringHashMap

public IntStringHashMap(int count)
Constructor with only size supplied. Uses default value for fill fraction.
Parameters:
count - number of values to assume in initial sizing of table

IntStringHashMap

public IntStringHashMap()
Default constructor.

IntStringHashMap

public IntStringHashMap(IntStringHashMap 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 PrimitiveHashBase
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 PrimitiveHashBase
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 PrimitiveKeyBase
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 PrimitiveKeyBase
Parameters:
array - backing value array object

reinsert

protected final boolean reinsert(int slot)
Reinsert an entry into the hash map. This method is designed for internal use when the table is being modified, and does not adjust the count present or check the table capacity.
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(boolean[] flags,
                           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 PrimitiveKeyBase
Parameters:
flags - array of flags for array slots used
karray - array of keys
varray - array of values

computeSlot

protected final int computeSlot(int key)
Compute the base slot for a key.
Parameters:
key - key value to be computed
Returns:
base slot for key

assignSlot

protected int assignSlot(int key,
                         java.lang.String 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 - key to be added to table
value - associated value for key
Returns:
slot at which entry was added

add

public java.lang.String add(int key,
                            java.lang.String 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
value - associated value for key
Returns:
value previously associated with key, null if key not previously present in table

internalFind

protected final int internalFind(int key)
Internal find key in table.
Parameters:
key - to be found in table
Returns:
index of matching key, or -index-1 of slot to be used for inserting key in table if not already present (always negative)

containsKey

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

get

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

remove

public java.lang.String remove(int key)
Remove an entry from the table.
Parameters:
key - key to be removed from table
Returns:
value associated with removed key, null if key not found in table

valueIterator

public final java.util.Iterator valueIterator()
Return an iterator for the value Objects in this map. The iterator returns all values in arbitrary order, but is not "live". Any changes to the map while the iteration is in progress will give indeterminant results.
Returns:
iterator for values in array

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