MutableObjectIterator<String> inputIterator = new StringReaderMutableObjectIterator(reader); sorter = new UnilateralSortMerger<String>(mm, ioMan, inputIterator, new DummyInvokable(), new RuntimeSerializerFactory<String>(serializer, String.class), comparator, 1.0, 4, 0.8f, true /* use large record handler */, false); MutableObjectIterator<String> sortedData = sorter.getIterator(); sorter.close();
/** * Sort the given range of items using quick sort. {@inheritDoc} If the recursion depth falls below * {@link #getMaxDepth}, then switch to {@link HeapSort}. */ public void sort(final IndexedSortable s, int p, int r) { int recordsPerSegment = s.recordsPerSegment(); int recordSize = s.recordSize(); int maxOffset = recordSize * (recordsPerSegment - 1); int pN = p / recordsPerSegment; int pO = (p % recordsPerSegment) * recordSize; int rN = r / recordsPerSegment; int rO = (r % recordsPerSegment) * recordSize; sortInternal(s, recordsPerSegment, recordSize, maxOffset, p, pN, pO, r, rN, rO, getMaxDepth(r - p)); }
/** * Forces an immediate shutdown of the thread. Looses any state and all buffers that the thread is currently * working on. This terminates cleanly for the JVM, but looses intermediate results. */ public void shutdown() { this.alive = false; this.interrupt(); }
private void upHeap() { int i = size; T node = heap[i]; // save bottom node int j = i >>> 1; while (j > 0 && lessThan(node, heap[j])) { heap[i] = heap[j]; // shift parents down i = j; j = j >>> 1; } heap[i] = node; // install saved node }
@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 void writeToOutput(ChannelWriterOutputView output, LargeRecordHandler<T> largeRecordsOutput) throws IOException { writeToOutput(output); }
/** * Adds a buffer to a PriorityQueue in log(size) time. If one tries to * add more objects than maxSize from initialize a RuntimeException * (ArrayIndexOutOfBound) is thrown. */ public final void put(T element) { size++; heap[size] = element; upHeap(); }
@Override public int compare(DataFileInfo<T> file1, DataFileInfo<T> file2) { if (file1.getFileLength() == file2.getFileLength()) { return 0; } else { return file1.getFileLength() >= file2.getFileLength() ? 1 : -1; } } }
MutableObjectIterator<StringValue> inputIterator = new StringValueReaderMutableObjectIterator(reader); sorter = new UnilateralSortMerger<StringValue>(mm, ioMan, inputIterator, new DummyInvokable(), new RuntimeSerializerFactory<StringValue>(serializer, StringValue.class), comparator, 1.0, 4, 0.8f, true /* use large record handler */, true); MutableObjectIterator<StringValue> sortedData = sorter.getIterator(); sorter.close();
/** * Sort the given range of items using quick sort. {@inheritDoc} If the recursion depth falls below * {@link #getMaxDepth}, then switch to {@link HeapSort}. */ public void sort(final IndexedSortable s, int p, int r) { int recordsPerSegment = s.recordsPerSegment(); int recordSize = s.recordSize(); int maxOffset = recordSize * (recordsPerSegment - 1); int pN = p / recordsPerSegment; int pO = (p % recordsPerSegment) * recordSize; int rN = r / recordsPerSegment; int rO = (r % recordsPerSegment) * recordSize; sortInternal(s, recordsPerSegment, recordSize, maxOffset, p, pN, pO, r, rN, rO, getMaxDepth(r - p)); }
/** * Forces an immediate shutdown of the thread. Looses any state and all buffers that the thread is currently * working on. This terminates cleanly for the JVM, but looses intermediate results. */ public void shutdown() { this.alive = false; this.interrupt(); }
private void upHeap() { int i = size; T node = heap[i]; // save bottom node int j = i >>> 1; while (j > 0 && lessThan(node, heap[j])) { heap[i] = heap[j]; // shift parents down i = j; j = j >>> 1; } heap[i] = node; // install saved node }
MutableObjectIterator<Tuple2<String, String[]>> inputIterator = new StringTupleReaderMutableObjectIterator(reader); sorter = new UnilateralSortMerger<Tuple2<String, String[]>>(mm, ioMan, inputIterator, new DummyInvokable(), new RuntimeSerializerFactory<Tuple2<String, String[]>>(serializer, (Class<Tuple2<String, String[]>>) (Class<?>) Tuple2.class), comparator, 1.0, 4, 0.8f, true /* use large record handler */, false); MutableObjectIterator<Tuple2<String, String[]>> sortedData = sorter.getIterator(); reader.close(); sorter.close();
MutableObjectIterator<Tuple2<StringValue, StringValue[]>> inputIterator = new StringValueTupleReaderMutableObjectIterator(reader); sorter = new UnilateralSortMerger<Tuple2<StringValue, StringValue[]>>(mm, ioMan, inputIterator, new DummyInvokable(), new RuntimeSerializerFactory<Tuple2<StringValue, StringValue[]>>(serializer, (Class<Tuple2<StringValue, StringValue[]>>) (Class<?>) Tuple2.class), comparator, 1.0, 4, 0.8f, true /* use large record handler */, false); MutableObjectIterator<Tuple2<StringValue, StringValue[]>> sortedData = sorter.getIterator(); reader.close(); sorter.close();