Package org.tribuo.hash
Class MessageDigestHasher
java.lang.Object
org.tribuo.hash.Hasher
org.tribuo.hash.MessageDigestHasher
- 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>
Hashes Strings using the supplied MessageDigest type.
MessageDigestHasher does not serialize the salt in its serialized forms, and thus the salt must be set after deserialization.
- See Also:
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Protobuf serialization version.static final Charset
Alias forStandardCharsets.UTF_8
.Fields inherited from class org.tribuo.hash.Hasher
MIN_LENGTH
Fields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER
-
Constructor Summary
ConstructorDescriptionMessageDigestHasher
(String hashType, String salt) Constructs a message digest hasher. -
Method Summary
Modifier and TypeMethodDescriptionstatic MessageDigestHasher
deserializeFromProto
(int version, String className, com.google.protobuf.Any message) Deserialization factory.boolean
static Supplier<MessageDigest>
getDigestSupplier
(String hashType) Creates a supplier for the specified hash type.com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance
Hashes the supplied input using the hashing function.int
hashCode()
void
Used by the OLCUT configuration system, and should not be called by external code.org.tribuo.protos.core.HasherProto
Serializes this object to a protobuf.void
The salt is transient, it must be set **to the same value as it was trained with** after theModel
is deserialized.toString()
Methods inherited from class org.tribuo.hash.Hasher
validateSalt
-
Field Details
-
CURRENT_VERSION
public static final int CURRENT_VERSIONProtobuf serialization version.- See Also:
-
utf8Charset
Alias forStandardCharsets.UTF_8
.
-
-
Constructor Details
-
MessageDigestHasher
Constructs a message digest hasher.- Parameters:
hashType
- The hash function to use.salt
- The salt value.
-
-
Method Details
-
deserializeFromProto
public static MessageDigestHasher deserializeFromProto(int version, String className, com.google.protobuf.Any message) throws com.google.protobuf.InvalidProtocolBufferException Deserialization factory.Note the salt must be set after the hasher has been deserialized.
- Parameters:
version
- The serialized object version number.className
- The class name.message
- The serialized data.- Returns:
- The deserialized object.
- Throws:
com.google.protobuf.InvalidProtocolBufferException
- If the protobuf could not be parsed from themessage
.
-
postConfig
public void postConfig() throws com.oracle.labs.mlrg.olcut.config.PropertyExceptionUsed by the OLCUT configuration system, and should not be called by external code.- Throws:
com.oracle.labs.mlrg.olcut.config.PropertyException
-
hash
Description copied from class:Hasher
Hashes the supplied input using the hashing function.If the salt is not set then this throws
IllegalStateException
. -
serialize
public org.tribuo.protos.core.HasherProto serialize()Description copied from interface:ProtoSerializable
Serializes this object to a protobuf.- Returns:
- The protobuf.
-
setSalt
Description copied from class:Hasher
The salt is transient, it must be set **to the same value as it was trained with** after theModel
is deserialized. -
toString
-
equals
-
hashCode
public int hashCode() -
getProvenance
public com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance getProvenance() -
getDigestSupplier
Creates a supplier for the specified hash type.- Parameters:
hashType
- The hash type, used to specify the MessageDigest implementation.- Returns:
- A supplier for the MessageDigest.
-