Package Utils
Class TopQueue
- java.lang.Object
-
- Utils.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 entryint[]
getList()
Returns the entries in the queue as an arrayint[]
getList(int n)
Returns the entries in the queue as an array.double[]
getValueList()
Returns the entries in the values as an arraydouble[]
getValueList(int n)
Returns the values in the queue as an array.
-
-
-
Method Detail
-
add
public boolean add(int e, double v)
Attempts to add a new entry- Parameters:
e
- The entryv
- 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
-
-