Package org.apache.commons.codec.digest
Class MurmurHash3.IncrementalHash32x86
java.lang.Object
org.apache.commons.codec.digest.MurmurHash3.IncrementalHash32x86
- Direct Known Subclasses:
MurmurHash3.IncrementalHash32
- Enclosing class:
- MurmurHash3
Generates 32-bit hash from input bytes. Bytes can be added incrementally and the new
hash computed.
This is an implementation of the 32-bit hash function MurmurHash3_x86_32
from Austin Appleby's original MurmurHash3 c++
code in SMHasher.
- Since:
- 1.14
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
The size of byte blocks that are processed together.private int
The current running hash.private int
The total number of input bytes added since the start.private final byte[]
Up to 3 unprocessed bytes from input data.private int
The number of unprocessed bytes in the tail data. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal void
add
(byte[] data, int offset, int length) Adds the byte array to the current incremental hash.final int
end()
Generates the 32-bit hash value.(package private) int
finalise
(int hash, int unprocessedLength, byte[] unprocessed, int totalLen) Finalizes the running hash to the output 32-bit hash by processing remaining bytes and performing final mixing.private static int
orBytes
(byte b1, byte b2, byte b3, byte b4) Combines the bytes using an Or operation (|
in a little-endian representation of a 32-bit integer; byte 1 will be the least significant byte, byte 4 the most significant.final void
start
(int seed) Starts a new incremental hash.
-
Field Details
-
BLOCK_SIZE
private static final int BLOCK_SIZEThe size of byte blocks that are processed together.- See Also:
-
unprocessed
private final byte[] unprocessedUp to 3 unprocessed bytes from input data. -
unprocessedLength
private int unprocessedLengthThe number of unprocessed bytes in the tail data. -
totalLen
private int totalLenThe total number of input bytes added since the start. -
hash
private int hashThe current running hash. This must be finalised to generate the 32-bit hash value.
-
-
Constructor Details
-
IncrementalHash32x86
public IncrementalHash32x86()
-
-
Method Details
-
start
public final void start(int seed) Starts a new incremental hash.- Parameters:
seed
- The initial seed value
-
add
public final void add(byte[] data, int offset, int length) Adds the byte array to the current incremental hash.- Parameters:
data
- The input byte arrayoffset
- The offset of datalength
- The length of array
-
end
public final int end()Generates the 32-bit hash value. Repeat calls to this method with no additional data will generate the same hash value.- Returns:
- The 32-bit hash
-
finalise
int finalise(int hash, int unprocessedLength, byte[] unprocessed, int totalLen) Finalizes the running hash to the output 32-bit hash by processing remaining bytes and performing final mixing.- Parameters:
hash
- The running hashunprocessedLength
- The number of unprocessed bytes in the tail data.unprocessed
- Up to 3 unprocessed bytes from input data.totalLen
- The total number of input bytes added since the start.- Returns:
- The 32-bit hash
-
orBytes
private static int orBytes(byte b1, byte b2, byte b3, byte b4) Combines the bytes using an Or operation (|
in a little-endian representation of a 32-bit integer; byte 1 will be the least significant byte, byte 4 the most significant.- Parameters:
b1
- The first byteb2
- The second byteb3
- The third byteb4
- The fourth byte- Returns:
- The 32-bit integer
-