Packagevegas.data.queue
Classpublic class CircularQueue
InheritanceCircularQueue Inheritance CoreObject
ImplementsBoundedQueue

The CircularQueue class allows for storing objects in a circular queue of a predefined size.

Example :

     import vegas.data.iterator.Iterator ;
     import vegas.data.queue.CircularQueue ;
     
     var q:CircularQueue = new CircularQueue(5) ;
     
     trace ("maxSize : " + q.maxSize()) ;
     trace ("enqueue item1 : " + q.enqueue ("item1")) ;
     trace ("enqueue item2 : " + q.enqueue ("item2")) ;
     trace ("enqueue item3 : " + q.enqueue ("item3")) ;
     trace ("enqueue item4 : " + q.enqueue ("item4")) ;
     trace ("enqueue item5 : " + q.enqueue ("item5")) ;
     trace ("enqueue item6 : " + q.enqueue ("item6")) ;
     
     trace ("element : " + q.element()) ;
     trace ("dequeue : " + q.dequeue()) ;
     trace ("element : " + q.element()) ;
     trace ("size : " + q.size()) ;
     trace ("isFull : " + q.isFull()) ;
     trace ("array : " + q.toArray()) ;
     
     trace("") ;
     
     trace ("queue : " + q) ;
     
     trace("") ;
     
     trace ("dequeue : " + q.dequeue()) ;
     trace ("enqueue item6 : " + q.enqueue("item6")) ;
     trace ("enqueue item7 : " + q.enqueue("item7")) ;
     trace ("peek : " + q.peek()) ;
     trace ("size : " + q.size()) ;
     trace ("isFull : " + q.isFull()) ;
     
     trace("") ;
     
     trace ("q : " + q) ;
     
     trace ("------- clone") ;
     
     var clone:CircularQueue = q.clone() ;
     trace ("dequeue clone : " + clone.dequeue()) ;
     trace ("enqueue clone item8 : " + clone.enqueue("item8")) ;
     trace ("original queue : " + q) ;
     trace ("clone queue : " + clone) ;
     trace ("clone iterator :") ;
     var i:Iterator = clone.iterator() ;
     while (i.hasNext()) 
     {
         trace ("\t+ " + i.next()) ;
     }
     trace("clone.toSource : " + clone.toSource()) ;
     



Public Properties
 PropertyDefined by
  MAX_CAPACITY : uint = 4.294967295E9
[static] The default numbers of elements in the queue.
CircularQueue
Public Methods
 MethodDefined by
  
CircularQueue(qSize:uint, elements:Array = null)
Creates a new CircularQueue instance.
CircularQueue
  
clear():void
Clear all elements in the queue.
CircularQueue
  
clone():*
Returns a shallow copy of the queue.
CircularQueue
  
contains(o:*):Boolean
Returns true if the queue contains the object passed in argument.
CircularQueue
  
copy():*
Returns a deep copy of the queue.
CircularQueue
  
dequeue():Boolean
Retreives the first element in the queue object, return a boolean.
CircularQueue
  
element():*
Returns the value of the first element in the queue.
CircularQueue
  
enqueue(o:*):Boolean
Enqueue a new element in the queue if the que is not full, return a boolean.
CircularQueue
 Inherited
Returns the internal ILogger reference of this ILogable object.
CoreObject
 Inherited
hashCode():uint
Returns a hashcode value for the object.
CoreObject
  
isEmpty():Boolean
Returns true if the queue is empty.
CircularQueue
  
isFull():Boolean
Returns true if the queue is full.
CircularQueue
  
Returns the iterator of the queue.
CircularQueue
  
maxSize():uint
Returns the max number of occurrences in the given queue.
CircularQueue
  
peek():*
Returns the value of the first element in the queue or null if the queue is empty.
CircularQueue
  
poll():*
Returns the value of the first element in the queue and remove this value in the queue.
CircularQueue
 Inherited
setLogger(log:ILogger = null):void
Sets the internal ILogger reference of this ILogable object.
CoreObject
  
size():uint
Returns the number of elements in the CircularQueue.
CircularQueue
  
toArray():Array
Returns the array representation of the CircularQueue.
CircularQueue
  
toSource(indent:int = 0):String
Returns a eden representation of the object.
CircularQueue
  
toString():String
Returns the string representation of this instance.
CircularQueue
Property detail
MAX_CAPACITYproperty
public static var MAX_CAPACITY:uint = 4.294967295E9

The default numbers of elements in the queue.

Constructor detail
CircularQueue()constructor
public function CircularQueue(qSize:uint, elements:Array = null)

Creates a new CircularQueue instance.

Parameters
qSize:uint — the max number of element in the queue
 
elements:Array (default = null) — an array with elements to enqueue in the current stack.
Method detail
clear()method
public function clear():void

Clear all elements in the queue.

clone()method 
public function clone():*

Returns a shallow copy of the queue.

Returns
* — a shallow copy of the queue.
contains()method 
public function contains(o:*):Boolean

Returns true if the queue contains the object passed in argument.

Parameters
o:*

Returns
Booleantrue if the queue contains the object passed in argument.
copy()method 
public function copy():*

Returns a deep copy of the queue.

Returns
* — a deep copy of the queue.
dequeue()method 
public function dequeue():Boolean

Retreives the first element in the queue object, return a boolean.

Returns
Booleantrue if the first element in the queue is dequeue.
element()method 
public function element():*

Returns the value of the first element in the queue.

Returns
* — the value of the first element in the queue.
enqueue()method 
public function enqueue(o:*):Boolean

Enqueue a new element in the queue if the que is not full, return a boolean.

Parameters
o:*

Returns
Boolean
isEmpty()method 
public function isEmpty():Boolean

Returns true if the queue is empty.

Returns
Booleantrue if the queue is empty.
isFull()method 
public function isFull():Boolean

Returns true if the queue is full.

Returns
Booleantrue if the queue is full.
iterator()method 
public function iterator():Iterator

Returns the iterator of the queue.

See vegas.data.iterator.ProtectedIterator

Returns
Iterator — the iterator of the queue.
maxSize()method 
public function maxSize():uint

Returns the max number of occurrences in the given queue.

Returns
uint — the max number of occurrences in the given queue.
peek()method 
public function peek():*

Returns the value of the first element in the queue or null if the queue is empty.

Returns
* — the value of the first element in the queue or null if the queue is empty.
poll()method 
public function poll():*

Returns the value of the first element in the queue and remove this value in the queue.

Returns
* — the value of the first element in the queue and remove this value in the queue.
size()method 
public function size():uint

Returns the number of elements in the CircularQueue.

Returns
uint — the number of elements in the CircularQueue.
toArray()method 
public function toArray():Array

Returns the array representation of the CircularQueue.

Returns
Array — the array representation of the CircularQueue.
toSource()method 
public override function toSource(indent:int = 0):String

Returns a eden representation of the object.

Parameters
indent:int (default = 0)

Returns
String — a string representation the source code of the object.
toString()method 
public override function toString():String

Returns the string representation of this instance.

Returns
String — the string representation of this instance