GNU Trove

gnu.trove
Class TObjectHash

java.lang.Object
  |
  +--gnu.trove.THash
        |
        +--gnu.trove.TObjectHash
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable, TObjectHashingStrategy
Direct Known Subclasses:
THashMap, THashSet, TObjectDoubleHashMap, TObjectFloatHashMap, TObjectIntHashMap, TObjectLongHashMap

public abstract class TObjectHash
extends THash
implements java.io.Serializable, TObjectHashingStrategy

An open addressed hashing implementation for Object types. Created: Sun Nov 4 08:56:06 2001

Version:
$Id: TObjectHash.java,v 1.16 2004/02/25 14:05:29 ericdf Exp $
Author:
Eric D. Friedman
See Also:
Serialized Form

Field Summary
protected  TObjectHashingStrategy _hashingStrategy
          the strategy used to hash objects in this collection.
protected  java.lang.Object[] _set
          the set of Objects
protected static java.lang.Object REMOVED
           
 
Fields inherited from class gnu.trove.THash
_free, _loadFactor, _maxSize, _size, DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR
 
Constructor Summary
TObjectHash()
          Creates a new TObjectHash instance with the default capacity and load factor.
TObjectHash(int initialCapacity)
          Creates a new TObjectHash instance whose capacity is the next highest prime above initialCapacity + 1 unless that value is already prime.
TObjectHash(int initialCapacity, float loadFactor)
          Creates a new TObjectHash instance with a prime value at or near the specified capacity and load factor.
TObjectHash(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy)
          Creates a new TObjectHash instance with a prime value at or near the specified capacity and load factor.
TObjectHash(int initialCapacity, TObjectHashingStrategy strategy)
          Creates a new TObjectHash instance whose capacity is the next highest prime above initialCapacity + 1 unless that value is already prime.
TObjectHash(TObjectHashingStrategy strategy)
          Creates a new TObjectHash instance with the default capacity and load factor and a custom hashing strategy.
 
Method Summary
protected  int capacity()
           
 java.lang.Object clone()
           
 int computeHashCode(java.lang.Object o)
          This is the default implementation of TObjectHashingStrategy: it delegates hashing to the Object's hashCode method.
 boolean contains(java.lang.Object obj)
          Searches the set for obj
 boolean equals(java.lang.Object o1, java.lang.Object o2)
          This is the default implementation of TObjectHashingStrategy: it delegates equality comparisons to the first parameter's equals() method.
 boolean forEach(TObjectProcedure procedure)
          Executes procedure for each element in the set.
protected  int index(java.lang.Object obj)
          Locates the index of obj.
protected  int insertionIndex(java.lang.Object obj)
          Locates the index at which obj can be inserted.
protected  void removeAt(int index)
          Delete the record at index.
protected  int setUp(int initialCapacity)
          initializes the Object set of this hash table.
protected  void throwObjectContractViolation(java.lang.Object o1, java.lang.Object o2)
          Convenience methods for subclasses to use in throwing exceptions about badly behaved user objects employed as keys.
 
Methods inherited from class gnu.trove.THash
clear, compact, ensureCapacity, isEmpty, postInsertHook, rehash, size, trimToSize
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_set

protected transient java.lang.Object[] _set
the set of Objects


_hashingStrategy

protected TObjectHashingStrategy _hashingStrategy
the strategy used to hash objects in this collection.


REMOVED

protected static final java.lang.Object REMOVED
Constructor Detail

TObjectHash

public TObjectHash()
Creates a new TObjectHash instance with the default capacity and load factor.


TObjectHash

public TObjectHash(TObjectHashingStrategy strategy)
Creates a new TObjectHash instance with the default capacity and load factor and a custom hashing strategy.

Parameters:
strategy - used to compute hash codes and to compare objects.

TObjectHash

public TObjectHash(int initialCapacity)
Creates a new TObjectHash instance whose capacity is the next highest prime above initialCapacity + 1 unless that value is already prime.

Parameters:
initialCapacity - an int value

TObjectHash

public TObjectHash(int initialCapacity,
                   TObjectHashingStrategy strategy)
Creates a new TObjectHash instance whose capacity is the next highest prime above initialCapacity + 1 unless that value is already prime. Uses the specified custom hashing strategy.

Parameters:
initialCapacity - an int value
strategy - used to compute hash codes and to compare objects.

TObjectHash

public TObjectHash(int initialCapacity,
                   float loadFactor)
Creates a new TObjectHash instance with a prime value at or near the specified capacity and load factor.

Parameters:
initialCapacity - used to find a prime capacity for the table.
loadFactor - used to calculate the threshold over which rehashing takes place.

TObjectHash

public TObjectHash(int initialCapacity,
                   float loadFactor,
                   TObjectHashingStrategy strategy)
Creates a new TObjectHash instance with a prime value at or near the specified capacity and load factor. Uses the specified custom hashing strategy.

Parameters:
initialCapacity - used to find a prime capacity for the table.
loadFactor - used to calculate the threshold over which rehashing takes place.
strategy - used to compute hash codes and to compare objects.
Method Detail

clone

public java.lang.Object clone()
Overrides:
clone in class THash
Returns:
a shallow clone of this collection

capacity

protected int capacity()
Specified by:
capacity in class THash
Returns:
the current physical capacity of the hash table.

removeAt

protected void removeAt(int index)
Description copied from class: THash
Delete the record at index. Reduces the size of the collection by one.

Overrides:
removeAt in class THash
Parameters:
index - an int value

setUp

protected int setUp(int initialCapacity)
initializes the Object set of this hash table.

Overrides:
setUp in class THash
Parameters:
initialCapacity - an int value
Returns:
an int value

forEach

public boolean forEach(TObjectProcedure procedure)
Executes procedure for each element in the set.

Parameters:
procedure - a TObjectProcedure value
Returns:
false if the loop over the set terminated because the procedure returned false for some value.

contains

public boolean contains(java.lang.Object obj)
Searches the set for obj

Parameters:
obj - an Object value
Returns:
a boolean value

index

protected int index(java.lang.Object obj)
Locates the index of obj.

Parameters:
obj - an Object value
Returns:
the index of obj or -1 if it isn't in the set.

insertionIndex

protected int insertionIndex(java.lang.Object obj)
Locates the index at which obj can be inserted. if there is already a value equal()ing obj in the set, returns that value's index as -index - 1.

Parameters:
obj - an Object value
Returns:
the index of a FREE slot at which obj can be inserted or, if obj is already stored in the hash, the negative value of that index, minus 1: -index -1.

computeHashCode

public final int computeHashCode(java.lang.Object o)
This is the default implementation of TObjectHashingStrategy: it delegates hashing to the Object's hashCode method.

Specified by:
computeHashCode in interface TObjectHashingStrategy
Returns:
the hashCode
See Also:
Object.hashCode()

equals

public final boolean equals(java.lang.Object o1,
                            java.lang.Object o2)
This is the default implementation of TObjectHashingStrategy: it delegates equality comparisons to the first parameter's equals() method.

Specified by:
equals in interface TObjectHashingStrategy
Parameters:
o1 - an Object value
o2 - an Object value
Returns:
true if the objects are equal
See Also:
Object.equals(Object)

throwObjectContractViolation

protected final void throwObjectContractViolation(java.lang.Object o1,
                                                  java.lang.Object o2)
                                           throws java.lang.IllegalArgumentException
Convenience methods for subclasses to use in throwing exceptions about badly behaved user objects employed as keys. We have to throw an IllegalArgumentException with a rather verbose message telling the user that they need to fix their object implementation to conform to the general contract for java.lang.Object.

Parameters:
o1 - the first of the equal elements with unequal hash codes.
o2 - the second of the equal elements with unequal hash codes.
Throws:
java.lang.IllegalArgumentException - the whole point of this method.

GNU Trove

GNU Trove is copyright © 2001-2003 Eric D. Friedman. All Rights Reserved.