Class UnsignedBytes

java.lang.Object
com.marksayson.deletionchecker.UnsignedBytes

public final class UnsignedBytes extends Object
Lexicographic comparison of byte sequences with each byte treated as unsigned (0..255).

This is the order the dataset is sorted in and searched by. It matches UTF-8 byte order, which in turn matches Unicode code-point order. Java's signed byte comparison and String.compareTo(java.lang.String) (UTF-16 code-unit order) both disagree with it for code points above U+FFFF, so all format code compares through here rather than by either of those.

  • Method Details

    • lexicographicalCompare

      public static int lexicographicalCompare(byte[] a, byte[] b)
      Compares two byte arrays.
      Parameters:
      a - the first array
      b - the second array
      Returns:
      a negative, zero, or positive value as a is lexicographically less than, equal to, or greater than b
    • lexicographicalCompare

      public static int lexicographicalCompare(byte[] a, int aFrom, int aTo, byte[] b, int bFrom, int bTo)
      Compares a range of one byte array against a range of another.
      Parameters:
      a - the first array
      aFrom - the first index of a to compare, inclusive
      aTo - the index after the last index of a to compare, exclusive
      b - the second array
      bFrom - the first index of b to compare, inclusive
      bTo - the index after the last index of b to compare, exclusive
      Returns:
      a negative, zero, or positive value as the a range is lexicographically less than, equal to, or greater than the b range
    • lexicographicalCompare

      public static int lexicographicalCompare(byte[] a, int aFrom, int aTo, ByteBuffer b, int bFrom, int bTo)
      Compares a range of a byte array against a range of a ByteBuffer, reading the buffer by absolute index without disturbing its position or limit.
      Parameters:
      a - the array
      aFrom - the first index of a to compare, inclusive
      aTo - the index after the last index of a to compare, exclusive
      b - the buffer
      bFrom - the first absolute index of b to compare, inclusive
      bTo - the absolute index after the last index of b to compare, exclusive
      Returns:
      a negative, zero, or positive value as the a range is lexicographically less than, equal to, or greater than the b range