Package org.apache.datasketches.memory
Class XxHash
java.lang.Object
org.apache.datasketches.memory.XxHash
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 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 TypeMethodDescriptionstatic long
hashByteArr
(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
hashCharArr
(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
hashDoubleArr
(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
hashFloatArr
(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
hashIntArr
(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
hashLong
(long in, long seed) Returns a 64-bit hash from a single long.static long
hashLongArr
(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
hashShortArr
(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.
-
Method Details
-
hashByteArr
public static long hashByteArr(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 arrayoffsetBytes
- starting at this offsetlengthBytes
- continuing for this lengthseed
- the given seed- Returns:
- the hash
-
hashShortArr
public static long hashShortArr(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 arrayoffsetShorts
- starting at this offsetlengthShorts
- continuing for this lengthseed
- the given seed- Returns:
- the hash
-
hashCharArr
public static long hashCharArr(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 arrayoffsetChars
- starting at this offsetlengthChars
- continuing for this lengthseed
- the given seed- Returns:
- the hash
-
hashIntArr
public static long hashIntArr(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 arrayoffsetInts
- starting at this offsetlengthInts
- continuing for this lengthseed
- the given seed- Returns:
- the hash
-
hashLongArr
public static long hashLongArr(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 arrayoffsetLongs
- starting at this offsetlengthLongs
- continuing for this lengthseed
- the given seed- Returns:
- the hash
-
hashLong
public static long hashLong(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.
-
hashFloatArr
public static long hashFloatArr(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 arrayoffsetFloats
- starting at this offsetlengthFloats
- continuing for this lengthseed
- the given seed- Returns:
- the hash
-
hashDoubleArr
public static long hashDoubleArr(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 arrayoffsetDoubles
- starting at this offsetlengthDoubles
- continuing for this lengthseed
- the given seed- Returns:
- the hash
-
hashString
Hash the given arr starting at the given offset and continuing for the given length using the given seed.- Parameters:
str
- the given stringoffsetChars
- starting at this offsetlengthChars
- continuing for this lengthseed
- the given seed- Returns:
- the hash
-