static int compare()

in datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java [39:60]


  static int compare(
      final ResourceImpl state1, final long offsetBytes1, final long lengthBytes1,
      final ResourceImpl state2, final long offsetBytes2, final long lengthBytes2) {
    state1.checkValid();
    ResourceImpl.checkBounds(offsetBytes1, lengthBytes1, state1.getCapacity());
    state2.checkValid();
    ResourceImpl.checkBounds(offsetBytes2, lengthBytes2, state2.getCapacity());
    final long cumOff1 = state1.getCumulativeOffset(offsetBytes1);
    final long cumOff2 = state2.getCumulativeOffset(offsetBytes2);
    final Object arr1 = state1.getUnsafeObject();
    final Object arr2 = state2.getUnsafeObject();
    if ((arr1 != arr2) || (cumOff1 != cumOff2)) {
      final long lenBytes = Math.min(lengthBytes1, lengthBytes2);
      for (long i = 0; i < lenBytes; i++) {
        final int byte1 = unsafe.getByte(arr1, cumOff1 + i);
        final int byte2 = unsafe.getByte(arr2, cumOff2 + i);
        if (byte1 < byte2) { return -1; }
        if (byte1 > byte2) { return  1; }
      }
    }
    return Long.compare(lengthBytes1, lengthBytes2);
  }