Class TopNBuffer

  • All Implemented Interfaces:
    Serializable

    public class TopNBuffer
    extends Object
    implements Serializable
    TopNBuffer stores mapping from sort key to records list, sortKey is RowData type, each record is RowData type. TopNBuffer could also track rank number of each record.
    See Also:
    Serialized Form
    • Method Detail

      • put

        public int put​(RowData sortKey,
                       RowData value)
        Appends a record into the buffer.
        Parameters:
        sortKey - sort key with which the specified value is to be associated
        value - record which is to be appended
        Returns:
        the size of the collection under the sortKey.
      • putAll

        public void putAll​(RowData sortKey,
                           Collection<RowData> values)
        Puts a record list into the buffer under the sortKey. Note: if buffer already contains sortKey, putAll will overwrite the previous value
        Parameters:
        sortKey - sort key with which the specified values are to be associated
        values - record lists to be associated with the specified key
      • get

        public Collection<RowData> get​(RowData sortKey)
        Gets the record list from the buffer under the sortKey.
        Parameters:
        sortKey - key to get
        Returns:
        the record list from the buffer under the sortKey
      • removeAll

        public void removeAll​(RowData sortKey)
        Removes all record list from the buffer under the sortKey.
        Parameters:
        sortKey - key to remove
      • removeLast

        public RowData removeLast()
        Removes the last record of the last Entry in the buffer.
        Returns:
        removed record
      • lastElement

        public RowData lastElement()
        Returns the last record of the last Entry in the buffer.
      • getElement

        public RowData getElement​(int rank)
        Gets record which rank is given value.
        Parameters:
        rank - rank value to search
        Returns:
        the record which rank is given value
      • containsKey

        public boolean containsKey​(RowData key)
        Returns true if the buffer contains a mapping for the specified key.
        Parameters:
        key - key whose presence in the buffer is to be tested
        Returns:
        true if the buffer contains a mapping for the specified key
      • getCurrentTopNum

        public int getCurrentTopNum()
        Gets number of total records.
        Returns:
        the number of total records.
      • getSortKeyComparator

        public Comparator<RowData> getSortKeyComparator()
        Gets sort key comparator used by buffer.
        Returns:
        sort key comparator used by buffer
      • checkSortKeyInBufferRange

        public boolean checkSortKeyInBufferRange​(RowData sortKey,
                                                 long topNum)
        Checks whether the record should be put into the buffer.
        Parameters:
        sortKey - sortKey to test
        topNum - buffer to add
        Returns:
        true if the record should be put into the buffer.