Package Utils

Class TopQueue


  • public class TopQueue
    extends java.lang.Object
    Queue that keeps only the entries with the top values
    • Constructor Summary

      Constructors 
      Constructor Description
      TopQueue​(int top)
      Constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(int e, double v)
      Attempts to add a new entry
      int[] getList()
      Returns the entries in the queue as an array
      int[] getList​(int n)
      Returns the entries in the queue as an array.
      double[] getValueList()
      Returns the entries in the values as an array
      double[] getValueList​(int n)
      Returns the values in the queue as an array.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TopQueue

        public TopQueue​(int top)
        Constructor
        Parameters:
        top - The number of top entries to store
    • Method Detail

      • add

        public boolean add​(int e,
                           double v)
        Attempts to add a new entry
        Parameters:
        e - The entry
        v - The entry's value
        Returns:
        Whether the entry was added. Returns false if the entry was smaller than the smallest element already in the queue and the queue is full.
      • getList

        public int[] getList()
        Returns the entries in the queue as an array
        Returns:
        Ordered list of entries
      • getList

        public int[] getList​(int n)
        Returns the entries in the queue as an array. Only the top n entries are returned, or all the entries in the list if n is greater than the size of the queue
        Parameters:
        n - The number of entries to return
        Returns:
        Ordered list of entries
      • getValueList

        public double[] getValueList()
        Returns the entries in the values as an array
        Returns:
        Ordered list of entries
      • getValueList

        public double[] getValueList​(int n)
        Returns the values in the queue as an array. Only the top n entries are returned, or all the entries in the list if n is greater than the size of the queue
        Parameters:
        n - The number of entries to return
        Returns:
        Ordered list of entries