@Test public void testHash() { System.out.println("PerfectHash"); PerfectHash hash = new PerfectHash("abc", "great", "hash"); assertEquals(0, hash.get("abc")); assertEquals(1, hash.get("great")); assertEquals(2, hash.get("hash")); assertEquals(-1, hash.get("perfect")); assertEquals(-1, hash.get("hash2")); }
private int hash(String k) { int klen = k.length(); int out = klen; if (select == null) { for (int i = 0; i < klen; i++) { int c = k.charAt(i) - min; if (c < 0) return -1; if (c >= kvals.length) return -2; out += kvals[c]; } } else { for (int i : select) { if (i >= klen) continue; int c = k.charAt(i) - min; if (c < 0) return -1; if (c >= kvals.length) return -2; out += kvals[c]; } } return out; }
PerfectHash implements Serializable { private int hash(String k) { int klen = k.length(); int out = klen; if (select == null) { for (int i = 0; i < klen; i++) { int c = k.charAt(i) - min; if (c < 0) return -1; if (c >= kvals.length) return -2; out += kvals[c]; } } else { for (int i : select) { if (i >= klen) continue; int c = k.charAt(i) - min; if (c < 0) return -1; if (c >= kvals.length) return -2; out += kvals[c]; } } return out; } }
PerfectHash implements Serializable { private int hash(String k) { int klen = k.length(); int out = klen; if (select == null) { for (int i = 0; i < klen; i++) { int c = k.charAt(i) - min; if (c < 0) return -1; if (c >= kvals.length) return -2; out += kvals[c]; } } else { for (int i : select) { if (i >= klen) continue; int c = k.charAt(i) - min; if (c < 0) return -1; if (c >= kvals.length) return -2; out += kvals[c]; } } return out; } PerfectHash(String... keywords);  PerfectHash(int[] select, String... keywords); }
PerfectHash implements Serializable { private int hash(String k) { int klen = k.length(); int out = klen; if (select == null) { for (int i = 0; i < klen; i++) { int c = k.charAt(i) - min; if (c < 0) return -1; if (c >= kvals.length) return -2; out += kvals[c]; } } else { for (int i : select) { if (i >= klen) continue; int c = k.charAt(i) - min; if (c < 0) return -1; if (c >= kvals.length) return -2; out += kvals[c]; } } return out; } PerfectHash(String... keywords);  PerfectHash(int[] select, String... keywords); int get(String key); }
PerfectHash implements Serializable { private int hash(String k) { int klen = k.length(); int out = klen; if (select == null) { for (int i = 0; i < klen; i++) { int c = k.charAt(i) - min; if (c < 0) return -1; if (c >= kvals.length) return -2; out += kvals[c]; } } else { for (int i : select) { if (i >= klen) continue; int c = k.charAt(i) - min; if (c < 0) return -1; if (c >= kvals.length) return -2; out += kvals[c]; } } return out; } PerfectHash(String... keywords);  PerfectHash(int[] select, String... keywords); int get(String key);  }