public int compareCustom(ByteBuffer b1, ByteBuffer b2) { // Compare for length int s1 = b1.position(), s2 = b2.position(); int l1 = b1.limit(), l2 = b2.limit(); // should we assert exactly 16 bytes (or 0)? seems prudent boolean p1 = l1 - s1 == 16, p2 = l2 - s2 == 16; if (!(p1 & p2)) { assert p1 | (l1 == s1); assert p2 | (l2 == s2); return p1 ? 1 : p2 ? -1 : 0; } long msb1 = b1.getLong(s1); long msb2 = b2.getLong(s2); msb1 = reorderTimestampBytes(msb1); msb2 = reorderTimestampBytes(msb2); assert (msb1 & topbyte(0xf0L)) == topbyte(0x10L); assert (msb2 & topbyte(0xf0L)) == topbyte(0x10L); int c = Long.compare(msb1, msb2); if (c != 0) return c; // this has to be a signed per-byte comparison for compatibility // so we transform the bytes so that a simple long comparison is equivalent long lsb1 = signedBytesToNativeLong(b1.getLong(s1 + 8)); long lsb2 = signedBytesToNativeLong(b2.getLong(s2 + 8)); return Long.compare(lsb1, lsb2); }
public int compareCustom(ByteBuffer b1, ByteBuffer b2) { // Compare for length int s1 = b1.position(), s2 = b2.position(); int l1 = b1.limit(), l2 = b2.limit(); // should we assert exactly 16 bytes (or 0)? seems prudent boolean p1 = l1 - s1 == 16, p2 = l2 - s2 == 16; if (!(p1 & p2)) { assert p1 | (l1 == s1); assert p2 | (l2 == s2); return p1 ? 1 : p2 ? -1 : 0; } long msb1 = b1.getLong(s1); long msb2 = b2.getLong(s2); msb1 = reorderTimestampBytes(msb1); msb2 = reorderTimestampBytes(msb2); assert (msb1 & topbyte(0xf0L)) == topbyte(0x10L); assert (msb2 & topbyte(0xf0L)) == topbyte(0x10L); int c = Long.compare(msb1, msb2); if (c != 0) return c; // this has to be a signed per-byte comparison for compatibility // so we transform the bytes so that a simple long comparison is equivalent long lsb1 = signedBytesToNativeLong(b1.getLong(s1 + 8)); long lsb2 = signedBytesToNativeLong(b2.getLong(s2 + 8)); return Long.compare(lsb1, lsb2); }
public int compareCustom(ByteBuffer b1, ByteBuffer b2) { // Compare for length int s1 = b1.position(), s2 = b2.position(); int l1 = b1.limit(), l2 = b2.limit(); // should we assert exactly 16 bytes (or 0)? seems prudent boolean p1 = l1 - s1 == 16, p2 = l2 - s2 == 16; if (!(p1 & p2)) { assert p1 | (l1 == s1); assert p2 | (l2 == s2); return p1 ? 1 : p2 ? -1 : 0; } long msb1 = b1.getLong(s1); long msb2 = b2.getLong(s2); msb1 = reorderTimestampBytes(msb1); msb2 = reorderTimestampBytes(msb2); assert (msb1 & topbyte(0xf0L)) == topbyte(0x10L); assert (msb2 & topbyte(0xf0L)) == topbyte(0x10L); int c = Long.compare(msb1, msb2); if (c != 0) return c; // this has to be a signed per-byte comparison for compatibility // so we transform the bytes so that a simple long comparison is equivalent long lsb1 = signedBytesToNativeLong(b1.getLong(s1 + 8)); long lsb2 = signedBytesToNativeLong(b2.getLong(s2 + 8)); return Long.compare(lsb1, lsb2); }
public int compareCustom(ByteBuffer b1, ByteBuffer b2) { // Compare for length int s1 = b1.position(), s2 = b2.position(); int l1 = b1.limit(), l2 = b2.limit(); // should we assert exactly 16 bytes (or 0)? seems prudent boolean p1 = l1 - s1 == 16, p2 = l2 - s2 == 16; if (!(p1 & p2)) { assert p1 | (l1 == s1); assert p2 | (l2 == s2); return p1 ? 1 : p2 ? -1 : 0; } long msb1 = b1.getLong(s1); long msb2 = b2.getLong(s2); msb1 = reorderTimestampBytes(msb1); msb2 = reorderTimestampBytes(msb2); assert (msb1 & topbyte(0xf0L)) == topbyte(0x10L); assert (msb2 & topbyte(0xf0L)) == topbyte(0x10L); int c = Long.compare(msb1, msb2); if (c != 0) return c; // this has to be a signed per-byte comparison for compatibility // so we transform the bytes so that a simple long comparison is equivalent long lsb1 = signedBytesToNativeLong(b1.getLong(s1 + 8)); long lsb2 = signedBytesToNativeLong(b2.getLong(s2 + 8)); return Long.compare(lsb1, lsb2); }