Class StreamHasher

java.lang.Object
org.aspectj.org.eclipse.jdt.internal.core.nd.StreamHasher

public final class StreamHasher extends Object
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 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

      public static long hash(String str)
      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.