Examples of XXHashFactory

Only the {@link #safeInstance() safe instance} is guaranteed to work on yourJVM, as a consequence it is advised to use the {@link #fastestInstance()} or{@link #fastestJavaInstance()} to pull a {@link XXHashFactory} instance.

All methods from this class are very costly, so you should get an instance once, and then reuse it whenever possible. This is typically done by storing a {@link XXHashFactory} instance in a static field.


Examples of net.jpountz.xxhash.XXHashFactory

    blockExample();
    streamingExample();
  }

  private static void blockExample() throws UnsupportedEncodingException {
    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);
    System.out.println("Block hash: " + hash);
  }
View Full Code Here

Examples of net.jpountz.xxhash.XXHashFactory

    int hash = hash32.hash(data, 0, data.length, seed);
    System.out.println("Block hash: " + hash);
  }

  private static void streamingExample() throws IOException {
    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;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.