public class HashCommon
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
HashCommon.EnumHasher |
Modifier and Type | Field and Description |
---|---|
static HashCommon.EnumHasher |
enumHasher |
static int |
INT_PHI
232 · φ, φ = (√5 − 1)/2.
|
static int |
INV_INT_PHI
The reciprocal of
INT_PHI modulo 232. |
static long |
INV_LONG_PHI
The reciprocal of
LONG_PHI modulo 264. |
static long |
LONG_PHI
264 · φ, φ = (√5 − 1)/2.
|
Modifier and Type | Method and Description |
---|---|
static int |
mix(int n)
Thoroughly mixes the bits of an integer.
|
static long |
mix(long x)
Quickly mixes the bits of a long integer.
|
static int |
mixOther(int x)
Thoroughly mixes the bits of an integer.
|
static int |
nextPowerOfTwo(int x)
Return the least power of two greater than or equal to the specified value.
|
static long |
nextPowerOfTwo(long x)
Return the least power of two greater than or equal to the specified value.
|
public static final HashCommon.EnumHasher enumHasher
public static final int INT_PHI
public static final int INV_INT_PHI
INT_PHI
modulo 232.public static final long LONG_PHI
public static final long INV_LONG_PHI
LONG_PHI
modulo 264.public static int mixOther(int x)
mix(int)
, and does almost exactly as well at
avoiding collisions on most input, so mix() is preferred.x
- an integer.x
.public static int mix(int n)
mixOriginal(int)
(which is used by Koloboke and Fastutil), but doesn't multiply by
any too-large numbers to ease compatibility with GWT. Specifically, it multiplies n
by 0x9E375
(found using the golden ratio times 2 to the 20, minus 2 to improve quality slightly) then xors that with itself
unsigned-right-shifted by 16 before returning. It tends to have less pathologically-bad cases than using an
unmixed integer in a hash table, but will still often have more collisions than an unmixed integer if that hash
table is filled with numbers that vary in their lower bits. The value of this is that when ints are given that
only differ in their upper bits, if you didn't mix a hash code you would have 95% or higher collision rates in
some cases. This acts as a safeguard for that kind of scenario.
mixOther(int)
, which is also GWT-compatible but is a little slower without offering any
improvement in collision rates.
IntDoubleOrderedMap
and IntIntOrderedMap
, at the least. The algorithm this uses
is also used by CrossHash.defaultHasher
.n
- an integer.x
.public static long mix(long x)
x
- a long integer.x
.invMix(long)
public static int nextPowerOfTwo(int x)
x
- a non-negative int.public static long nextPowerOfTwo(long x)
x
- a non-negative long.Copyright © Eben Howard 2012–2022. All rights reserved.