org.helidb.lang.hasher
Class CharacterToCharacterHasher

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

public class CharacterToCharacterHasher
extends Object
implements Hasher<Character,Character>

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

Hashes have a length of two bytes.

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

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

Field Summary
static CharacterToCharacterHasher INSTANCE
          The singleton instance.
 
Constructor Summary
CharacterToCharacterHasher()
           
 
Method Summary
 Character fromBytes(byte[] barr)
          Interpret the serialized hash value.
 int getHashLength()
          Get the size of the hash in bytes.
 Character hash(Character c)
          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(Character c)
          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 CharacterToCharacterHasher INSTANCE
The singleton instance. This may be used instead of instantiating the object.

Constructor Detail

CharacterToCharacterHasher

public CharacterToCharacterHasher()
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<Character,Character>
Returns:
The size of the hash, in number of bytes.

toBytes

public byte[] toBytes(Character c)
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<Character,Character>
Parameters:
c - The hash to serialize.
Returns:
The serialized hash.

fromBytes

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

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

hash

public Character hash(Character c)
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<Character,Character>
Parameters:
c - 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<Character,Character>
Returns:
true, always.