ArrayedQueue

ArrayedQueue

A queue based on an array (circular queue).  This is called a FIFO structure (First In, First Out).

See Also

LinkedQueue

Summary
ArrayedQueueA queue based on an array (circular queue).
Functions and Properties
ArrayedQueueInitializes a queue object to match the given size.
maxSizeThe queue’s maximum capacity.
peekIndicates the front item.
backIndicates the most recently added item.
enqueueEnqueues some data.
dequeueDequeues and returns the front item.
disposeDeletes the last dequeued item to free it for the garbage collector.
getAtReads an item relative to the front index.
setAtWrites an item relative to the front index.
contains@inheritDoc
clear@inheritDoc
getIterator@inheritDoc
size@inheritDoc
isEmpty@inheritDoc
toArray@inheritDoc
toStringPrints out a string representing the current object.
dumpPrints out all elements (for debug/demo purposes).
init@private

Functions and Properties

ArrayedQueue

public function ArrayedQueue(size: int)

Initializes a queue object to match the given size.  The size must be a power of two - if not the size is automatically rounded to the next largest power of 2.  The initial value of all items is null.

Parameters

sizeThe queue’s size. 

maxSize

public function get maxSize():int

The queue’s maximum capacity.

peek

public function peek():*

Indicates the front item.

Returns

The front item or null if the queue is empty. 

back

public function back():*

Indicates the most recently added item.

Returns

The last item in the queue or null if the queue is empty. 

enqueue

public function enqueue(obj: *):Boolean

Enqueues some data.

Parameters

param obj The data to enqueue. 

Returns

True if the item fits into the queue, otherwise false. 

dequeue

public function dequeue():*

Dequeues and returns the front item.

Returns

The front item or null if the queue is empty. 

dispose

public function dispose():void

Deletes the last dequeued item to free it for the garbage collector.  <i>Use only directly after you have invoked dequeue()</i>.

@example The following code clears the dequeued item

<listing version=”3.0”> myQueue.dequeue(); myQueue.dispose(); </listing>

getAt

public function getAt(i: int):*

Reads an item relative to the front index.

Parameters

iThe index of the item. 

Returns

The item at the given index. 

setAt

public function setAt(i: int,
obj: *):void

Writes an item relative to the front index.

Parameters

iThe index of the item.
objThe data. 

contains

public function contains(obj: *):Boolean

@inheritDoc

clear

public function clear():void

@inheritDoc

getIterator

public function getIterator():Iterator

@inheritDoc

size

public function get size():int

@inheritDoc

isEmpty

public function isEmpty():Boolean

@inheritDoc

toArray

public function toArray():Array

@inheritDoc

toString

public function toString():String

Prints out a string representing the current object.

Returns

A string representing the current object. 

dump

public function dump():String

Prints out all elements (for debug/demo purposes).

Returns

A human-readable representation of the structure. 

init

private function init(size: int):void

@private

A ‘java-style’ collection interface.
public function ArrayedQueue(size: int)
Initializes a queue object to match the given size.
public function get maxSize():int
The queue’s maximum capacity.
public function peek():*
Indicates the front item.
public function back():*
Indicates the most recently added item.
public function enqueue(obj: *):Boolean
Enqueues some data.
public function dequeue():*
Dequeues and returns the front item.
public function dispose():void
Deletes the last dequeued item to free it for the garbage collector.
public function getAt(i: int):*
Reads an item relative to the front index.
public function setAt(i: int,
obj: *):void
Writes an item relative to the front index.
public function contains(obj: *):Boolean
@inheritDoc
public function clear():void
@inheritDoc
public function getIterator():Iterator
@inheritDoc
public function get size():int
@inheritDoc
public function isEmpty():Boolean
@inheritDoc
public function toArray():Array
@inheritDoc
public function toString():String
Prints out a string representing the current object.
public function dump():String
Prints out all elements (for debug/demo purposes).
private function init(size: int):void
@private
A queue based on a linked list.
Close