@Override
 public int getSegment(Object key) {
   // The result must always be positive, so we make sure the dividend is positive first
   return (hashFunction.hash(key) & Integer.MAX_VALUE) / segmentSize;
 }
Esempio n. 2
0
 /**
  * Applies the given hash function to the hash code of a given object, and then normalizes it to
  * ensure a positive value is always returned.
  *
  * @param object to hash
  * @param hashFct hash function to apply
  * @return a non-null, non-negative normalized hash code for a given object
  */
 public static int getNormalizedHash(Object object, Hash hashFct) {
   // make sure no negative numbers are involved.
   return hashFct.hash(object) & Integer.MAX_VALUE;
 }