NormalizedKeySorter implements InMemorySorter<T> { @Override public void reset() { this.numRecords = 0; this.currentSortIndexOffset = 0; this.currentDataBufferOffset = 0; this.sortIndexBytes = 0; this.freeMemory.addAll(this.sortIndex); this.freeMemory.addAll(this.recordBufferSegments); this.sortIndex.clear(); this.recordBufferSegments.clear(); this.currentSortIndexSegment = nextMemorySegment(); this.sortIndex.add(this.currentSortIndexSegment); this.recordCollector.reset(); } NormalizedKeySorter(TypeSerializer<T> serializer, TypeComparator<T> comparator, List<MemorySegment> memory);  NormalizedKeySorter(TypeSerializer<T> serializer, TypeComparator<T> comparator, 
			List<MemorySegment> memory, int maxNormalizedKeyBytes); @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(ChannelWriterOutputView output); @Override void writeToOutput(ChannelWriterOutputView output, LargeRecordHandler<T> largeRecordsOutput); @Override void writeToOutput(final ChannelWriterOutputView output, final int start, int num);  }
@Test public void testReset() throws Exception { final int numSegments = MEMORY_SIZE / MEMORY_PAGE_SIZE; final List<MemorySegment> memory = this.memoryManager.allocatePages(new DummyInvokable(), numSegments); NormalizedKeySorter<Tuple2<Integer, String>> sorter = newSortBuffer(memory); TestData.TupleGenerator generator = new TestData.TupleGenerator(SEED, KEY_MAX, VALUE_LENGTH, KeyMode.RANDOM, ValueMode.FIX_LENGTH); Tuple2<Integer, String> record = new Tuple2<>(); int num = -1; do { generator.next(record); num++; } while (sorter.write(record)); sorter.reset(); generator = new TestData.TupleGenerator(SEED2, KEY_MAX, VALUE_LENGTH, KeyMode.RANDOM, ValueMode.FIX_LENGTH); int num2 = -1; do { generator.next(record); num2++; } while (sorter.write(record)); Assert.assertEquals("The number of records written after the reset was not the same as before.", num, num2); generator.reset(); Tuple2<Integer, String> readTarget = new Tuple2<>(); int i = 0; while (i < num) { generator.next(record); readTarget = sorter.getRecord(readTarget, i++); int rk = readTarget.f0; int gk = record.f0; String rv = readTarget.f1; String gv = record.f1; Assert.assertEquals("The re-read key is wrong", gk, rk); Assert.assertEquals("The re-read value is wrong", gv, rv); } sorter.dispose(); this.memoryManager.release(memory); }