CharSequenceHashBuilder { GeneratedHashRules perfectIntegerHashBuilder(int[] values) { byte bitIndex = 0; int accumMask = 0; boolean needsMoreSplitting; shiftStackDepth = 0; do { Arrays.fill(largestGroup, 0); needsMoreSplitting = recursiveBalanceScan(shiftsStack, shiftStackDepth, accumMask, values, 0, largestGroup, lengthCountSpace); bitIndex = (byte)findIdxOfSmallestGroup(largestGroup, Integer.MAX_VALUE, accumMask); if (bitIndex>=0) { accumMask |= (1<<bitIndex); shiftsStack[shiftStackDepth++] = bitIndex; if (1==largestGroup[bitIndex]) { needsMoreSplitting = false; break; } } else { break; } } while (true); return new GeneratedHashRules(needsMoreSplitting, accumMask, shiftsStack, shiftStackDepth, null, 0); } CharSequenceHashBuilder();   }
@Test public void integerPerfectHashTest() { int maxValues = 2000; int j = maxValues; while (--j >= 0) { int[] testValues = new int[j]; int i = j; while (--i >= 0) { testValues[i] = (i*1111)+12345; } CharSequenceHashBuilder obj = new CharSequenceHashBuilder(); GeneratedHashRules result = obj.perfectIntegerHashBuilder(testValues); int spaceSize = (1<<Integer.bitCount(result.lengthMask())); assertTrue("space size "+spaceSize+" vs "+j, spaceSize >= j); assertTrue( spaceSize <= (1+(j*4))); assertFalse(result.needsMoreSplitting()); } }