@Override public int compare(int i, int j) { final int segmentNumberI = i / this.indexEntriesPerSegment; final int segmentOffsetI = (i % this.indexEntriesPerSegment) * this.indexEntrySize; final int segmentNumberJ = j / this.indexEntriesPerSegment; final int segmentOffsetJ = (j % this.indexEntriesPerSegment) * this.indexEntrySize; return compare(segmentNumberI, segmentOffsetI, segmentNumberJ, segmentOffsetJ); }
@Override public T getRecord(int logicalPosition) throws IOException { return getRecordFromBuffer(readPointer(logicalPosition)); }
@Override public void swap(int i, int j) { final int segmentNumberI = i / this.indexEntriesPerSegment; final int segmentOffsetI = (i % this.indexEntriesPerSegment) * this.indexEntrySize; final int segmentNumberJ = j / this.indexEntriesPerSegment; final int segmentOffsetJ = (j % this.indexEntriesPerSegment) * this.indexEntrySize; swap(segmentNumberI, segmentOffsetI, segmentNumberJ, segmentOffsetJ); }
@Override public InMemorySorter<T> create(List<MemorySegment> sortSegments) { final TypeSerializer<T> typeSerializer = typeSerializerFactory.getSerializer(); final TypeComparator<T> duplicateTypeComparator = typeComparator.duplicate(); if (useFixedLengthRecordSorter) { return new FixedLengthRecordSorter<>(typeSerializer, duplicateTypeComparator, sortSegments); } else { return new NormalizedKeySorter<>(typeSerializer, duplicateTypeComparator, sortSegments); } } }
if (memoryAvailable()) { this.currentSortIndexSegment = nextMemorySegment(); this.sortIndex.add(this.currentSortIndexSegment); this.currentSortIndexOffset = 0;
/** * Resets the sort buffer back to the state where it is empty. All contained data is discarded. */ @Override public void reset() { // reset all offsets this.numRecords = 0; this.currentSortIndexOffset = 0; this.currentDataBufferOffset = 0; this.sortIndexBytes = 0; // return all memory this.freeMemory.addAll(this.sortIndex); this.freeMemory.addAll(this.recordBufferSegments); this.sortIndex.clear(); this.recordBufferSegments.clear(); // grab first buffers this.currentSortIndexSegment = nextMemorySegment(); this.sortIndex.add(this.currentSortIndexSegment); this.recordCollector.reset(); }
@Override public int compare(int segmentNumberI, int segmentOffsetI, int segmentNumberJ, int segmentOffsetJ) { final MemorySegment segI = this.sortIndex.get(segmentNumberI); final MemorySegment segJ = this.sortIndex.get(segmentNumberJ); int val = segI.compare(segJ, segmentOffsetI + OFFSET_LEN, segmentOffsetJ + OFFSET_LEN, this.numKeyBytes); if (val != 0 || this.normalizedKeyFullyDetermines) { return this.useNormKeyUninverted ? val : -val; } final long pointerI = segI.getLong(segmentOffsetI) & POINTER_MASK; final long pointerJ = segJ.getLong(segmentOffsetJ) & POINTER_MASK; return compareRecords(pointerI, pointerJ); }
/** * Writes the records in this buffer in their logical order to the given output. * * @param output The output view to write the records to. * @throws IOException Thrown, if an I/O exception occurred writing to the output view. */ @Override public void writeToOutput(ChannelWriterOutputView output) throws IOException { writeToOutput(output, null); }
return new MutableObjectIterator<T>() private final int size = size(); private int current = 0;
@Override public InMemorySorter<T> create(List<MemorySegment> sortSegments) { final TypeSerializer<T> typeSerializer = typeSerializerFactory.getSerializer(); final TypeComparator<T> duplicateTypeComparator = typeComparator.duplicate(); if (useFixedLengthRecordSorter) { return new FixedLengthRecordSorter<>(typeSerializer, duplicateTypeComparator, sortSegments); } else { return new NormalizedKeySorter<>(typeSerializer, duplicateTypeComparator, sortSegments); } } }
if (memoryAvailable()) { this.currentSortIndexSegment = nextMemorySegment(); this.sortIndex.add(this.currentSortIndexSegment); this.currentSortIndexOffset = 0;
/** * Resets the sort buffer back to the state where it is empty. All contained data is discarded. */ @Override public void reset() { // reset all offsets this.numRecords = 0; this.currentSortIndexOffset = 0; this.currentDataBufferOffset = 0; this.sortIndexBytes = 0; // return all memory this.freeMemory.addAll(this.sortIndex); this.freeMemory.addAll(this.recordBufferSegments); this.sortIndex.clear(); this.recordBufferSegments.clear(); // grab first buffers this.currentSortIndexSegment = nextMemorySegment(); this.sortIndex.add(this.currentSortIndexSegment); this.recordCollector.reset(); }
@Override public int compare(int segmentNumberI, int segmentOffsetI, int segmentNumberJ, int segmentOffsetJ) { final MemorySegment segI = this.sortIndex.get(segmentNumberI); final MemorySegment segJ = this.sortIndex.get(segmentNumberJ); int val = segI.compare(segJ, segmentOffsetI + OFFSET_LEN, segmentOffsetJ + OFFSET_LEN, this.numKeyBytes); if (val != 0 || this.normalizedKeyFullyDetermines) { return this.useNormKeyUninverted ? val : -val; } final long pointerI = segI.getLong(segmentOffsetI) & POINTER_MASK; final long pointerJ = segJ.getLong(segmentOffsetJ) & POINTER_MASK; return compareRecords(pointerI, pointerJ); }
/** * Writes the records in this buffer in their logical order to the given output. * * @param output The output view to write the records to. * @throws IOException Thrown, if an I/O exception occurred writing to the output view. */ @Override public void writeToOutput(ChannelWriterOutputView output) throws IOException { writeToOutput(output, null); }
return new MutableObjectIterator<T>() private final int size = size(); private int current = 0;
@Override public T getRecord(T reuse, int logicalPosition) throws IOException { return getRecordFromBuffer(reuse, readPointer(logicalPosition)); }
buffer = new NormalizedKeySorter<E>(serializerFactory.getSerializer(), comp, sortSegments);
if (memoryAvailable()) { this.currentSortIndexSegment = nextMemorySegment(); this.sortIndex.add(this.currentSortIndexSegment); this.currentSortIndexOffset = 0;
/** * Resets the sort buffer back to the state where it is empty. All contained data is discarded. */ @Override public void reset() { // reset all offsets this.numRecords = 0; this.currentSortIndexOffset = 0; this.currentDataBufferOffset = 0; this.sortIndexBytes = 0; // return all memory this.freeMemory.addAll(this.sortIndex); this.freeMemory.addAll(this.recordBufferSegments); this.sortIndex.clear(); this.recordBufferSegments.clear(); // grab first buffers this.currentSortIndexSegment = nextMemorySegment(); this.sortIndex.add(this.currentSortIndexSegment); this.recordCollector.reset(); }
@Override public int compare(int segmentNumberI, int segmentOffsetI, int segmentNumberJ, int segmentOffsetJ) { final MemorySegment segI = this.sortIndex.get(segmentNumberI); final MemorySegment segJ = this.sortIndex.get(segmentNumberJ); int val = segI.compare(segJ, segmentOffsetI + OFFSET_LEN, segmentOffsetJ + OFFSET_LEN, this.numKeyBytes); if (val != 0 || this.normalizedKeyFullyDetermines) { return this.useNormKeyUninverted ? val : -val; } final long pointerI = segI.getLong(segmentOffsetI) & POINTER_MASK; final long pointerJ = segJ.getLong(segmentOffsetJ) & POINTER_MASK; return compareRecords(pointerI, pointerJ); }