Github user Hexiaoqiao commented on a diff in the pull request: https://github.com/apache/incubator-carbondata/pull/627#discussion_r104613452 --- Diff: core/src/main/java/org/apache/carbondata/core/util/ByteUtil.java --- @@ -152,6 +152,159 @@ static boolean lessThanUnsigned(long x1, long x2) { return (x1 + Long.MIN_VALUE) < (x2 + Long.MIN_VALUE); } + +/* public static int binarySearch(byte[] a, int fromIndex, int toIndex, byte[] key) { + int keyLength = key.length; + rangeCheck(a.length, fromIndex, toIndex, keyLength); + return binarySearch0(a, fromIndex, toIndex / keyLength, key); + } + + // Like public version, but without range checks. + private static int binarySearch0(byte[] a, int fromIndex, int toIndex, byte[] key) { + int low = fromIndex; + int high = toIndex - 1; + int keyLength = key.length; + // int high = toIndex/keyLength; + + while (low <= high) { + int mid = (low + high) >>> 1; + // byte midVal = a[mid]; + + int result = ByteUtil.UnsafeComparer.INSTANCE.compareTo(a, mid * keyLength, keyLength, key, 0, + keyLength); + + if (result < 0) + low = mid + keyLength; + else if (result > 0) + high = mid - keyLength; + else + return mid; // key found + } + return -(low + 1); // key not found. + }*/ + /** + * Checks that {@code fromIndex} and {@code toIndex} are in the range and toIndex % keyLength = 0 + * and throws an exception if they aren't. + */ + private static void rangeCheck(int arrayLength, int fromIndex, int toIndex, int keyWordLength) { + if (fromIndex > toIndex || toIndex % keyWordLength != 0) { + throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")"); --- End diff -- the exception msg may be misleading, please give some msg about `toIndex % keyWordLength != 0`.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---