Class StreamHasher
java.lang.Object
org.aspectj.org.eclipse.jdt.internal.core.nd.StreamHasher
Computes a 64-bit hash value of a character stream that can be supplied one chunk at a time.
Usage:
StreamHasher hasher = new StreamHasher();
for (long offset = 0; offset < streamLength; offset += chunkLength) {
hasher.addChunk(offset, chunkOfCharacters);
}
int64 hashValue = hasher.computeHash();
Based on lookup3.c by Bob Jenkins from {@link "http://burtleburtle.net/bob/c/lookup3.c"}-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChunk(char[] chunk)Adds a chunk of data to the hasher.longComputes and returns the hash value.static longComputes a 64-bit hash value of a String.
-
Constructor Details
-
StreamHasher
public StreamHasher()
-
-
Method Details
-
addChunk
public void addChunk(char[] chunk)Adds a chunk of data to the hasher.- Parameters:
chunk- Contents of the chunk.
-
computeHash
public long computeHash()Computes and returns the hash value. Must be called once after the last chunk.- Returns:
- The hash value of the character stream.
-
hash
Computes a 64-bit hash value of a String. The resulting hash value is zero if the string is empty.- Parameters:
str- The string to hash.- Returns:
- The hash value.
-