com.sosnoski.util.hashmap
Class ObjectKeyBase

java.lang.Object
  |
  +--com.sosnoski.util.ObjectHashBase
        |
        +--com.sosnoski.util.hashmap.ObjectKeyBase
Direct Known Subclasses:
ObjectIntHashMap, ObjectObjectHashMap, StringIntHashMap

public abstract class ObjectKeyBase
extends ObjectHashBase

Base class for type-specific hash map classes with object keys. This class builds on the basic structure provided by ObjectHashBase, specializing it for the case of a hash map where data values are associated with the keys. See the base class description for details of the implementation.

Hash maps based on this class are unsynchronized in order to provide the best possible performance for typical usage scenarios, so explicit synchronization must be implemented by the subclass or the application in cases where they are to be modified in a multithreaded environment.

Subclasses need to implement the abstract methods defined by the base class for working with the key array, and by this class for working with the value array and for restructuring, as well as the actual data access methods (at least the basic add(), containsKey(), get(), and remove() methods).

Version:
1.1
Author:
Dennis M. Sosnoski
See Also:
PrimitiveKeyBase

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
ObjectKeyBase(int count, double fill, java.lang.Class ktype, java.lang.Class vtype, java.lang.Object tech)
          Constructor with full specification.
ObjectKeyBase(ObjectKeyBase from)
          Copy (clone) constructor.
 
Method Summary
 void clear()
          Set the table to the empty state.
protected abstract  java.lang.Object getValueArray()
          Get the backing array of values.
protected  void internalRemove(int slot)
          Internal remove pair from the table.
 java.util.Iterator iterator()
          Return an iterator for the key Objects in this map.
protected  void reallocate(int size)
          Resize the base arrays after a size change.
protected abstract  boolean reinsert(int slot)
          Reinsert an entry into the hash map.
protected abstract  void restructure(java.lang.Object karray, java.lang.Object varray)
          Restructure the table.
protected abstract  void setValueArray(java.lang.Object array)
          Set the backing array of values.
 
Methods inherited from class com.sosnoski.util.ObjectHashBase
ensureCapacity, freeSlot, getKeyArray, growCapacity, setKeyArray, size, standardFind, standardSlot, stepSlot
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectKeyBase

public ObjectKeyBase(int count,
                     double fill,
                     java.lang.Class ktype,
                     java.lang.Class vtype,
                     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
ktype - type of primitives used for keys
vtype - type of primitives or objects used for values
tech - hash technique specifier (one of STANDARD_HASH, IDENTITY_COMP, or IDENTITY_HASH, inherited from ObjectHashBase)

ObjectKeyBase

public ObjectKeyBase(ObjectKeyBase from)
Copy (clone) constructor.
Parameters:
from - instance being copied
Method Detail

getValueArray

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

setValueArray

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

restructure

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

reallocate

protected void reallocate(int size)
Resize the base arrays after a size change. This implementation of the abstract base class method allocates the new arrays and then calls another method for handling the actual transfer of the keys and values from the old arrays to the new ones.
Overrides:
reallocate in class ObjectHashBase
Parameters:
size - new size for base arrays

reinsert

protected abstract boolean reinsert(int slot)
Reinsert an entry into the hash map. This abstract method is used when the table is being directly modified by the base class, and should 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

internalRemove

protected void internalRemove(int slot)
Internal remove pair from the table. Removes the pair from the table by setting the key entry to null and adjusting the count present, then chains through the table to reinsert any other pairs which may have collided with the removed pair. If the associated value is an object reference, it should be set to null before this method is called.
Parameters:
slot - index number of pair to be removed

clear

public void clear()
Set the table to the empty state. This override of the base class method first calls the base class method to clear the entry information, then checks if the hash map values are objects, and if so clears all references to these objects.
Overrides:
clear in class ObjectHashBase

iterator

public final java.util.Iterator iterator()
Return an iterator for the key Objects in this map. The iterator returns all keys 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 keys in map


Company Web Site

XML Benchmark Home