Package mindustry.ai
Class PathfindQueue
java.lang.Object
mindustry.ai.PathfindQueue
A priority queue.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(int e, float weight) Inserts the specified element into this priority queue.void
clear()
Removes all of the elements from this priority queue.boolean
empty()
int
peek()
Retrieves, but does not remove, the head of this queue.int
poll()
Retrieves and removes the head of this queue, or returnsnull
if this queue is empty.
-
Field Details
-
queue
public int[] queuePriority queue represented as a balanced binary heap: the two children of queue[n] are queue[2*n+1] and queue[2*(n+1)]. The priority queue is ordered by the elements' natural ordering: For each node n in the heap and each descendant d of n, n <= d. The element with the lowest value is in queue[0], assuming the queue is nonempty. -
weights
public float[] weightsWeights of each object in the queue. -
size
public int sizeThe number of elements in the priority queue.
-
-
Constructor Details
-
PathfindQueue
public PathfindQueue() -
PathfindQueue
public PathfindQueue(int initialCapacity)
-
-
Method Details
-
empty
public boolean empty() -
add
public boolean add(int e, float weight) Inserts the specified element into this priority queue. Ifuniqueness
is enabled and this priority queue already contains the element, the call leaves the queue unchanged and returns false.- Returns:
- true if the element was added to this queue, else false
- Throws:
ClassCastException
- if the specified element cannot be compared with elements currently in this priority queue according to the priority queue's orderingIllegalArgumentException
- if the specified element is null
-
peek
public int peek()Retrieves, but does not remove, the head of this queue. If this queue is empty,0
is returned.- Returns:
- the head of this queue
-
clear
public void clear()Removes all of the elements from this priority queue. The queue will be empty after this call returns. -
poll
public int poll()Retrieves and removes the head of this queue, or returnsnull
if this queue is empty.- Returns:
- the head of this queue, or
null
if this queue is empty.
-