package jhash; public class Hash { public static double getHash(String s, int lenght) { Double tmp = new Double(0); for (int i = 0; i < s.length(); ++i) { char c = s.charAt(i); int j = (int) c; tmp += j; } while (tmp < Math.pow(10, lenght - 1) || tmp > Math.pow(10, lenght)) { if (tmp >= Math.pow(10, lenght)) { //System.out.println("vetší než " + Math.pow(10, lenght)); double zbytek = tmp % 2; tmp = ((tmp / 2) + zbytek)- (zbytek / 2); } if (tmp < Math.pow(10, lenght-1)) { //System.out.println("menší než " + Math.pow(10, lenght-1); tmp = tmp * 2; } } return tmp; } }