com.sosnoski.util.hashmap
Class ObjectObjectHashMap

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

public class ObjectObjectHashMap
extends ObjectKeyBase

Hash map using Object values as keys mapped to Object 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
protected  java.lang.Object[] m_keyTable
          Array of key table slots.
protected  java.lang.Object[] 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
ObjectObjectHashMap()
          Default constructor.
ObjectObjectHashMap(int count)
          Constructor with only size supplied.
ObjectObjectHashMap(int count, double fill)
          Constructor with size and fill fraction specified.
ObjectObjectHashMap(int count, double fill, java.lang.Object tech)
          Constructor with full specification.
ObjectObjectHashMap(int count, java.lang.Object tech)
          Constructor with only size and hash technique supplied.
ObjectObjectHashMap(java.lang.Object tech)
          Constructor with technique specified.
ObjectObjectHashMap(ObjectObjectHashMap base)
          Copy (clone) constructor.
 
Method Summary
 java.lang.Object add(java.lang.Object key, java.lang.Object value)
          Add an entry to the table.
protected  int assignSlot(java.lang.Object key, java.lang.Object value)
          Assign slot for entry.
 java.lang.Object clone()
          Construct a copy of the table.
 boolean containsKey(java.lang.Object key)
          Check if an entry is present in the table.
 java.lang.Object get(java.lang.Object 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.
 java.lang.Object remove(java.lang.Object 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.
 java.util.Iterator valueIterator()
          Return an iterator for the value Objects in this map.
 
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

m_keyTable

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

m_valueTable

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

ObjectObjectHashMap

public ObjectObjectHashMap(int count,
                           double fill,
                           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
tech - hash technique specifier (one of STANDARD_HASH, IDENTITY_COMP, or IDENTITY_HASH, inherited from ObjectHashBase)

ObjectObjectHashMap

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

ObjectObjectHashMap

public ObjectObjectHashMap(int count,
                           java.lang.Object tech)
Constructor with only size and hash technique supplied. Uses default value for fill fraction.
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)

ObjectObjectHashMap

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

ObjectObjectHashMap

public ObjectObjectHashMap(java.lang.Object tech)
Constructor with technique specified. Uses standard default values for size and fill fraction.
Parameters:
tech - hash technique specifier (one of STANDARD_HASH, IDENTITY_COMP, or IDENTITY_HASH, inherited from ObjectHashBase)

ObjectObjectHashMap

public ObjectObjectHashMap()
Default constructor.

ObjectObjectHashMap

public ObjectObjectHashMap(ObjectObjectHashMap 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.Object key,
                         java.lang.Object 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 java.lang.Object add(java.lang.Object key,
                            java.lang.Object 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 (non-null)
Returns:
value previously associated with key, or null if key not previously present in table

containsKey

public final boolean containsKey(java.lang.Object 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 java.lang.Object get(java.lang.Object 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.Object remove(java.lang.Object 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 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