org.apache.cassandra.utils
Class FastObjectHash<T>

java.lang.Object
  extended by org.apache.cassandra.utils.FastHash
      extended by org.apache.cassandra.utils.FastObjectHash<T>
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
FastHashMap

public abstract class FastObjectHash<T>
extends FastHash

An open addressed hashing implementation for Object types.

Author:
Avinash Lakshman

Field Summary
protected static java.lang.Object FREE
           
protected static java.lang.Object REMOVED
           
protected  java.lang.Object[] set_
          the set of Objects
 
Fields inherited from class org.apache.cassandra.utils.FastHash
autoCompactionFactor_, autoCompactRemovesRemaining_, DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, free_, loadFactor_, maxSize_, size_
 
Constructor Summary
FastObjectHash()
          Creates a new TObjectHash instance with the default capacity and load factor.
FastObjectHash(int initialCapacity)
          Creates a new TObjectHash instance whose capacity is the next highest prime above initialCapacity + 1 unless that value is already prime.
FastObjectHash(int initialCapacity, float loadFactor)
          Creates a new TObjectHash instance with a prime value at or near the specified capacity and load factor.
 
Method Summary
protected  int capacity()
           
 FastObjectHash<T> clone()
           
 int computeHashCode(T 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(T o1, T o2)
          This is the default implementation of TObjectHashingStrategy: it delegates equality comparisons to the first parameter's equals() method.
protected  int index(java.lang.Object obj)
          Locates the index of obj.
protected  int insertionIndex(T 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 org.apache.cassandra.utils.FastHash
calculateGrownCapacity, clear, compact, ensureCapacity, getAutoCompactionFactor, isEmpty, postInsertHook, reenableAutoCompaction, rehash, setAutoCompactionFactor, size, tempDisableAutoCompaction, 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


REMOVED

protected static final java.lang.Object REMOVED

FREE

protected static final java.lang.Object FREE
Constructor Detail

FastObjectHash

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


FastObjectHash

public FastObjectHash(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

FastObjectHash

public FastObjectHash(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.
Method Detail

clone

public FastObjectHash<T> clone()
Overrides:
clone in class FastHash
Returns:
a shallow clone of this collection

capacity

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

removeAt

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

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

setUp

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

Overrides:
setUp in class FastHash
Parameters:
initialCapacity - an int value
Returns:
an int 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(T 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(T o)
This is the default implementation of TObjectHashingStrategy: it delegates hashing to the Object's hashCode method.

Parameters:
o - for which the hashcode is to be computed
Returns:
the hashCode
See Also:
Object.hashCode()

equals

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

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.


Copyright © 2009 The Apache Software Foundation