Package smile.util
Class PriorityQueue
java.lang.Object
smile.util.PriorityQueue
Priority Queue for index items.
-
Constructor Summary
ConstructorDescriptionPriorityQueue
(double[] a) Constructor.PriorityQueue
(int d, double[] a) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
change
(int k) The priority of item k has changed.void
insert
(int v) Insert a new item into queue.boolean
isEmpty()
Returns true if the queue is empty.void
lower
(int k) The value of item k is lower (higher priority) now.int
poll()
Removes and returns the index of item with minimum value (highest priority).
-
Constructor Details
-
PriorityQueue
public PriorityQueue(double[] a) Constructor. Default use a 3-heap.- Parameters:
a
- external array of priority. Lower value means higher priority.
-
PriorityQueue
public PriorityQueue(int d, double[] a) Constructor.- Parameters:
d
- d-heap.a
- external array of priority. Lower value means higher priority.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Returns true if the queue is empty.- Returns:
- true if the queue is empty.
-
insert
public void insert(int v) Insert a new item into queue.- Parameters:
v
- the index of item.
-
poll
public int poll()Removes and returns the index of item with minimum value (highest priority).- Returns:
- the index of item with minimum value.
-
lower
public void lower(int k) The value of item k is lower (higher priority) now.- Parameters:
k
- the item index.
-
change
public void change(int k) The priority of item k has changed.- Parameters:
k
- the item index.
-