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 Details

    • MIN_LENGTH

      public static final int MIN_LENGTH
      The minimum length of the salt. Salts shorter than this will not validate.
      See Also:
  • Constructor Details

    • Hasher

      public Hasher()
  • Method Details

    • hash

      public abstract String hash(String input)
      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

      public abstract void setSalt(String salt)
      The salt is transient, it must be set **to the same value as it was trained with** after the Model is deserialized.
      Parameters:
      salt - Salt value.
    • validateSalt

      public static boolean validateSalt(String salt)
      Salt validation is currently a test to see if the string is longer than MIN_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.