Skip to content

Instantly share code, notes, and snippets.

@jpountz
Last active March 16, 2026 08:24
Show Gist options
  • Select an option

  • Save jpountz/4489305 to your computer and use it in GitHub Desktop.

Select an option

Save jpountz/4489305 to your computer and use it in GitHub Desktop.
xxhash streaming hashing
XXHashFactory factory = XXHashFactory.fastestInstance();
byte[] data = "12345345234572".getBytes("UTF-8");
ByteArrayInputStream in = new ByteArrayInputStream(data);
int seed = 0x9747b28c; // used to initialize the hash value, use whatever
// value you want, but always the same
StreamingXXHash32 hash32 = factory.newStreamingHash32(seed);
byte[] buf = new byte[8]; // for real-world usage, use a larger buffer, like 8192 bytes
for (;;) {
int read = in.read(buf);
if (read == -1) {
break;
}
hash32.update(buf, 0, read);
}
int hash = hash32.getValue();
System.out.println("Streaming hash: " + hash);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment