# Class XxHash64

java.lang.Object
org.apache.datasketches.hash.XxHash64

public final class XxHash64 extends Object
The XxHash is a fast, non-cryptographic, 64-bit hash function that has excellent avalanche and 2-way bit independence properties. This java version adapted from the C++ version and the OpenHFT/Zero-Allocation-Hashing implementation referenced below as inspiration.

The C++ source repository: https://github.com/Cyan4973/xxHash. It has a BSD 2-Clause License: http://www.opensource.org/licenses/bsd-license.php. See LICENSE.

Portions of this code were adapted from OpenHFT/Zero-Allocation-Hashing, which has an Apache 2 license as does this site. See LICENSE.

Author:
  Lee Rhodes

## Method Summary

Modifier and Type
Method
Description
`static long`
`hash(long in, long seed)`
Returns a 64-bit hash from a single long.
`static long`
`hash(MemorySegment seg, long offsetBytes, long lengthBytes, long seed)`
Returns the 64-bit hash of the sequence of bytes in the given MemorySegment
`static long`
`hashBytes(byte[] arr, int offsetBytes, int lengthBytes, long seed)`
Hash the given arr starting at the given offset and continuing for the given length using the given seed.
`static long`
`hashChars(char[] arr, int offsetChars, int lengthChars, long seed)`
Hash the given arr starting at the given offset and continuing for the given length using the given seed.
`static long`
`hashDoubles(double[] arr, int offsetDoubles, int lengthDoubles, long seed)`
Hash the given arr starting at the given offset and continuing for the given length using the given seed.
`static long`
`hashFloats(float[] arr, int offsetFloats, int lengthFloats, long seed)`
Hash the given arr starting at the given offset and continuing for the given length using the given seed.
`static long`
`hashInts(int[] arr, int offsetInts, int lengthInts, long seed)`
Hash the given arr starting at the given offset and continuing for the given length using the given seed.
`static long`
`hashLongs(long[] arr, int offsetLongs, int lengthLongs, long seed)`
Hash the given arr starting at the given offset and continuing for the given length using the given seed.
`static long`
`hashShorts(short[] arr, int offsetShorts, int lengthShorts, long seed)`
Hash the given arr starting at the given offset and continuing for the given length using the given seed.
`static long`
`hashString(String str, int offsetChars, int lengthChars, long seed)`
Hash the given arr starting at the given offset and continuing for the given length using the given seed.

### Methods inherited from class Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### hash

public static long hash(MemorySegment seg, long offsetBytes, long lengthBytes, long seed)
Returns the 64-bit hash of the sequence of bytes in the given MemorySegment

Parameters:
  `seg` - A reference to the relevant MemorySegment.
  `offsetBytes` - offset in bytes in the given segment.
  `lengthBytes` - the length in bytes to be hashed
  `seed` - a given seed
Returns:
  the 64-bit hash of the sequence of bytes.

### hash

public static long hash(long in, long seed)
Returns a 64-bit hash from a single long. This method has been optimized for speed when only a single hash of a long is required.

Parameters:
  `in` - A long.
  `seed` - A long valued seed.
Returns:
  the hash.

### hashBytes

public static long hashBytes(byte[] arr, int offsetBytes, int lengthBytes, long seed)
Hash the given arr starting at the given offset and continuing for the given length using the given seed.

Parameters:
  `arr` - the given array
  `offsetBytes` - starting at this offset
  `lengthBytes` - continuing for this length
  `seed` - the given seed
Returns:
  the hash

### hashShorts

public static long hashShorts(short[] arr, int offsetShorts, int lengthShorts, long seed)
Hash the given arr starting at the given offset and continuing for the given length using the given seed.

Parameters:
  `arr` - the given array
  `offsetShorts` - starting at this offset
  `lengthShorts` - continuing for this length
  `seed` - the given seed
Returns:
  the hash

### hashChars

public static long hashChars(char[] arr, int offsetChars, int lengthChars, long seed)
Hash the given arr starting at the given offset and continuing for the given length using the given seed.

Parameters:
  `arr` - the given array
  `offsetChars` - starting at this offset
  `lengthChars` - continuing for this length
  `seed` - the given seed
Returns:
  the hash

### hashInts

public static long hashInts(int[] arr, int offsetInts, int lengthInts, long seed)
Hash the given arr starting at the given offset and continuing for the given length using the given seed.

Parameters:
  `arr` - the given array
  `offsetInts` - starting at this offset
  `lengthInts` - continuing for this length
  `seed` - the given seed
Returns:
  the hash

### hashLongs

public static long hashLongs(long[] arr, int offsetLongs, int lengthLongs, long seed)
Hash the given arr starting at the given offset and continuing for the given length using the given seed.

Parameters:
  `arr` - the given array
  `offsetLongs` - starting at this offset
  `lengthLongs` - continuing for this length
  `seed` - the given seed
Returns:
  the hash

### hashFloats

public static long hashFloats(float[] arr, int offsetFloats, int lengthFloats, long seed)
Hash the given arr starting at the given offset and continuing for the given length using the given seed.

Parameters:
  `arr` - the given array
  `offsetFloats` - starting at this offset
  `lengthFloats` - continuing for this length
  `seed` - the given seed
Returns:
  the hash

### hashDoubles

public static long hashDoubles(double[] arr, int offsetDoubles, int lengthDoubles, long seed)
Hash the given arr starting at the given offset and continuing for the given length using the given seed.

Parameters:
  `arr` - the given array
  `offsetDoubles` - starting at this offset
  `lengthDoubles` - continuing for this length
  `seed` - the given seed
Returns:
  the hash

### hashString

public static long hashString(String str, int offsetChars, int lengthChars, long seed)
Hash the given arr starting at the given offset and continuing for the given length using the given seed.

Parameters:
  `str` - the given string
  `offsetChars` - starting at this offset
  `lengthChars` - continuing for this length
  `seed` - the given seed
Returns:
  the hash