org.helidb.lang.hasher
Class IntegerToIntegerHasher

java.lang.Object
  extended by org.helidb.lang.hasher.IntegerToIntegerHasher
All Implemented Interfaces:
Hasher<Integer,Integer>

public class IntegerToIntegerHasher
extends Object
implements Hasher<Integer,Integer>

This is a value-preserving Integer hasher. It does not support null values.

Hashes have a length of four bytes.

Since this object does not contain any internal state, the singleton instance INSTANCE may be used instead of instantiating the class.

Since:
1.0
Author:
Karl Gustafsson
In_jar:
helidb-core

Field Summary
static IntegerToIntegerHasher INSTANCE
          The singleton instance.
 
Constructor Summary
IntegerToIntegerHasher()
           
 
Method Summary
 Integer fromBytes(byte[] barr)
          Interpret the serialized hash value.
 int getHashLength()
          Get the size of the hash in bytes.
 Integer hash(Integer i)
          Hash the supplied value.
 boolean isPreservingValues()
          Does the hashing operation not modify the hashed value at all? This is true if v.equals(hasher.hash(v)) for all values v accepted by the hasher.
 byte[] toBytes(Integer i)
          Serialize the hash to a byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE

public static final IntegerToIntegerHasher INSTANCE
The singleton instance. This may be used instead of instantiating the object.

Constructor Detail

IntegerToIntegerHasher

public IntegerToIntegerHasher()
Method Detail

getHashLength

public int getHashLength()
Description copied from interface: Hasher
Get the size of the hash in bytes. This is the size of the byte array created by Hasher.toBytes(Comparable) and accepted by Hasher.fromBytes(byte[]).

Specified by:
getHashLength in interface Hasher<Integer,Integer>
Returns:
The size of the hash, in number of bytes.

toBytes

public byte[] toBytes(Integer i)
Description copied from interface: Hasher
Serialize the hash to a byte array.

For a given Hasher object, the byte arrays returned by this method must always be of the same size.

Specified by:
toBytes in interface Hasher<Integer,Integer>
Parameters:
i - The hash to serialize.
Returns:
The serialized hash.

fromBytes

public Integer fromBytes(byte[] barr)
Description copied from interface: Hasher
Interpret the serialized hash value.

Specified by:
fromBytes in interface Hasher<Integer,Integer>
Parameters:
barr - The serialized hash value.
Returns:
The hash value.

hash

public Integer hash(Integer i)
Description copied from interface: Hasher
Hash the supplied value.

Hashing may be a fairly expensive operation, depending on the implementation. Clients should try to reuse the result from this method as much as possible.

Specified by:
hash in interface Hasher<Integer,Integer>
Parameters:
i - The value to hash.
Returns:
The hash value.

isPreservingValues

public boolean isPreservingValues()
Description copied from interface: Hasher
Does the hashing operation not modify the hashed value at all? This is true if v.equals(hasher.hash(v)) for all values v accepted by the hasher.

Specified by:
isPreservingValues in interface Hasher<Integer,Integer>
Returns:
true, always.