FixedLengthRecordSorter implements InMemorySorter<T> { @Override public int compare(int i, int j) { final int bufferNumI = i / this.recordsPerSegment; final int segmentOffsetI = (i % this.recordsPerSegment) * this.recordSize; final int bufferNumJ = j / this.recordsPerSegment; final int segmentOffsetJ = (j % this.recordsPerSegment) * this.recordSize; final MemorySegment segI = this.sortBuffer.get(bufferNumI); final MemorySegment segJ = this.sortBuffer.get(bufferNumJ); int val = segI.compare(segJ, segmentOffsetI, segmentOffsetJ, this.numKeyBytes); return this.useNormKeyUninverted ? val : -val; } FixedLengthRecordSorter(TypeSerializer<T> serializer, TypeComparator<T> comparator, 
			List<MemorySegment> memory); @Override void reset(); @Override boolean isEmpty(); @Override void dispose(); @Override long getCapacity(); @Override long getOccupancy(); @Override T getRecord(int logicalPosition); @Override T getRecord(T reuse, int logicalPosition); @Override boolean write(T record); @Override int compare(int i, int j); @Override void swap(int i, int j); @Override int size(); @Override final MutableObjectIterator<T> getIterator(); @Override void writeToOutput(final ChannelWriterOutputView output); @Override void writeToOutput(ChannelWriterOutputView output, LargeRecordHandler<T> largeRecordsOutput); @Override void writeToOutput(final ChannelWriterOutputView output, final int start, int num);  }
@Test public void testCompare() throws Exception { final int numSegments = MEMORY_SIZE / MEMORY_PAGE_SIZE; final List<MemorySegment> memory = this.memoryManager.allocatePages(new DummyInvokable(), numSegments); FixedLengthRecordSorter<IntPair> sorter = newSortBuffer(memory); UniformIntPairGenerator generator = new UniformIntPairGenerator(Integer.MAX_VALUE, 1, true); IntPair record = new IntPair(); int num = -1; do { generator.next(record); num++; } while (sorter.write(record) && num < 3354624); Random rnd = new Random(SEED << 1); for (int i = 0; i < 2 * num; i++) { int pos1 = rnd.nextInt(num); int pos2 = rnd.nextInt(num); int cmp = sorter.compare(pos1, pos2); if (pos1 < pos2) { Assert.assertTrue(cmp <= 0); } else { Assert.assertTrue(cmp >= 0); } } sorter.dispose(); this.memoryManager.release(memory); }