Class FixedLengthRecordSorter<T>

    • Method Detail

      • recordSize

        public int recordSize()
        Description copied from interface: IndexedSortable
        Gets the size of each record, the number of bytes separating the head of successive records.
        Specified by:
        recordSize in interface IndexedSortable
        Returns:
        The record size
      • recordsPerSegment

        public int recordsPerSegment()
        Description copied from interface: IndexedSortable
        Gets the number of elements in each memory segment.
        Specified by:
        recordsPerSegment in interface IndexedSortable
        Returns:
        The number of records per segment
      • reset

        public void reset()
        Resets the sort buffer back to the state where it is empty. All contained data is discarded.
        Specified by:
        reset in interface InMemorySorter<T>
      • isEmpty

        public boolean isEmpty()
        Checks whether the buffer is empty.
        Specified by:
        isEmpty in interface InMemorySorter<T>
        Returns:
        True, if no record is contained, false otherwise.
      • dispose

        public void dispose()
        Description copied from interface: InMemorySorter
        Disposes the sorter. This method does not release the memory segments used by the sorter.
        Specified by:
        dispose in interface Disposable
        Specified by:
        dispose in interface InMemorySorter<T>
      • getCapacity

        public long getCapacity()
        Description copied from interface: InMemorySorter
        Gets the total capacity of this sorter, in bytes.
        Specified by:
        getCapacity in interface InMemorySorter<T>
        Returns:
        The sorter's total capacity.
      • getOccupancy

        public long getOccupancy()
        Description copied from interface: InMemorySorter
        Gets the number of bytes currently occupied in this sorter, records and sort index.
        Specified by:
        getOccupancy in interface InMemorySorter<T>
        Returns:
        The number of bytes occupied.
      • getRecord

        public T getRecord​(int logicalPosition)
                    throws IOException
        Description copied from interface: InMemorySorter
        Gets the record at the given logical position.
        Specified by:
        getRecord in interface InMemorySorter<T>
        Parameters:
        logicalPosition - The logical position of the record.
        Throws:
        IOException - Thrown, if an exception occurred during deserialization.
      • getRecord

        public T getRecord​(T reuse,
                           int logicalPosition)
                    throws IOException
        Description copied from interface: InMemorySorter
        Gets the record at the given logical position.
        Specified by:
        getRecord in interface InMemorySorter<T>
        Parameters:
        reuse - The reuse object to deserialize the record into.
        logicalPosition - The logical position of the record.
        Throws:
        IOException - Thrown, if an exception occurred during deserialization.
      • write

        public boolean write​(T record)
                      throws IOException
        Writes a given record to this sort buffer. The written record will be appended and take the last logical position.
        Specified by:
        write in interface InMemorySorter<T>
        Parameters:
        record - The record to be written.
        Returns:
        True, if the record was successfully written, false, if the sort buffer was full.
        Throws:
        IOException - Thrown, if an error occurred while serializing the record into the buffers.
      • compare

        public int compare​(int segmentNumberI,
                           int segmentOffsetI,
                           int segmentNumberJ,
                           int segmentOffsetJ)
        Description copied from interface: IndexedSortable
        Compare records at the given addresses consistent with the semantics of Comparator.compare(Object, Object).
        Specified by:
        compare in interface IndexedSortable
        Parameters:
        segmentNumberI - index of memory segment containing first record
        segmentOffsetI - offset into memory segment containing first record
        segmentNumberJ - index of memory segment containing second record
        segmentOffsetJ - offset into memory segment containing second record
        Returns:
        a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
      • swap

        public void swap​(int i,
                         int j)
        Description copied from interface: IndexedSortable
        Swap items at the given addresses.
        Specified by:
        swap in interface IndexedSortable
      • swap

        public void swap​(int segmentNumberI,
                         int segmentOffsetI,
                         int segmentNumberJ,
                         int segmentOffsetJ)
        Description copied from interface: IndexedSortable
        Swap records at the given addresses.
        Specified by:
        swap in interface IndexedSortable
        Parameters:
        segmentNumberI - index of memory segment containing first record
        segmentOffsetI - offset into memory segment containing first record
        segmentNumberJ - index of memory segment containing second record
        segmentOffsetJ - offset into memory segment containing second record
      • size

        public int size()
        Description copied from interface: IndexedSortable
        Gets the number of elements in the sortable.
        Specified by:
        size in interface IndexedSortable
        Returns:
        The number of elements.
      • getIterator

        public final MutableObjectIterator<T> getIterator()
        Gets an iterator over all records in this buffer in their logical order.
        Specified by:
        getIterator in interface InMemorySorter<T>
        Returns:
        An iterator returning the records in their logical order.
      • writeToOutput

        public void writeToOutput​(ChannelWriterOutputView output)
                           throws IOException
        Writes the records in this buffer in their logical order to the given output.
        Specified by:
        writeToOutput in interface InMemorySorter<T>
        Parameters:
        output - The output view to write the records to.
        Throws:
        IOException - Thrown, if an I/O exception occurred writing to the output view.
      • writeToOutput

        public void writeToOutput​(ChannelWriterOutputView output,
                                  int start,
                                  int num)
                           throws IOException
        Writes a subset of the records in this buffer in their logical order to the given output.
        Specified by:
        writeToOutput in interface InMemorySorter<T>
        Parameters:
        output - The output view to write the records to.
        start - The logical start position of the subset.
        num - The number of elements to write.
        Throws:
        IOException - Thrown, if an I/O exception occurred writing to the output view.