public static int compare(ValidWriteIdList a, ValidWriteIdList b) {
    if (!a.getTableName().equalsIgnoreCase(b.getTableName())) {
      return a.getTableName().toLowerCase().compareTo(b.getTableName().toLowerCase());
    }
    // The algorithm assumes invalidWriteIds are sorted and values are less or equal than hwm, here is how
    // the algorithm works:
    // 1. Compare two invalidWriteIds until one the list ends, difference means the mismatch writeid is
    //    committed in one ValidWriteIdList but not the other, the comparison end
    // 2. Every writeid from the last writeid in the short invalidWriteIds till its hwm should be committed
    //    in the other ValidWriteIdList, otherwise the comparison end
    // 3. Every writeid from lower hwm to higher hwm should be invalid, otherwise, the comparison end
    int minLen = Math.min(a.getInvalidWriteIds().length, b.getInvalidWriteIds().length);
    for (int i=0;i<minLen;i++) {
      if (a.getInvalidWriteIds()[i] == b.getInvalidWriteIds()[i]) {
        continue;
      }
      return a.getInvalidWriteIds()[i] > b.getInvalidWriteIds()[i]?1:-1;
    }
    if (a.getInvalidWriteIds().length == b.getInvalidWriteIds().length) {
      return Long.signum(a.getHighWatermark() - b.getHighWatermark());
    }
    if (a.getInvalidWriteIds().length == minLen) {
      if (a.getHighWatermark() != b.getInvalidWriteIds()[minLen] -1) {
        return Long.signum(a.getHighWatermark() - (b.getInvalidWriteIds()[minLen] -1));
      }
      if (allInvalidFrom(b.getInvalidWriteIds(), minLen, b.getHighWatermark())) {
        return 0;
      } else {
        return -1;
      }
    } else {
      if (b.getHighWatermark() != a.getInvalidWriteIds()[minLen] -1) {
        return Long.signum((a.getInvalidWriteIds()[minLen] - 1) - b.getHighWatermark());
      }
      if (allInvalidFrom(a.getInvalidWriteIds(), minLen, a.getHighWatermark())) {
        return 0;
      } else {
        return 1;
      }
    }
  }
Compare the freshness of two ValidWriteIdList
@param a
@param b
@return 0, if a and b are equivalent
1, if a is more recent
-1, if b is more recent
*
storage-api/src/java/org/apache/hive/common/util/TxnIdUtils.java