public interface ElementHashProvider
An element hash provider.
-
Method Summary
Modifier and TypeMethodDescriptionlonggetElementHash(int elementIndex) Returns a 64-bit hash value of the element with given index.intReturns the number of elements.static <T> ElementHashProviderofCollection(Collection<T> collection, ToLongFunction<? super T> elementHashFunction) Creates anElementHashProvidergiven a collection of elements and a function that maps an element to a 64-bit hash value.static ElementHashProviderofFunction(IntToLongFunction elementIndexToHash, int numberOfElements) Creates anElementHashProvidergiven a function that maps an element index to its corresponding hash value for a given number of elements.static ElementHashProviderofValues(long... elementHashes) Creates anElementHashProvidergiven a non-empty list of element hashes.
-
Method Details
-
getElementHash
long getElementHash(int elementIndex) Returns a 64-bit hash value of the element with given index.The function must be defined for all nonnegative indices less than
getNumberOfElements(). Multiple calls with the same element index must always return the same hash value. The hash values must have a high quality, meaning that they can be considered as uniformly distributed and mutually independent in practice.- Parameters:
elementIndex- the element index- Returns:
- the hash value
-
getNumberOfElements
int getNumberOfElements()Returns the number of elements.The number of elements must be positive.
- Returns:
- the number of elements
-
ofValues
Creates anElementHashProvidergiven a non-empty list of element hashes.- Parameters:
elementHashes- list of element hashes- Returns:
- an element hash provider
- Throws:
IllegalArgumentException- if the list of element hashes is empty
-
ofFunction
Creates anElementHashProvidergiven a function that maps an element index to its corresponding hash value for a given number of elements.The function must always return the same hash value for the same element index and must be defined for all nonnegative indices smaller than the given number of elements.
- Parameters:
elementIndexToHash- function that maps an element index to its corresponding hash valuenumberOfElements- the number of elements- Returns:
- an element hash provider
- Throws:
IllegalArgumentException- if the provided function is null or the number of elements is not positive.
-
ofCollection
static <T> ElementHashProvider ofCollection(Collection<T> collection, ToLongFunction<? super T> elementHashFunction) Creates anElementHashProvidergiven a collection of elements and a function that maps an element to a 64-bit hash value.- Type Parameters:
T- the element type- Parameters:
collection- a collection of elementselementHashFunction- a function that maps an element to a 64-bit hash value- Returns:
- an element hash provider
- Throws:
IllegalArgumentException- if any argument is null or the collection is empty
-