@Test public void testCompare() { MemoryRowBlock rowBlock = null; try { rowBlock = new MemoryRowBlock(new DataType[]{ DataType.newBuilder().setType(Type.TEXT).build() }); RowWriter builder = rowBlock.getWriter(); builder.startRow(); builder.putText("CÔTE D'IVOIRE"); builder.endRow(); builder.startRow(); builder.putText("CANADA"); builder.endRow(); RowBlockReader reader = rowBlock.getReader(); UnSafeTuple t1 = new UnSafeTuple(); UnSafeTuple t2 = new UnSafeTuple(); reader.next(t1); reader.next(t2); int compare = UnSafeTupleBytesComparator.compare(t1.getFieldAddr(0), t2.getFieldAddr(0)); assertTrue(compare > 0); } finally { if (rowBlock != null) { rowBlock.release(); } } }
public static int compare(long ptr1, long ptr2) { int lstrLen = UNSAFE.getInt(ptr1); int rstrLen = UNSAFE.getInt(ptr2); ptr1 += SizeOf.SIZE_OF_INT; ptr2 += SizeOf.SIZE_OF_INT; int minLength = Math.min(lstrLen, rstrLen); int minWords = minLength / Longs.BYTES; for (int i = 0; i < minWords * Longs.BYTES; i += Longs.BYTES) { long lw = UNSAFE.getLong(ptr1); long rw = UNSAFE.getLong(ptr2); if (lw != rw) { if (!littleEndian) { return UnsignedLongs.compare(lw, rw); } int n = Long.numberOfTrailingZeros(lw ^ rw) & ~0x7; return (int) (((lw >>> n) & UNSIGNED_MASK) - ((rw >>> n) & UNSIGNED_MASK)); } ptr1 += SizeOf.SIZE_OF_LONG; ptr2 += SizeOf.SIZE_OF_LONG; } for (int i = minWords * Longs.BYTES; i < minLength; i++) { int result = UnsignedBytes.compare(UNSAFE.getByte(ptr1++), UNSAFE.getByte(ptr2++)); if (result != 0) { return result; } } return lstrLen - rstrLen; }
UnSafeTupleBytesComparator { public static int compare(long ptr1, long ptr2) { int lstrLen = UNSAFE.getInt(ptr1); int rstrLen = UNSAFE.getInt(ptr2); ptr1 += SizeOf.SIZE_OF_INT; ptr2 += SizeOf.SIZE_OF_INT; int minLength = Math.min(lstrLen, rstrLen); int minWords = minLength / Longs.BYTES; for (int i = 0; i < minWords * Longs.BYTES; i += Longs.BYTES) { long lw = UNSAFE.getLong(ptr1); long rw = UNSAFE.getLong(ptr2); if (lw != rw) { if (!littleEndian) { return UnsignedLongs.compare(lw, rw); } int n = Long.numberOfTrailingZeros(lw ^ rw) & ~0x7; return (int) (((lw >>> n) & UNSIGNED_MASK) - ((rw >>> n) & UNSIGNED_MASK)); } ptr1 += SizeOf.SIZE_OF_LONG; ptr2 += SizeOf.SIZE_OF_LONG; } for (int i = minWords * Longs.BYTES; i < minLength; i++) { int result = UnsignedBytes.compare(UNSAFE.getByte(ptr1++), UNSAFE.getByte(ptr2++)); if (result != 0) { return result; } } return lstrLen - rstrLen; } }
UnSafeTupleBytesComparator { public static int compare(long ptr1, long ptr2) { int lstrLen = UNSAFE.getInt(ptr1); int rstrLen = UNSAFE.getInt(ptr2); ptr1 += SizeOf.SIZE_OF_INT; ptr2 += SizeOf.SIZE_OF_INT; int minLength = Math.min(lstrLen, rstrLen); int minWords = minLength / Longs.BYTES; for (int i = 0; i < minWords * Longs.BYTES; i += Longs.BYTES) { long lw = UNSAFE.getLong(ptr1); long rw = UNSAFE.getLong(ptr2); if (lw != rw) { if (!littleEndian) { return UnsignedLongs.compare(lw, rw); } int n = Long.numberOfTrailingZeros(lw ^ rw) & ~0x7; return (int) (((lw >>> n) & UNSIGNED_MASK) - ((rw >>> n) & UNSIGNED_MASK)); } ptr1 += SizeOf.SIZE_OF_LONG; ptr2 += SizeOf.SIZE_OF_LONG; } for (int i = minWords * Longs.BYTES; i < minLength; i++) { int result = UnsignedBytes.compare(UNSAFE.getByte(ptr1++), UNSAFE.getByte(ptr2++)); if (result != 0) { return result; } } return lstrLen - rstrLen; }  }
UnSafeTupleBytesComparator { public static int compare(long ptr1, long ptr2) { int lstrLen = UNSAFE.getInt(ptr1); int rstrLen = UNSAFE.getInt(ptr2); ptr1 += SizeOf.SIZE_OF_INT; ptr2 += SizeOf.SIZE_OF_INT; int minLength = Math.min(lstrLen, rstrLen); int minWords = minLength / Longs.BYTES; for (int i = 0; i < minWords * Longs.BYTES; i += Longs.BYTES) { long lw = UNSAFE.getLong(ptr1); long rw = UNSAFE.getLong(ptr2); if (lw != rw) { if (!littleEndian) { return UnsignedLongs.compare(lw, rw); } int n = Long.numberOfTrailingZeros(lw ^ rw) & ~0x7; return (int) (((lw >>> n) & UNSIGNED_MASK) - ((rw >>> n) & UNSIGNED_MASK)); } ptr1 += SizeOf.SIZE_OF_LONG; ptr2 += SizeOf.SIZE_OF_LONG; } for (int i = minWords * Longs.BYTES; i < minLength; i++) { int result = UnsignedBytes.compare(UNSAFE.getByte(ptr1++), UNSAFE.getByte(ptr2++)); if (result != 0) { return result; } } return lstrLen - rstrLen; }  static int compare(long ptr1, long ptr2); }
UnSafeTupleBytesComparator { public static int compare(long ptr1, long ptr2) { int lstrLen = UNSAFE.getInt(ptr1); int rstrLen = UNSAFE.getInt(ptr2); ptr1 += SizeOf.SIZE_OF_INT; ptr2 += SizeOf.SIZE_OF_INT; int minLength = Math.min(lstrLen, rstrLen); int minWords = minLength / Longs.BYTES; for (int i = 0; i < minWords * Longs.BYTES; i += Longs.BYTES) { long lw = UNSAFE.getLong(ptr1); long rw = UNSAFE.getLong(ptr2); if (lw != rw) { if (!littleEndian) { return UnsignedLongs.compare(lw, rw); } int n = Long.numberOfTrailingZeros(lw ^ rw) & ~0x7; return (int) (((lw >>> n) & UNSIGNED_MASK) - ((rw >>> n) & UNSIGNED_MASK)); } ptr1 += SizeOf.SIZE_OF_LONG; ptr2 += SizeOf.SIZE_OF_LONG; } for (int i = minWords * Longs.BYTES; i < minLength; i++) { int result = UnsignedBytes.compare(UNSAFE.getByte(ptr1++), UNSAFE.getByte(ptr2++)); if (result != 0) { return result; } } return lstrLen - rstrLen; }  static int compare(long ptr1, long ptr2);  }