| Package | com.developmentarc.framework.datastructures.utils |
| Class | public class PriorityQueue |
Items that are added to the queue are sorted from highest priority to lowest and when the next() method is called the highest priority item in the queue is returned. Items with the same priority are returned in the order they where added to the queue (First in First out).
| Property | Defined by | ||
|---|---|---|---|
| hasItems : Boolean [read-only]
Used to determine if items are currently stored inside the
PriorityQueue.
| PriorityQueue | ||
| items : Array [read-only]
Returns a cloned copy of the items table in the queue.
| PriorityQueue | ||
| length : int [read-only]
The number of items currently in the PriorityQueue.
| PriorityQueue | ||
| Method | Defined by | ||
|---|---|---|---|
| PriorityQueue | |||
|
addItem(item:*, priority:uint = 5):void
Adds an item to a queue based on the priority value.
| PriorityQueue | ||
|
next():*
Used to access the next item in the queue base
on the priority.
| PriorityQueue | ||
|
peek():*
Peek returns the first item in the queue without removing
the item from the queue.
| PriorityQueue | ||
|
removeAllItems():void
Clears all items from the queue.
| PriorityQueue | ||
|
removeAt(position:uint):Boolean
Removes an item at the specified position.
| PriorityQueue | ||
|
removeItem(item:*, numberOfInstances:int, priority:int = -1):Boolean
Removes an item from the queue.
| PriorityQueue | ||
| hasItems | property |
hasItems:Boolean [read-only]Used to determine if items are currently stored inside the PriorityQueue.
Implementation public function get hasItems():Boolean
| items | property |
items:Array [read-only]Returns a cloned copy of the items table in the queue.
Implementation public function get items():Array
| length | property |
length:int [read-only]The number of items currently in the PriorityQueue.
Implementation public function get length():int
| PriorityQueue | () | constructor |
public function PriorityQueue()
| addItem | () | method |
public function addItem(item:*, priority:uint = 5):voidAdds an item to a queue based on the priority value. The queue always starts at the zero postion when next() is called so the prioirty value determines where the item should reside in the queue. The lowest priority is 0, which overrides all other priorities. By default the priority is set to 5.
Example: An item of priority 3 is added to the queue. The addItem() method first checks to see if there are any items of a higher or the same priority of the item. If there are items of higher or same priority the new item is put behind the existing items.
Parametersitem:* — The item to add to the queue.
|
|
priority:uint (default = 5) — The prioirty to assign the item.
|
| next | () | method |
public function next():*Used to access the next item in the queue base on the priority. If no items are in the queue then null is returned. It is recommened that you check hasItems before calling next to prevent returning a null value.
Returns* — The next item in the queue based in the highest priority.
|
| peek | () | method |
public function peek():*Peek returns the first item in the queue without removing the item from the queue. This enables you to peek at the item without adjust the order in the queue.
Returns* — First item in the queue, null if no items in the queue.
|
| removeAllItems | () | method |
public function removeAllItems():voidClears all items from the queue.
| removeAt | () | method |
public function removeAt(position:uint):BooleanRemoves an item at the specified position. If the position is invalid then a false value is returned stating that the item was not removed at the provided position. If the position is valid the method returns a true for success.
Parametersposition:uint — The position in the PriorityQueue to remove.
|
Boolean — True for successful removal, false for an invalid position.
|
| removeItem | () | method |
public function removeItem(item:*, numberOfInstances:int, priority:int = -1):BooleanRemoves an item from the queue. Items can have multiple instances stored inside a queue so if if you only wish to remove a specific number of instances from the queue but leave the rest you can provide a value in the numberOfInstances argument. By default all instance of the requested item are removed.
Parametersitem:* — The item to remove from the queue.
|
|
numberOfInstances:int — The number of instances to look for.
|
|
priority:int (default = -1) |
Boolean — Boolean True if one or more instances were found, otherwise False
|