@Override
    public void reset() {
        // reset all offsets
        this.numRecords = 0;
        this.currentSortBufferOffset = 0;
        this.sortBufferBytes = 0;

        // return all memory
        this.freeMemory.addAll(this.sortBuffer);
        this.sortBuffer.clear();

        // grab first buffers
        this.currentSortBufferSegment = nextMemorySegment();
        this.sortBuffer.add(this.currentSortBufferSegment);
        this.outView.set(this.currentSortBufferSegment);
    }
@Test
    void testReset() 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);
        RandomIntPairGenerator generator = new RandomIntPairGenerator(SEED);

        // write the buffer full with the first set of records
        IntPair record = new IntPair();
        int num = -1;
        do {
            generator.next(record);
            num++;
        } while (sorter.write(record) && num < 3354624);

        sorter.reset();

        // write a second sequence of records. since the values are of fixed length, we must be able
        // to write an equal number
        generator.reset();

        // write the buffer full with the first set of records
        int num2 = -1;
        do {
            generator.next(record);
            num2++;
        } while (sorter.write(record) && num2 < 3354624);

        assertThat(num2)
                .withFailMessage(
                        "The number of records written after the reset was not the same as before.")
                .isEqualTo(num);

        // re-read the records
        generator.reset();
        IntPair readTarget = new IntPair();

        int i = 0;
        while (i < num) {
            generator.next(record);
            readTarget = sorter.getRecord(readTarget, i++);

            int rk = readTarget.getKey();
            int gk = record.getKey();

            int rv = readTarget.getValue();
            int gv = record.getValue();

            assertThat(rk).withFailMessage("The re-read key is wrong %d", i).isEqualTo(gk);
            assertThat(rv).withFailMessage("The re-read value is wrong %d", i).isEqualTo(gv);
        }

        // release the memory occupied by the buffers
        sorter.dispose();
        this.memoryManager.release(memory);
    }