|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.helidb.lang.hasher.ConstantSizeValueHasher<T>
T
- The type of value hashed.public class ConstantSizeValueHasher<T extends Comparable<T>>
This is a generic value-preserving Hasher
. It uses a
Serializer
for its serializing methods.
Constructor Summary | |
---|---|
ConstantSizeValueHasher(Serializer<T> serializer)
Constructor. |
Method Summary | |
---|---|
T |
fromBytes(byte[] barr)
Interpret the serialized hash value. |
int |
getHashLength()
Get the size of the hash in bytes. |
T |
hash(T o)
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(T o)
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 |
Constructor Detail |
---|
public ConstantSizeValueHasher(Serializer<T> serializer) throws IllegalArgumentException
serializer
- The serializer used for the serializing methods.
IllegalArgumentException
- If the serializer does not produce
values of a constant size.Method Detail |
---|
public boolean isPreservingValues()
Hasher
true
if v.equals(hasher.hash(v))
for all values v
accepted by the hasher.
isPreservingValues
in interface Hasher<T extends Comparable<T>,T extends Comparable<T>>
true
, always.public int getHashLength()
Hasher
byte
array created by Hasher.toBytes(Comparable)
and accepted by
Hasher.fromBytes(byte[])
.
getHashLength
in interface Hasher<T extends Comparable<T>,T extends Comparable<T>>
public T hash(T o) throws NullPointerException
Hasher
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.
hash
in interface Hasher<T extends Comparable<T>,T extends Comparable<T>>
o
- The value to hash.
NullPointerException
- If o == null
and the serializer does
not support null
values.public byte[] toBytes(T o)
Hasher
For a given Hasher
object, the byte arrays returned by this
method must always be of the same size.
toBytes
in interface Hasher<T extends Comparable<T>,T extends Comparable<T>>
o
- The hash to serialize.
public T fromBytes(byte[] barr)
Hasher
fromBytes
in interface Hasher<T extends Comparable<T>,T extends Comparable<T>>
barr
- The serialized hash value.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |