List of usage examples for com.google.common.primitives UnsignedInts compare
@CheckReturnValue public static int compare(int a, int b)
From source file:suneido.database.immudb.BtreeKey.java
@Override public int compareTo(BtreeKey other) { int cmp = key.compareTo(other.key); return (cmp != 0) ? cmp : UnsignedInts.compare(dataAdr, other.dataAdr); }
From source file:org.projectfloodlight.openflow.types.U32.java
@Override public int compareTo(U32 o) { return UnsignedInts.compare(raw, o.raw); }
From source file:com.yandex.yoctodb.util.UnsignedByteArrays.java
private static int compare(@NotNull final Buffer left, long leftFrom, final long leftLength, @NotNull final Buffer right, long rightFrom, final long rightLength) { assert leftLength > 0; assert rightLength > 0; // Adapted from Guava UnsignedBytes long length = Math.min(leftLength, rightLength); for (; length >= Longs.BYTES; leftFrom += Longs.BYTES, rightFrom += Longs.BYTES, length -= Longs.BYTES) { final long lw = left.getLong(leftFrom); final long rw = right.getLong(rightFrom); if (lw != rw) { return UnsignedLongs.compare(lw, rw); }/*from www. j a va 2s . c o m*/ } if (length >= Ints.BYTES) { final int lw = left.getInt(leftFrom); final int rw = right.getInt(rightFrom); if (lw != rw) { return UnsignedInts.compare(lw, rw); } leftFrom += Ints.BYTES; rightFrom += Ints.BYTES; length -= Ints.BYTES; } for (; length > 0; leftFrom++, rightFrom++, length--) { final int result = UnsignedBytes.compare(left.get(leftFrom), right.get(rightFrom)); if (result != 0) { return result; } } return (leftLength < rightLength) ? -1 : ((leftLength == rightLength) ? 0 : 1); }
From source file:hu.akarnokd.utils.lang.ArrayUtils.java
/** * Finds the first index where the value is located or * the index where it could be inserted, similar to the regular * binarySearch() methods, but it works with duplicate elements and * uses unsigned comparison.//from ww w. ja va2 s. c o m * @param array the array to search * @param fromIndex the starting index, inclusive * @param toIndex the end index, exclusive * @param value the value to search * @return if positive, the exact index where the value is first * encountered, or -(insertion point - 1) if not in the array. */ public static int findFirstUnsigned(@NonNull int[] array, int fromIndex, int toIndex, int value) { int a = fromIndex; int b = toIndex; while (a <= b) { int mid = a + (b - a) / 2; int midVal = array[mid]; int c = UnsignedInts.compare(midVal, value); if (c < 0) { a = mid + 1; } else if (c > 0) { b = mid - 1; } else { if (mid > 0) { if (array[mid - 1] != value) { return mid; } else { b = mid - 1; } } else { return 0; } } } return -(a + 1); }
From source file:hu.akarnokd.utils.lang.ArrayUtils.java
/** * Finds the last index where the value is located or * the index where it could be inserted, similar to the regular * binarySearch() methods, but it works with duplicate elements and * uses unsigned comparison.//from www .j av a 2 s .c o m * @param array the array to search * @param fromIndex the starting index, inclusive * @param toIndex the end index, exclusive * @param value the value to search * @return if positive, the exact index where the value is first * encountered, or -(insertion point - 1) if not in the array. */ public static int findLastUnsigned(@NonNull int[] array, int fromIndex, int toIndex, int value) { int a = fromIndex; int b = toIndex; while (a <= b) { int mid = a + (b - a) / 2; int midVal = array[mid]; int c = UnsignedInts.compare(midVal, value); if (c < 0) { a = mid + 1; } else if (c > 0) { b = mid - 1; } else { if (mid < toIndex - 1) { if (array[mid + 1] != value) { return mid; } else { a = mid + 1; } } else { return 0; } } } return -(a + 1); }