public abstract class AbstractPriorityQueue<T,O extends PriorityObject<T>> extends Object implements Cloneable
Modifier and Type | Field and Description |
---|---|
protected boolean |
asc
Indicates the sorting order.
|
protected int |
lastIndex |
protected int |
maxSize |
protected O[] |
queue
The list of objects.
|
Constructor and Description |
---|
AbstractPriorityQueue()
Standard constructor of the PriorityQueue class.
|
AbstractPriorityQueue(boolean ascending)
Creates a PriorityQueue with the given sorting order.
|
AbstractPriorityQueue(boolean ascending,
int initialSize)
Creates a PriorityQueue with the given sorting order.
|
AbstractPriorityQueue(int initialSize)
Standard constructor of the PriorityQueue class.
|
Modifier and Type | Method and Description |
---|---|
void |
add(double priority,
T obj)
Adds an object to the queue at the appropriate position.
|
void |
add(O p) |
PriorityObject<T> |
addIfBetter(double priority,
T obj,
int maxSize)
Adds an object and ensures that maxSize of the queue is not exceeded.
|
List<T> |
asList()
Return sorted list of all objects
|
void |
clear()
Resets this priority queue such that it can be re-filled from scratch:
isEmpty() will thus be true after calling this
method. |
abstract AbstractPriorityQueue<T,O> |
clone()
Performs a copy of
this , using references to the elements in
queue . |
protected void |
ensureCapacity(int minCapacity)
copied from ArrayList to automatically increase the array size
|
double |
firstPriority()
Returns the priority of the first object in the queue.
|
T |
getFirst()
returns the first value of the queue.
|
O |
getFirstEntry() |
int |
getMaxSize() |
protected abstract O |
getPriorityObject(double priority,
T object)
Generates a priority object with priority
priority for the
object object . |
protected abstract O[] |
initializeQueue(int initialSize)
Creates the array needed for this priority queue.
|
boolean |
isAscending()
Indicates if the sorting order is ascending or descending.
|
boolean |
isEmpty() |
T |
removeFirst()
Removes the first object from the queue and returns that object to the
caller.
|
O |
removeFirstEntry()
returns AND removes the first value of the queue.
|
void |
setMaxSize(int maxSize) |
protected void |
sift_down_rev()
Lowers a key from the top
|
protected void |
sift_down()
Lowers a key from the top
|
protected void |
sift_up_rev()
Lowers a key from the top
|
protected void |
sift_up()
Lowers a key from the top
|
int |
size()
Returns the size of the priority queue.
|
protected double |
val(int x) |
protected O extends PriorityObject<T>[] queue
protected final boolean asc
protected int lastIndex
protected int maxSize
public AbstractPriorityQueue()
public AbstractPriorityQueue(int initialSize)
public AbstractPriorityQueue(boolean ascending)
ascending
- If this parameter is set 'true' the sorting order is
ascending, otherwise descending.public AbstractPriorityQueue(boolean ascending, int initialSize)
ascending
- If this parameter is set 'true' the sorting order is
ascending, otherwise descending.protected abstract O[] initializeQueue(int initialSize)
initialSize
- protected abstract O getPriorityObject(double priority, T object)
priority
for the
object object
.priority
- object
- PriorityObject
type with
priority priority
for object
public abstract AbstractPriorityQueue<T,O> clone()
this
, using references to the elements in
queue
.public void add(double priority, T obj)
priority
- The priority of the object.obj
- The object that is added.public void add(O p)
public PriorityObject<T> addIfBetter(double priority, T obj, int maxSize)
priority
- The priority/weight of the object.obj
- The object that is added.maxSize
- maximum size of the queuenull
.protected void ensureCapacity(int minCapacity)
protected double val(int x)
protected void sift_up()
protected void sift_down()
protected void sift_up_rev()
protected void sift_down_rev()
public int size()
public double firstPriority()
public boolean isEmpty()
public final boolean isAscending()
public O getFirstEntry()
public T getFirst()
public O removeFirstEntry()
public T removeFirst()
public List<T> asList()
isAscending()
is true
, else sorted in descending
orderpublic int getMaxSize()
public void setMaxSize(int maxSize)
public void clear()
isEmpty()
will thus be true
after calling this
method. Note, however that the internal object array maintained by this
queue will be kept unchanged, therefore this queue still references all
objects contained within (if any). If you wish to clear the complete
queue, you will have to destroy it.Copyright © 2015. All Rights Reserved.