com.planetj.math.rabinhash
Class RabinHashFunction64

java.lang.Object
  extended bycom.planetj.math.rabinhash.RabinHashFunction64
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public final class RabinHashFunction64
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

This class provides an implementation of a hash function based on Rabin fingerprints, one which can efficiently produce a 64-bit hash value for a sequence of bytes. Its services and characteristics are entirely analogous to that of RabinHashFunction32, except that hash values are 64 bits and the implementation works in terms of degree 64 polynomials represented as longs.

Please see the documentation and comments for RabinHashFunction32 for more information.

Since:
2.0
Version:
2.0
Author:
Sean Owen
See Also:
Serialized Form

Field Summary
static RabinHashFunction64 DEFAULT_HASH_FUNCTION
          Default hash function, provided for convenience.
 
Constructor Summary
RabinHashFunction64(long P)
          Creates a RabinHashFunction64 based on the specified polynomial.
 
Method Summary
 boolean equals(java.lang.Object o)
           
 long getP()
           
 long hash(byte[] A)
          Return the Rabin hash value of an array of bytes.
 long hash(java.nio.ByteBuffer A)
          Returns the Rabin hash value of a ByteBuffer.
 long hash(char[] A)
          Return the Rabin hash value of an array of chars.
 long hash(java.io.File f)
          Computes the Rabin hash value of the contents of a file.
 long hash(java.io.InputStream is)
          Computes the Rabin hash value of the data from an InputStream.
 long hash(long[] A)
          Returns the Rabin hash value of an array of longs.
 long hash(java.nio.LongBuffer A)
          Returns the Rabin hash value of an LongBuffer.
 long hash(java.io.Serializable obj)
          Returns the Rabin hash value of a serializable object.
 long hash(java.lang.String s)
          Computes the Rabin hash value of a String.
 long hash(java.net.URL url)
          Computes the Rabin hash value of the contents of a file, specified by URL.
 int hashCode()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_HASH_FUNCTION

public static final RabinHashFunction64 DEFAULT_HASH_FUNCTION
Default hash function, provided for convenience.

Constructor Detail

RabinHashFunction64

public RabinHashFunction64(long P)

Creates a RabinHashFunction64 based on the specified polynomial.

This class does not test the polynomial for irreducibility; therefore this constructor should only be used with polynomials that are already known to be irreducible, or else the hash function will not perform optimally.

Parameters:
P - a degree 64 polynomial over GF(2), represented as a long
Method Detail

getP

public long getP()
Returns:
irreducible polynomial used in this hash function, represented as a long

hash

public long hash(byte[] A)

Return the Rabin hash value of an array of bytes.

Parameters:
A - the array of bytes
Returns:
the hash value
Throws:
java.lang.NullPointerException - if A is null

hash

public long hash(char[] A)

Return the Rabin hash value of an array of chars.

Parameters:
A - the array of chars
Returns:
the hash value
Throws:
java.lang.NullPointerException - if A is null

hash

public long hash(long[] A)

Returns the Rabin hash value of an array of longs. This method is the most efficient of all the hash methods, so it should be used when possible.

Parameters:
A - array of longs
Returns:
the hash value
Throws:
java.lang.NullPointerException - if A is null

hash

public long hash(java.nio.ByteBuffer A)

Returns the Rabin hash value of a ByteBuffer.

Parameters:
A - ByteBuffer
Returns:
the hash value
Throws:
java.lang.NullPointerException - if A is null

hash

public long hash(java.nio.LongBuffer A)

Returns the Rabin hash value of an LongBuffer.

Parameters:
A - LongBuffer
Returns:
the hash value
Throws:
java.lang.NullPointerException - if A is null

hash

public long hash(java.io.Serializable obj)

Returns the Rabin hash value of a serializable object.

Parameters:
obj - the object to be hashed
Returns:
the hash value
Throws:
java.lang.NullPointerException - if obj is null

hash

public long hash(java.lang.String s)

Computes the Rabin hash value of a String.

Parameters:
s - the string to be hashed
Returns:
the hash value
Throws:
java.lang.NullPointerException - if s is null

hash

public long hash(java.io.File f)
          throws java.io.FileNotFoundException,
                 java.io.IOException

Computes the Rabin hash value of the contents of a file.

Parameters:
f - the file to be hashed
Returns:
the hash value of the file
Throws:
java.io.FileNotFoundException - if the file cannot be found
java.io.IOException - if an error occurs while reading the file
java.lang.NullPointerException - if f is null

hash

public long hash(java.net.URL url)
          throws java.io.IOException

Computes the Rabin hash value of the contents of a file, specified by URL.

Parameters:
url - the URL of the file to be hashed
Returns:
the hash value of the file
Throws:
java.io.IOException - if an error occurs while reading from the URL
java.lang.NullPointerException - if url is null

hash

public long hash(java.io.InputStream is)
          throws java.io.IOException

Computes the Rabin hash value of the data from an InputStream.

Parameters:
is - the InputStream to hash
Returns:
the hash value of the data from the InputStream
Throws:
java.io.IOException - if an error occurs while reading from the InputStream
java.lang.NullPointerException - if stream is null

equals

public boolean equals(java.lang.Object o)

hashCode

public int hashCode()

toString

public java.lang.String toString()