compare static method

int compare(
  1. ByteArray a,
  2. ByteArray b
)

Static utility methods Compares two byte arrays lexicographically.

a the first array b the second array Returns negative, zero, or positive value

Implementation

/// Compares two byte arrays lexicographically.
///
/// [a] the first array
/// [b] the second array
/// Returns negative, zero, or positive value
static int compare(ByteArray a, ByteArray b) {
  int minLength = a.length < b.length ? a.length : b.length;

  for (int i = 0; i < minLength; i++) {
    int diff = a.get(i) - b.get(i);
    if (diff != 0) return diff;
  }

  return a.length - b.length;
}