package jhash; public class Hash { public static int getHash(String s, int lenght) { int usedLenght = lenght + 1; double tmp = 0; for (int i = 0; i < s.length(); ++i) { char c = s.charAt(i); int j = (int) c; tmp += j; } tmp = Math.abs(Integer.reverse((int)tmp)); while (tmp < Math.pow(10, usedLenght - 1) || tmp > Math.pow(10, usedLenght)) { if (tmp >= Math.pow(10, usedLenght)) { int zbytek = (int)(tmp % 2); tmp = ((tmp / 2) + zbytek) - (zbytek / 2); } if (tmp < Math.pow(10, usedLenght - 1)) { tmp = tmp * 2; } } return (int) (tmp / 10.0); } }