Package com.helger.base.hashcode
Class HashCodeCalculator
java.lang.Object
com.helger.base.hashcode.HashCodeCalculator
This class provides the hash code generation for different data types.
- Author:
- Philip Helger
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe hash code value to be used fornullvalues.static final intUse a prime number as the start.static final intEach value is multiplied with this value. 31 because it can easily be optimized to(1 << 5) - 1. -
Method Summary
Modifier and TypeMethodDescriptionstatic intappend(int nPrevHashCode, boolean x) Atomic type hash code generation.static intappend(int nPrevHashCode, boolean[] x) Atomic type hash code generation.static intappend(int nPrevHashCode, boolean[] x, int nOfs, int nLen) Atomic type hash code generation.static intappend(int nPrevHashCode, byte x) Atomic type hash code generation.static intappend(int nPrevHashCode, byte[] x) Atomic type hash code generation.static intappend(int nPrevHashCode, byte[] x, int nOfs, int nLen) Atomic type hash code generation.static intappend(int nPrevHashCode, char x) Atomic type hash code generation.static intappend(int nPrevHashCode, char[] x) Atomic type hash code generation.static intappend(int nPrevHashCode, char[] x, int nOfs, int nLen) Atomic type hash code generation.static intappend(int nPrevHashCode, double x) Atomic type hash code generation.static intappend(int nPrevHashCode, double[] x) Atomic type hash code generation.static intappend(int nPrevHashCode, double[] x, int nOfs, int nLen) Atomic type hash code generation.static intappend(int nPrevHashCode, float x) Atomic type hash code generation.static intappend(int nPrevHashCode, float[] x) Atomic type hash code generation.static intappend(int nPrevHashCode, float[] x, int nOfs, int nLen) Atomic type hash code generation.static intappend(int nPrevHashCode, int x) Atomic type hash code generation.static intappend(int nPrevHashCode, int[] x) Atomic type hash code generation.static intappend(int nPrevHashCode, int[] x, int nOfs, int nLen) Atomic type hash code generation.static intappend(int nPrevHashCode, long x) Atomic type hash code generation.static intappend(int nPrevHashCode, long[] x) Atomic type hash code generation.static intappend(int nPrevHashCode, long[] x, int nOfs, int nLen) Atomic type hash code generation.static intappend(int nPrevHashCode, short x) Atomic type hash code generation.static intappend(int nPrevHashCode, short[] x) Atomic type hash code generation.static intappend(int nPrevHashCode, short[] x, int nOfs, int nLen) Atomic type hash code generation.static intObject hash code generation.static intArray hash code generation.static intAtomic type hash code generation.static inthashCode(boolean x) static inthashCode(boolean[] x, int nOfs, int nLen) static inthashCode(byte x) static inthashCode(byte[] x, int nOfs, int nLen) static inthashCode(char x) static inthashCode(char[] x, int nOfs, int nLen) static longhashCode(double x) static inthashCode(double[] x, int nOfs, int nLen) static inthashCode(float x) static inthashCode(float[] x, int nOfs, int nLen) static inthashCode(int[] x, int nOfs, int nLen) static inthashCode(long[] x, int nOfs, int nLen) static inthashCode(short x) static inthashCode(short[] x, int nOfs, int nLen) static intstatic int
-
Field Details
-
INITIAL_HASHCODE
public static final int INITIAL_HASHCODEUse a prime number as the start.- See Also:
-
MULTIPLIER
public static final int MULTIPLIEREach value is multiplied with this value. 31 because it can easily be optimized to(1 << 5) - 1.- See Also:
-
HASHCODE_NULL
public static final int HASHCODE_NULLThe hash code value to be used fornullvalues. Do not use 0 as e.g.BigDecimal ("0")also results in a 0 hash code.- See Also:
-
-
Method Details
-
hashCode
public static int hashCode(boolean x) -
hashCode
public static int hashCode(byte x) -
hashCode
public static int hashCode(char x) -
hashCode
public static long hashCode(double x) -
hashCode
public static int hashCode(float x) -
hashCode
public static int hashCode(short x) -
hashCode
-
append
public static int append(int nPrevHashCode, boolean x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, byte x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, char x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, double x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, float x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, int x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, long x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, short x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
Object hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Object to add. May benull.- Returns:
- The updated hash code
-
hashCode
public static int hashCode(@Nonnull boolean[] x, @Nonnegative int nOfs, @Nonnegative int nLen) -
hashCode
public static int hashCode(@Nonnull byte[] x, @Nonnegative int nOfs, @Nonnegative int nLen) -
hashCode
public static int hashCode(@Nonnull char[] x, @Nonnegative int nOfs, @Nonnegative int nLen) -
hashCode
public static int hashCode(@Nonnull double[] x, @Nonnegative int nOfs, @Nonnegative int nLen) -
hashCode
public static int hashCode(@Nonnull float[] x, @Nonnegative int nOfs, @Nonnegative int nLen) -
hashCode
public static int hashCode(@Nonnull int[] x, @Nonnegative int nOfs, @Nonnegative int nLen) -
hashCode
public static int hashCode(@Nonnull long[] x, @Nonnegative int nOfs, @Nonnegative int nLen) -
hashCode
public static int hashCode(@Nonnull short[] x, @Nonnegative int nOfs, @Nonnegative int nLen) -
hashCode
-
append
public static int append(int nPrevHashCode, @Nullable boolean[] x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, @Nullable boolean[] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, @Nullable byte[] x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, @Nullable byte[] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, @Nullable char[] x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, @Nullable char[] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, @Nullable double[] x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, @Nullable double[] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, @Nullable float[] x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, @Nullable float[] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, @Nullable int[] x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, @Nullable int[] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, @Nullable long[] x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, @Nullable long[] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, @Nullable short[] x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, @Nullable short[] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-
append
Array hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Object array to add. May benull.- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, @Nullable Object[] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-