Module hash4j

Interface ConsistentBucketHasher


public interface ConsistentBucketHasher
A hash function that maps a given hash consistently to a bucket index of given range.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    getBucket(long hash, int numBuckets)
    Returns a bucket index in the range [0, numBuckets) based on a 64-bit hash value of the key.
  • Method Details

    • getBucket

      int getBucket(long hash, int numBuckets)
      Returns a bucket index in the range [0, numBuckets) based on a 64-bit hash value of the key.

      The returned bucket index is uniformly distributed. If numBuckets is changed, remapping to other bucket indices is minimized.

      This function is not thread-safe!

      Parameters:
      hash - a 64-bit hash value of the key
      numBuckets - the number of buckets, must be positive
      Returns:
      the bucket index