src/jdk.jfr/share/classes/jdk/jfr/internal/util/UniversalHashFamily.java
branchJEP-349-branch
changeset 57375 3efa9b992c4d
parent 57374 41f0051285e0
child 57376 8e8a06a3059c
equal deleted inserted replaced
57374:41f0051285e0 57375:3efa9b992c4d
     1 package jdk.jfr.internal.util;
       
     2 
       
     3 import java.util.Random;
       
     4 
       
     5 public class UniversalHashFamily {
       
     6     final Random rand = new Random();
       
     7 
       
     8     private static long getA(long hashFunction) {
       
     9         return hashFunction | 1;
       
    10     }
       
    11 
       
    12     private static long getB(long hashFunction, long mask) {
       
    13         return hashFunction & mask;
       
    14     }
       
    15 
       
    16     private static long getHash(long key, long hashFunction, long mask) {
       
    17         return (getA(hashFunction) * key) + (hashFunction & mask);
       
    18     }
       
    19 
       
    20     public static int getIndex(long key, long hashFunction, long shift, long mask) {
       
    21         return (int)(getHash(key, hashFunction, mask) >>> shift);
       
    22     }
       
    23 
       
    24     public long getRandomHashFunction() {
       
    25         return rand.nextLong() & Long.MAX_VALUE;
       
    26     }
       
    27 }