com.sosnoski.util.hashmap
Class PrimitiveKeyBase

java.lang.Object
  |
  +--com.sosnoski.util.PrimitiveHashBase
        |
        +--com.sosnoski.util.hashmap.PrimitiveKeyBase
Direct Known Subclasses:
IntStringHashMap

public abstract class PrimitiveKeyBase
extends PrimitiveHashBase

Base class for type-specific hash map classes with primitive keys. This class builds on the basic structure provided by PrimitiveHashBase, specializing it for the case of a hash map where a data value is associated with each key. See the base class description for details of the implementation.

Hash sets 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.0
Author:
Dennis M. Sosnoski
See Also:
PrimitiveHashBase

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
PrimitiveKeyBase(int count, double fill, java.lang.Class ktype, java.lang.Class vtype)
          Constructor with full specification.
PrimitiveKeyBase(PrimitiveKeyBase base)
          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 reallocate(int size)
          Resize the base arrays after a size change.
protected abstract  void restructure(boolean[] flags, 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.PrimitiveHashBase
ensureCapacity, freeSlot, getKeyArray, growCapacity, setKeyArray, size, stepSlot
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrimitiveKeyBase

public PrimitiveKeyBase(int count,
                        double fill,
                        java.lang.Class ktype,
                        java.lang.Class vtype)
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

PrimitiveKeyBase

public PrimitiveKeyBase(PrimitiveKeyBase base)
Copy (clone) constructor.
Parameters:
base - 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(boolean[] flags,
                                    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:
flags - array of flags for array slots used
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 PrimitiveHashBase
Parameters:
size - new size for base arrays

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 PrimitiveHashBase


Company Web Site

XML Benchmark Home