Package org.tribuo.hash
Class Hasher
java.lang.Object
org.tribuo.hash.Hasher
- All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.config.Configurable
,com.oracle.labs.mlrg.olcut.provenance.Provenancable<com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance>
,Serializable
,ProtoSerializable<org.tribuo.protos.core.HasherProto>
- Direct Known Subclasses:
HashCodeHasher
,MessageDigestHasher
,ModHashCodeHasher
public abstract class Hasher
extends Object
implements com.oracle.labs.mlrg.olcut.config.Configurable, com.oracle.labs.mlrg.olcut.provenance.Provenancable<com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance>, Serializable, ProtoSerializable<org.tribuo.protos.core.HasherProto>
An abstract base class for hash functions used to hash the names of features.
Hasher implementations do not serialize the salt in their serialized forms, and thus the salt must be set after deserialization.
- See Also:
-
Field Summary
Fields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract String
Hashes the supplied input using the hashing function.abstract void
The salt is transient, it must be set **to the same value as it was trained with** after theModel
is deserialized.static boolean
validateSalt
(String salt) Salt validation is currently a test to see if the string is longer thanMIN_LENGTH
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.oracle.labs.mlrg.olcut.config.Configurable
postConfig
Methods inherited from interface org.tribuo.protos.ProtoSerializable
serialize
Methods inherited from interface com.oracle.labs.mlrg.olcut.provenance.Provenancable
getProvenance
-
Field Details
-
MIN_LENGTH
public static final int MIN_LENGTHThe minimum length of the salt. Salts shorter than this will not validate.- See Also:
-
-
Constructor Details
-
Hasher
public Hasher()
-
-
Method Details
-
hash
Hashes the supplied input using the hashing function.If the salt is not set then this throws
IllegalStateException
.- Parameters:
input
- The input to hash.- Returns:
- A String representation of the hashed output.
-
setSalt
The salt is transient, it must be set **to the same value as it was trained with** after theModel
is deserialized.- Parameters:
salt
- Salt value.
-
validateSalt
Salt validation is currently a test to see if the string is longer thanMIN_LENGTH
.When this method is updated Hasher must update it's serialVersionUID, this ensures that serialised instances of downstream classes which call this method are invalidated, as changes to validateSalt may invalidate old salts, and there is no other way to communicate this to the developer.
- Parameters:
salt
- String to validate.- Returns:
- True if the salt is valid, false otherwise.
-