Packagecom.developmentarc.framework.datastructures.utils
Classpublic class PriorityQueue

The PriorityQueue is a data structure utility designed to store items in a stored order based upon a defined priority value. When an item is added to the queue the item is assigned a priority value, 0 being the "highest" priority and unit.MAX_VALUE as the "lowest" priority.

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).



Public Properties
 PropertyDefined 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
Public Methods
 MethodDefined 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
  
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
Property detail
hasItemsproperty
hasItems:Boolean  [read-only]

Used to determine if items are currently stored inside the PriorityQueue.

Implementation
    public function get hasItems():Boolean
itemsproperty 
items:Array  [read-only]

Returns a cloned copy of the items table in the queue.

Implementation
    public function get items():Array
lengthproperty 
length:int  [read-only]

The number of items currently in the PriorityQueue.

Implementation
    public function get length():int
Constructor detail
PriorityQueue()constructor
public function PriorityQueue()
Method detail
addItem()method
public function addItem(item:*, priority:uint = 5):void

Adds 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.

Parameters
item:* — 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():void

Clears all items from the queue.

removeAt()method 
public function removeAt(position:uint):Boolean

Removes 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.

Parameters
position:uint — The position in the PriorityQueue to remove.

Returns
Boolean — True for successful removal, false for an invalid position.
removeItem()method 
public function removeItem(item:*, numberOfInstances:int, priority:int = -1):Boolean

Removes 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.

Parameters
item:* — The item to remove from the queue.
 
numberOfInstances:int — The number of instances to look for.
 
priority:int (default = -1)

Returns
Boolean — Boolean True if one or more instances were found, otherwise False