import java.lang.Math; public class Hasher { public static long elfHash(String toHash) { long hashValue = 0; for (int Pos = 0; Pos < toHash.length(); Pos++) { // use all elements hashValue = (hashValue << 4) + toHash.charAt(Pos); // shift/mix long hiBits = hashValue & 0xF000000000000000L; // get high nybble if (hiBits != 0) { hashValue ^= hiBits >> 56; // xor high nybble with second nybble } hashValue &= ~hiBits; // clear high nybble } return ( hashValue & 0x0FFFFFFFFFFFFFFFL ); } public static long sfold(String s) { int intLength = s.length() / 4; long hashValue = 0; for (int j = 0; j < intLength; j++) { char c[] = s.substring(j * 4, (j * 4) + 4).toCharArray(); long mult = 1; for (int k = 0; k < c.length; k++) { hashValue += c[k] * mult; mult *= 256; } } char c[] = s.substring(intLength * 4).toCharArray(); long mult = 1; for (int k = 0; k < c.length; k++) { hashValue += c[k] * mult; mult *= 256; } return ( hashValue & 0x0FFFFFFFFFFFFFFFL ); } public static long DEKHash(String str) { long hashValue = str.length(); for(int i = 0; i < str.length(); i++) { hashValue = ((hashValue << 5) ^ (hashValue >> 27)) ^ str.charAt(i); } return ( hashValue & 0x0FFFFFFFFFFFFFFFL ); } /* End Of DEK Hash Function */ public static long FNVHash(String str) { long fnv_prime = 0x811C9DC5; long hashValue = 0; for(int i = 0; i < str.length(); i++) { hashValue *= fnv_prime; hashValue ^= str.charAt(i); } return ( hashValue & 0x0FFFFFFFFFFFFFFFL ); } /* End Of FNV Hash Function */ };