@Test public void testBranchyUnsignedBinarySearch() { char[] data1 = fromShorts(new short[]{-19, -17, -15, -13, -11, -9, -7, -5, -3}); assertEquals(8, Util.branchyUnsignedBinarySearch(data1, 0, data1.length, data1[8])); assertEquals(0, Util.branchyUnsignedBinarySearch(data1, 0, data1.length, data1[0])); assertEquals(data1.length-1, Util.branchyUnsignedBinarySearch(data1, data1.length-1, data1.length, data1[data1.length-1])); assertEquals(-1, Util.branchyUnsignedBinarySearch(data1, 0, 0, (char)0)); assertEquals(-10, Util.branchyUnsignedBinarySearch(data1, 0, data1.length, (char) -1)); }
protected static int branchyUnsignedBinarySearch(final char[] array, final int begin, final int end, final char k) { if ((end > 0) && ((array[end - 1]) < (int) (k))) { return -end - 1; } int low = begin; int high = end - 1; while (low <= high) { final int middleIndex = (low + high) >>> 1; final int middleValue = (array[middleIndex]); if (middleValue < (int) (k)) { low = middleIndex + 1; } else if (middleValue > (int) (k)) { high = middleIndex - 1; } else { return middleIndex; } } return -(low + 1); }
Util { protected static int branchyUnsignedBinarySearch(final char[] array, final int begin, final int end, final char k) { if ((end > 0) && ((array[end - 1]) < (int) (k))) { return -end - 1; } int low = begin; int high = end - 1; while (low <= high) { final int middleIndex = (low + high) >>> 1; final int middleValue = (array[middleIndex]); if (middleValue < (int) (k)) { low = middleIndex + 1; } else if (middleValue > (int) (k)) { high = middleIndex - 1; } else { return middleIndex; } } return -(low + 1); } }
Util { protected static int branchyUnsignedBinarySearch(final char[] array, final int begin, final int end, final char k) { if ((end > 0) && ((array[end - 1]) < (int) (k))) { return -end - 1; } int low = begin; int high = end - 1; while (low <= high) { final int middleIndex = (low + high) >>> 1; final int middleValue = (array[middleIndex]); if (middleValue < (int) (k)) { low = middleIndex + 1; } else if (middleValue > (int) (k)) { high = middleIndex - 1; } else { return middleIndex; } } return -(low + 1); } private  Util(); }
Util { protected static int branchyUnsignedBinarySearch(final char[] array, final int begin, final int end, final char k) { if ((end > 0) && ((array[end - 1]) < (int) (k))) { return -end - 1; } int low = begin; int high = end - 1; while (low <= high) { final int middleIndex = (low + high) >>> 1; final int middleValue = (array[middleIndex]); if (middleValue < (int) (k)) { low = middleIndex + 1; } else if (middleValue > (int) (k)) { high = middleIndex - 1; } else { return middleIndex; } } return -(low + 1); } private  Util(); static Container[] addOffset(Container source, char offsets); static int advanceUntil(char[] array, int pos, int length, char min); static int iterateUntil(char[] array, int pos, int length, int min); static void fillArrayAND(final char[] container, final long[] bitmap1,
      final long[] bitmap2); static void fillArrayANDNOT(final char[] container, final long[] bitmap1,
      final long[] bitmap2); static void fillArrayXOR(final char[] container, final long[] bitmap1,
      final long[] bitmap2); static void flipBitmapRange(long[] bitmap, int start, int end); @Deprecated static int cardinalityInBitmapWordRange(long[] bitmap, int start, int end); static int cardinalityInBitmapRange(long[] bitmap, int start, int end); static int maxLowBitAsInteger(); static void resetBitmapRange(long[] bitmap, int start, int end); static int intersectArrayIntoBitmap(long[] bitmap, char[] array, int length); static int select(long w, int j); static void setBitmapRange(long[] bitmap, int start, int end); @Deprecated static int setBitmapRangeAndCardinalityChange(long[] bitmap, int start, int end); @Deprecated static int flipBitmapRangeAndCardinalityChange(long[] bitmap, int start, int end); @Deprecated static int resetBitmapRangeAndCardinalityChange(long[] bitmap, int start, int end); static int unsignedBinarySearch(final char[] array, final int begin, final int end,
      final char k); static int unsignedDifference(final char[] set1, final int length1, final char[] set2,
      final int length2, final char[] buffer); static int unsignedDifference(CharIterator set1, CharIterator set2,
                                       final char[] buffer); static int unsignedExclusiveUnion2by2(final char[] set1, final int length1,
      final char[] set2, final int length2, final char[] buffer); static int unsignedIntersect2by2(final char[] set1, final int length1, final char[] set2,
      final int length2, final char[] buffer); static boolean unsignedIntersects(char[] set1, int length1, char[] set2, int length2); static int unsignedLocalIntersect2by2Cardinality(final char[] set1, final int length1,
      final char[] set2, final int length2); static int unsignedUnion2by2(
          final char[] set1, final int offset1, final int length1,
          final char[] set2, final int offset2, final int length2,
          final char[] buffer); static long toUnsignedLong(int x); static void partialRadixSort(int[] data); }
Util { protected static int branchyUnsignedBinarySearch(final char[] array, final int begin, final int end, final char k) { if ((end > 0) && ((array[end - 1]) < (int) (k))) { return -end - 1; } int low = begin; int high = end - 1; while (low <= high) { final int middleIndex = (low + high) >>> 1; final int middleValue = (array[middleIndex]); if (middleValue < (int) (k)) { low = middleIndex + 1; } else if (middleValue > (int) (k)) { high = middleIndex - 1; } else { return middleIndex; } } return -(low + 1); } private  Util(); static Container[] addOffset(Container source, char offsets); static int advanceUntil(char[] array, int pos, int length, char min); static int iterateUntil(char[] array, int pos, int length, int min); static void fillArrayAND(final char[] container, final long[] bitmap1,
      final long[] bitmap2); static void fillArrayANDNOT(final char[] container, final long[] bitmap1,
      final long[] bitmap2); static void fillArrayXOR(final char[] container, final long[] bitmap1,
      final long[] bitmap2); static void flipBitmapRange(long[] bitmap, int start, int end); @Deprecated static int cardinalityInBitmapWordRange(long[] bitmap, int start, int end); static int cardinalityInBitmapRange(long[] bitmap, int start, int end); static int maxLowBitAsInteger(); static void resetBitmapRange(long[] bitmap, int start, int end); static int intersectArrayIntoBitmap(long[] bitmap, char[] array, int length); static int select(long w, int j); static void setBitmapRange(long[] bitmap, int start, int end); @Deprecated static int setBitmapRangeAndCardinalityChange(long[] bitmap, int start, int end); @Deprecated static int flipBitmapRangeAndCardinalityChange(long[] bitmap, int start, int end); @Deprecated static int resetBitmapRangeAndCardinalityChange(long[] bitmap, int start, int end); static int unsignedBinarySearch(final char[] array, final int begin, final int end,
      final char k); static int unsignedDifference(final char[] set1, final int length1, final char[] set2,
      final int length2, final char[] buffer); static int unsignedDifference(CharIterator set1, CharIterator set2,
                                       final char[] buffer); static int unsignedExclusiveUnion2by2(final char[] set1, final int length1,
      final char[] set2, final int length2, final char[] buffer); static int unsignedIntersect2by2(final char[] set1, final int length1, final char[] set2,
      final int length2, final char[] buffer); static boolean unsignedIntersects(char[] set1, int length1, char[] set2, int length2); static int unsignedLocalIntersect2by2Cardinality(final char[] set1, final int length1,
      final char[] set2, final int length2); static int unsignedUnion2by2(
          final char[] set1, final int offset1, final int length1,
          final char[] set2, final int offset2, final int length2,
          final char[] buffer); static long toUnsignedLong(int x); static void partialRadixSort(int[] data); static final boolean USE_HYBRID_BINSEARCH; }