HashGenerator.java
package BloomFilter;
public class HashGenerator {
private int size;
private int seed;
private HashGroup group;
enum HashGroup {
G1, G2, G3, G4
}
public HashGenerator(int size, int seed, HashGroup group) {
this.size = size;
this.seed = seed;
this.group = group;
}
public int doHash(String value) {
switch (group) {
case G1 -> {return hashG1(value);}
case G2 -> {return hashG2(value);}
case G3 -> {return hashG3(value);}
case G4 -> {return hashG4(value);}
default -> throw new RuntimeException("Err HashGroup is NULL!");
}
}
private int hashG1(String value) {
var hash = 0;
for (var idx = 0; idx < value.length(); idx++) {
var c = value.charAt(idx);
hash = (hash << 5) + hash + c;
hash &= hash;