NormalizedKeySorter implements IndexedSortable { 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); void reset(); boolean isEmpty(); List<MemorySegment> dispose(); long getCapacity(); long getOccupancy(); void getRecord(T target, int logicalPosition); boolean write(T record); int compare(int i, int j); @Override void swap(int i, int j); @Override int size(); final MutableObjectIterator<T> getIterator(); void writeToOutput(final ChannelWriterOutputView output); 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<PactRecord> sorter = newSortBuffer(memory); TestData.Generator generator = new TestData.Generator(SEED, KEY_MAX, VALUE_LENGTH, KeyMode.RANDOM, ValueMode.FIX_LENGTH); PactRecord record = new PactRecord(); int num = -1; do { generator.next(record); num++; } while (sorter.write(record)); sorter.reset(); generator = new TestData.Generator(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(); PactRecord readTarget = new PactRecord(); int i = 0; while (i < num) { generator.next(record); sorter.getRecord(readTarget, i++); Key rk = readTarget.getField(0, Key.class); Key gk = record.getField(0, Key.class); Value rv = readTarget.getField(1, Value.class); Value gv = record.getField(1, Value.class); Assert.assertEquals("The re-read key is wrong", gk, rk); Assert.assertEquals("The re-read value is wrong", gv, rv); } this.memoryManager.release(sorter.dispose()); }