com.sosnoski.util.hashset
Class StringHashSet

java.lang.Object
  |
  +--com.sosnoski.util.ObjectHashBase
        |
        +--com.sosnoski.util.hashset.ObjectSetBase
              |
              +--com.sosnoski.util.hashset.StringHashSet

public class StringHashSet
extends ObjectSetBase

Hash set of Strings. 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  boolean m_identCompare
          Use identity comparison flag.
protected  boolean m_identHash
          Use identity hash flag.
protected  java.lang.String[] m_keyTable
          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, MINIMUM_SIZE, STANDARD_HASH
 
Constructor Summary
StringHashSet()
          Default constructor.
StringHashSet(int count)
          Constructor with only size supplied.
StringHashSet(int count, double fill)
          Constructor with size and fill fraction supplied.
StringHashSet(int count, double fill, java.lang.Object tech)
          Constructor with full specification.
StringHashSet(int count, java.lang.Object tech)
          Constructor with size and technique supplied.
StringHashSet(java.lang.Object tech)
          Constructor with only technique supplied.
StringHashSet(StringHashSet base)
          Copy (clone) constructor.
 
Method Summary
 boolean add(java.lang.String key)
          Add a key to the set.
protected  int assignSlot(java.lang.String key)
          Assign slot for entry.
 java.lang.Object clone()
          Construct a copy of the set.
 boolean contains(java.lang.String key)
          Check if key is in set.
protected  java.lang.Object[] getKeyArray()
          Get the backing array of keys.
protected  boolean reinsert(int slot)
          Reinsert a key into the hash set.
 boolean remove(java.lang.String key)
          Remove an entry from the set.
protected  void restructure(java.lang.Object karray)
          Restructure the set.
protected  void setKeyArray(java.lang.Object array)
          Set the backing array of keys.
 
Methods inherited from class com.sosnoski.util.hashset.ObjectSetBase
internalRemove, iterator, reallocate
 
Methods inherited from class com.sosnoski.util.ObjectHashBase
clear, 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.String[] m_keyTable
Array of value table slots.

m_identHash

protected boolean m_identHash
Use identity hash flag.

m_identCompare

protected boolean m_identCompare
Use identity comparison flag.
Constructor Detail

StringHashSet

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

StringHashSet

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

StringHashSet

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

StringHashSet

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

StringHashSet

public StringHashSet(java.lang.Object tech)
Constructor with only technique supplied. Uses default value for fill fraction.
Parameters:
tech - hash technique specifier (one of STANDARD_HASH, IDENTITY_COMP, or IDENTITY_HASH, inherited from ObjectHashBase)

StringHashSet

public StringHashSet()
Default constructor.

StringHashSet

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

getKeyArray

protected 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 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

reinsert

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

restructure

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

assignSlot

protected int assignSlot(java.lang.String key)
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 set
Returns:
slot at which key was added

add

public boolean add(java.lang.String key)
Add a key to the set.
Parameters:
key - key to be added to set
Returns:
true if key added to set, false if already present in set

contains

public boolean contains(java.lang.String key)
Check if key is in set.
Parameters:
key - key to be found in set
Returns:
true if key found in set, false if not

remove

public boolean remove(java.lang.String key)
Remove an entry from the set.
Parameters:
key - key to be removed from set
Returns:
true if key successfully removed from set, false if key not found in set

clone

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


Company Web Site

XML Benchmark Home