xxhash hashing. This package supports both block hashing via
net. and streaming hashing via
net.. Have a look at
net. to know how to get instances of these
interfaces.
Streaming hashing is a little slower but doesn't require to load the whole stream into memory.
Sample block usage:
XXHashFactory factory = XXHashFactory.fastestInstance();
byte[] data = "12345345234572".getBytes("UTF-8");
XXHash32 hash32 = factory.hash32();
int seed = 0x9747b28c; // used to initialize the hash value, use whatever
// value you want, but always the same
int hash = hash32.hash(data, 0, data.length, seed);
Sample streaming usage:
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();
| Modifier and Type | Class and Description |
|---|---|
| pack-priv abstract class | |
| pack-priv abstract class | |
| public abstract class | StreamingXXHash32
Streaming interface for |
| pack-priv class | |
| public abstract class | StreamingXXHash64
Streaming interface for |
| pack-priv class | |
| public abstract class | XXHash32
A 32-bits hash. |
| pack-priv class | |
| public abstract class | XXHash64
A 64-bits hash. |
| pack-priv class | |
| public class | XXHashFactory
Entry point to get |
| Modifier and Type | Enum and Description |
|---|---|
| pack-priv enum | |
| pack-priv enum |