/** * Identical to lookup3, except initval is biased by -(length<<2). * This is equivalent to leaving out the length factor in the initial state. * {@code lookup3ycs(k, offset, length, initval) == lookup3(k,offset,length,initval-(length<<2))} * and * {@code lookup3ycs(k, offset, length, initval+(length<<2)) == lookup3(k,offset,length,initval)} */ public static int lookup3ycs(int[] k, int offset, int length, int initval) { return lookup3(k, offset, length, initval - (length << 2)); }
/** * test that the hash of the UTF-16 encoded Java String is equal to the hash of the unicode code points * * @param utf32 * @param len */ void tstEquiv(int[] utf32, int len) { int seed = 100; StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i++) { sb.appendCodePoint(utf32[i]); } int hash = Lookup3Hash.lookup3(utf32, 0, len, seed - (len << 2)); int hash2 = Lookup3Hash.lookup3ycs(utf32, 0, len, seed); assertEquals(hash, hash2); int hash3 = Lookup3Hash.lookup3ycs(sb, 0, sb.length(), seed); assertEquals(hash, hash3); long hash4 = Lookup3Hash.lookup3ycs64(sb, 0, sb.length(), seed); assertEquals((int) hash4, hash); }
@Test public void testEqualsLOOKUP3() { int[] hashes = new int[]{0xc4c20dd5, 0x3ab04cc3, 0xebe874a3, 0x0e770ef3, 0xec321498, 0x73845e86, 0x8a2db728, 0x03c313bb, 0xfe5b9199, 0x95965125, 0xcbc4e7c2}; /*** the hash values were generated by adding the following to lookup3.c * * char* s = "hello world"; * int len = strlen(s); * uint32_t a[len]; * for (int i=0; i<len; i++) { * a[i]=s[i]; * uint32_t result = hashword(a, i+1, i*12345); * printf("0x%.8x\n", result); * } * */ String s = "hello world"; int[] a = new int[s.length()]; for (int i = 0; i < s.length(); i++) { a[i] = s.charAt(i); int len = i + 1; int hash = Lookup3Hash.lookup3(a, 0, len, i * 12345); assertEquals(hashes[i], hash); int hash2 = Lookup3Hash.lookup3ycs(a, 0, len, i * 12345 + (len << 2)); assertEquals(hashes[i], hash2); int hash3 = Lookup3Hash.lookup3ycs(s, 0, len, i * 12345 + (len << 2)); assertEquals(hashes[i], hash3); } }
/** * Identical to lookup3, except initval is biased by -(length<<2). * This is equivalent to leaving out the length factor in the initial state. * {@code lookup3ycs(k, offset, length, initval) == lookup3(k,offset,length,initval-(length<<2))} * and * {@code lookup3ycs(k, offset, length, initval+(length<<2)) == lookup3(k,offset,length,initval)} */ public static int lookup3ycs(int[] k, int offset, int length, int initval) { return lookup3(k, offset, length, initval - (length << 2)); }