protected void makeHashFunc()

in datafu-pig/src/main/java/datafu/pig/hash/Hasher.java [177:201]


  protected void makeHashFunc(String algorithm, String seed) throws IllegalArgumentException, RuntimeException
  {
    try {
      if (algorithm.equals("murmur3-32")) {
        if (seed.length() != 8) { throw new IllegalArgumentException("Seed for "+algorithm+" must be an 8-character string representing a 32-bit unsigned number in hexadecimal."); }
        int seedint = Hasher.intFromHex(seed);
        hash_func = Hashing.murmur3_32(seedint);
      }
      else if (algorithm.equals("murmur3-128")) {
        if (seed.length() != 8) { throw new IllegalArgumentException("Seed for "+algorithm+" must be an 8-character string representing a 32-bit unsigned number in hexadecimal."); }
        int seedint = Hasher.intFromHex(seed);
        hash_func = Hashing.murmur3_128(seedint);
      }
      else if (algorithm.equals("sip24")){
        if (seed.length() != 32){ throw new IllegalArgumentException("Seed for "+algorithm+" must be a 32-character string representing a 128-bit unsigned number in hexadecimal."); }
        long k0 = Hasher.longFromHex(seed.substring( 0,16));
        long k1 = Hasher.longFromHex(seed.substring(16,32));
        hash_func = Hashing.sipHash24(k0, k1);
      }
      else { throw new IllegalArgumentException("No hash function found for algorithm "+algorithm+" with a seed. Allowed values include "+SEEDED_HASH_NAMES); }
    }
    catch (NumberFormatException err) {
      throw new RuntimeException(err);
    }
  }