Last active
March 16, 2026 08:24
-
-
Save jpountz/4489305 to your computer and use it in GitHub Desktop.
xxhash streaming hashing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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