Package org.agrona.collections
Class Hashing
java.lang.Object
org.agrona.collections.Hashing
Hashing functions for applying to integers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final float
Default load factor to be used in open-addressing hashed data structures. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic long
compoundKey
(int keyPartA, int keyPartB) Combined two 32-bit keys into a 64-bit compound.static int
evenHash
(int value, int mask) Generate an even hash for an int value and apply mask to get a remainder that will be even.static int
evenHash
(long value, int mask) Generate an even hash for a long value and apply mask to get a remainder that will be even.static int
hash
(int value) Generate a hash for an int value.static int
hash
(int value, int mask) Generate a hash for an int value and apply mask to get remainder.static int
hash
(long value) Generate a hash for a long value.static int
hash
(long value, int mask) Generate a hash for a long value and apply mask to get a remainder.static int
Generate a hash for an object and apply mask to get a remainder.
-
Field Details
-
DEFAULT_LOAD_FACTOR
public static final float DEFAULT_LOAD_FACTORDefault load factor to be used in open-addressing hashed data structures.- See Also:
-
-
Constructor Details
-
Hashing
private Hashing()
-
-
Method Details
-
hash
public static int hash(int value) Generate a hash for an int value.- Parameters:
value
- to be hashed.- Returns:
- the hashed value.
-
hash
public static int hash(long value) Generate a hash for a long value.- Parameters:
value
- to be hashed.- Returns:
- the hashed value.
-
hash
public static int hash(int value, int mask) Generate a hash for an int value and apply mask to get remainder.- Parameters:
value
- to be hashed.mask
- mask to be applied that must be a power of 2 - 1.- Returns:
- the hash of the value.
-
hash
Generate a hash for an object and apply mask to get a remainder.- Parameters:
value
- to be hashed.mask
- mask to be applied that must be a power of 2 - 1.- Returns:
- the hash of the value.
-
hash
public static int hash(long value, int mask) Generate a hash for a long value and apply mask to get a remainder.- Parameters:
value
- to be hashed.mask
- mask to be applied that must be a power of 2 - 1.- Returns:
- the hash of the value.
-
evenHash
public static int evenHash(int value, int mask) Generate an even hash for an int value and apply mask to get a remainder that will be even.- Parameters:
value
- to be hashed.mask
- mask to be applied that must be a power of 2 - 1.- Returns:
- the hash of the value which is always even.
-
evenHash
public static int evenHash(long value, int mask) Generate an even hash for a long value and apply mask to get a remainder that will be even.- Parameters:
value
- to be hashed.mask
- mask to be applied that must be a power of 2 - 1.- Returns:
- the hash of the value which is always even.
-
compoundKey
public static long compoundKey(int keyPartA, int keyPartB) Combined two 32-bit keys into a 64-bit compound.- Parameters:
keyPartA
- to make the upper bitskeyPartB
- to make the lower bits.- Returns:
- the compound key
-