CQueue
CQueue implements a queue.
The typical queue operations are implemented, which include
enqueue(),
dequeue() and
peek(). In addition,
contains() can be used to check if an item is contained in the queue. To obtain the number of the items in the queue, check the
Count property.
Items in the queue may be traversed using foreach as follows,
foreach($queue as $item) ...
Public Properties
| Property |
Type |
Description |
Defined By |
| count | integer | Returns the number of items in the queue. | CQueue |
| iterator | Iterator | Returns an iterator for traversing the items in the queue. | CQueue |
Property Details
public integer getCount()
Returns the number of items in the queue.
public Iterator getIterator()
Returns an iterator for traversing the items in the queue. This method is required by the interface IteratorAggregate.
Method Details
public void __construct(array $data=NULL) |
| $data | array | the initial data. Default is null, meaning no initialization. |
Constructor. Initializes the queue with an array or an iterable object.
Removes all items in the queue.
public boolean contains(mixed $item) |
| $item | mixed | the item |
| {return} | boolean | whether the queue contains the item |
public void copyFrom(mixed $data) |
| $data | mixed | the data to be copied from, must be an array or object implementing Traversable |
Source Code: framework/collections/CQueue.php#71 (
show)
public function copyFrom($data)
{
if(is_array($data) || ($data instanceof Traversable))
{
$this->clear();
foreach($data as $item)
{
$this->_d[]=$item;
++$this->_c;
}
}
elseif($data!==null)
throw new CException(Yii::t('yii','Queue data must be an array or an object implementing Traversable.'));
}
Copies iterable data into the queue. Note, existing data in the list will be cleared first.
public integer count() |
| {return} | integer | number of items in the queue. |
Returns the number of items in the queue. This method is required by Countable interface.
public mixed dequeue() |
| {return} | mixed | the item at the beginning of the queue |
Source Code: framework/collections/CQueue.php#122 (
show)
public function dequeue()
{
if($this->_c===0)
throw new CException(Yii::t('yii','The queue is empty.'));
else
{
--$this->_c;
return array_shift($this->_d);
}
}
Removes and returns the object at the beginning of the queue.
public void enqueue(mixed $item) |
| $item | mixed | the item to be appended into the queue |
Adds an object to the end of the queue.
public integer getCount() |
| {return} | integer | the number of items in the queue |
Returns the number of items in the queue.
public Iterator getIterator() |
| {return} | Iterator | an iterator for traversing the items in the queue. |
Returns an iterator for traversing the items in the queue. This method is required by the interface IteratorAggregate.
public mixed peek() |
| {return} | mixed | item at the top of the queue |
Returns the item at the top of the queue.
public array toArray() |
| {return} | array | the list of items in queue |