com.mhhe.clrs2e
Class MultiplicationMethod

java.lang.Object
  |
  +--com.mhhe.clrs2e.MultiplicationMethod

public class MultiplicationMethod
extends java.lang.Object

Implements the multiplication method of hashing on pages 231-232 of Introduction to Algorithms, Second edition.


Field Summary
private  long bitMask
          If the table size is a power of 2, the bit mask used.
private  boolean isPowerOf2
          true if the table size is a power of 2, false otherwise.
private  int shiftAmount
          If the table size is a power of 2, the shift amount used.
private  int tableSize
          The size of the hash table being used.
 
Constructor Summary
MultiplicationMethod(int size)
          Creates a hash function that uses the multiplication method.
 
Method Summary
 int hash(java.lang.Object o)
          Returns the hash value of an object, based on its Java hashCode value and the multiplication method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tableSize

private int tableSize
The size of the hash table being used.


isPowerOf2

private boolean isPowerOf2
true if the table size is a power of 2, false otherwise.


shiftAmount

private int shiftAmount
If the table size is a power of 2, the shift amount used.


bitMask

private long bitMask
If the table size is a power of 2, the bit mask used.

Constructor Detail

MultiplicationMethod

public MultiplicationMethod(int size)
Creates a hash function that uses the multiplication method.

Parameters:
size - The size of the hash table.
Method Detail

hash

public int hash(java.lang.Object o)
Returns the hash value of an object, based on its Java hashCode value and the multiplication method.

Parameters:
o - The object being hashed. If the object implements DynamicSetElement, the hash value is of its key.