Class XXHash


  • public class XXHash
    extends java.lang.Object
    Native bindings to xxhash.

    xxHash is an extremely fast Hash algorithm, running at RAM speed limits. It also successfully passes all tests from the SMHasher suite.

    • Method Detail

      • nXXH32

        public static int nXXH32​(long input,
                                 long length,
                                 int seed)
        Unsafe version of: 32
        Parameters:
        length - the number of bytes stored at memory address input
      • XXH32

        public static int XXH32​(java.nio.ByteBuffer input,
                                int seed)
        Calculates the 32-bits hash of sequence length bytes stored at memory address input.
        Parameters:
        input - the bytes to hash. The memory between input & input+length must be valid (allocated and read-accessible).
        seed - the seed that can be used to alter the result predictably
      • nXXH32_createState

        public static long nXXH32_createState()
        Unsafe version of: 32_createState
      • XXH32_createState

        @Nullable
        public static XXH32State XXH32_createState()
        Creates memory for XXH32_state_t. The state must then be initialized using 32_reset before first use.

        LWJGL note: This function simply delegates to the system malloc() function.

      • nXXH32_freeState

        public static int nXXH32_freeState​(long statePtr)
        Unsafe version of: 32_freeState
      • XXH32_freeState

        public static int XXH32_freeState​(XXH32State statePtr)
        Frees the specified XXH32_state_t.
        Parameters:
        statePtr - the state to free
      • nXXH32_copyState

        public static void nXXH32_copyState​(long dst_state,
                                            long src_state)
      • XXH32_copyState

        public static void XXH32_copyState​(XXH32State dst_state,
                                           XXH32State src_state)
      • nXXH32_reset

        public static int nXXH32_reset​(long statePtr,
                                       int seed)
        Unsafe version of: 32_reset
      • XXH32_reset

        public static int XXH32_reset​(XXH32State statePtr,
                                      int seed)
        Resets the specified XXH32_state_t.
        Parameters:
        statePtr - the XXH32_state_t to reset
        seed - the seed that can be used to alter the hashing result predictably
      • nXXH32_update

        public static int nXXH32_update​(long statePtr,
                                        long input,
                                        long length)
        Unsafe version of: 32_update
        Parameters:
        length - the number of bytes stored at memory address input
      • XXH32_update

        public static int XXH32_update​(XXH32State statePtr,
                                       java.nio.ByteBuffer input)
        These functions generate the xxHash of an input provided in multiple segments. Note that, for small input, they are slower than single-call functions, due to state management. For small input, prefer 32.

        XXH state must first be allocated, using 32_createState.

        Start a new hash by initializing state with a seed, using 32_reset.

        Then, feed the hash state by calling 32_update as many times as necessary. Obviously, input must be allocated and read accessible. The function returns an error code, with 0 meaning OK, and any other value meaning there is an error.

        Finally, a hash value can be produced anytime, by using 32_digest. This function returns the 32-bits hash as an int.

        It's still possible to continue inserting input into the hash state after a digest, and generate some new hashes later on, by calling again 32_digest.

        When done, free XXH state space.

        Parameters:
        statePtr - the XXH32_state_t to use
        input - the bytes to hash. The memory between input & input+length must be valid (allocated and read-accessible).
      • nXXH32_digest

        public static int nXXH32_digest​(long statePtr)
        Unsafe version of: 32_digest
      • XXH32_digest

        public static int XXH32_digest​(XXH32State statePtr)
        Returns the final 32-bits hash of the specified XXH32_state_t.
        Parameters:
        statePtr - the XXH32_state_t to use
      • nXXH32_canonicalFromHash

        public static void nXXH32_canonicalFromHash​(long dst,
                                                    int hash)
        Unsafe version of: 32_canonicalFromHash
      • XXH32_canonicalFromHash

        public static void XXH32_canonicalFromHash​(XXH32Canonical dst,
                                                   int hash)
        Default result type for XXH functions are primitive unsigned 32 and 64 bits.

        The canonical representation uses human-readable write convention, aka big-endian (large digits first). These functions allow transformation of hash result into and from its canonical format. This way, hash values can be written into a file / memory, remaining comparable across different systems.

        Parameters:
        dst - the destination canonical representation
        hash - the source hash
      • nXXH32_hashFromCanonical

        public static int nXXH32_hashFromCanonical​(long src)
        Unsafe version of: 32_hashFromCanonical
      • XXH32_hashFromCanonical

        public static int XXH32_hashFromCanonical​(XXH32Canonical src)
        Transforms the specified canonical representation to a primitive value.
        Parameters:
        src - the source canonical representation
      • nXXH64

        public static long nXXH64​(long input,
                                  long length,
                                  long seed)
        Unsafe version of: 64
        Parameters:
        length - the number of bytes stored at memory address input
      • XXH64

        public static long XXH64​(java.nio.ByteBuffer input,
                                 long seed)
        64-bit version of 32.

        This function runs 2x faster on 64-bits systems, but slower on 32-bits systems.

        Parameters:
        input - the bytes to hash. The memory between input & input+length must be valid (allocated and read-accessible).
        seed - the seed that can be used to alter the result predictably
      • nXXH64_createState

        public static long nXXH64_createState()
        Unsafe version of: 64_createState
      • nXXH64_freeState

        public static int nXXH64_freeState​(long statePtr)
        Unsafe version of: 64_freeState
      • XXH64_freeState

        public static int XXH64_freeState​(XXH64State statePtr)
        64-bit version of 32_freeState.
        Parameters:
        statePtr - the state to free
      • nXXH64_copyState

        public static void nXXH64_copyState​(long dst_state,
                                            long src_state)
      • XXH64_copyState

        public static void XXH64_copyState​(XXH64State dst_state,
                                           XXH64State src_state)
      • nXXH64_reset

        public static int nXXH64_reset​(long statePtr,
                                       long seed)
        Unsafe version of: 64_reset
      • XXH64_reset

        public static int XXH64_reset​(XXH64State statePtr,
                                      long seed)
        64-bit version of 32_reset.
        Parameters:
        statePtr - the XXH64_state_t to reset
        seed - the seed that can be used to alter the hashing result predictably
      • nXXH64_update

        public static int nXXH64_update​(long statePtr,
                                        long input,
                                        long length)
        Unsafe version of: 64_update
        Parameters:
        length - the number of bytes stored at memory address input
      • XXH64_update

        public static int XXH64_update​(XXH64State statePtr,
                                       java.nio.ByteBuffer input)
        64-bit version of 32_update.
        Parameters:
        statePtr - the XXH64_state_t to use
        input - the bytes to hash. The memory between input & input+length must be valid (allocated and read-accessible).
      • nXXH64_digest

        public static long nXXH64_digest​(long statePtr)
        Unsafe version of: 64_digest
      • XXH64_digest

        public static long XXH64_digest​(XXH64State statePtr)
        64-bit version of 32_digest.
        Parameters:
        statePtr - the XXH64_state_t to use
      • nXXH64_canonicalFromHash

        public static void nXXH64_canonicalFromHash​(long dst,
                                                    long hash)
        Unsafe version of: 64_canonicalFromHash
      • XXH64_canonicalFromHash

        public static void XXH64_canonicalFromHash​(XXH64Canonical dst,
                                                   long hash)
        64-bit version of 32_canonicalFromHash.
        Parameters:
        dst - the destination canonical representation
        hash - the source hash
      • nXXH64_hashFromCanonical

        public static long nXXH64_hashFromCanonical​(long src)
        Unsafe version of: 64_hashFromCanonical
      • XXH64_hashFromCanonical

        public static long XXH64_hashFromCanonical​(XXH64Canonical src)
        64-bit version of 32_hashFromCanonical.
        Parameters:
        src - the source canonical representation