Annotation of embedaddon/php/ext/spl/internal/splqueue.inc, revision 1.1.1.1

1.1       misho       1: <?php
                      2: 
                      3: /** @file splqueue.inc
                      4:  * @ingroup SPL
                      5:  * @brief class SplQueue
                      6:  * @author  Etienne Kneuss
                      7:  * @date    2008 - 2009
                      8:  *
                      9:  * SPL - Standard PHP Library
                     10:  */
                     11: 
                     12: /** @ingroup SPL
                     13:  * @brief Implementation of a Queue through a DoublyLinkedList. As SplQueue
                     14:  *        extends SplDoublyLinkedList, unshift() and pop() are still available 
                     15:  *        even though they don't make much sense for a queue. For convenience,
                     16:  *        two aliases are available:
                     17:  *         - enqueue() is an alias of push()
                     18:  *         - dequeue() is an alias of shift()
                     19:  *
                     20:  * @since PHP 5.3
                     21:  *
                     22:  * The SplQueue class provides the main functionalities of a
                     23:  * queue implemented using a doubly linked list (DLL).
                     24:  */
                     25: class SplQueue extends SplDoublyLinkedList
                     26: {
                     27:        protected $_it_mode = parent::IT_MODE_FIFO;
                     28: 
                     29:        /** Changes the iteration mode. There are two orthogonal sets of modes that 
                     30:         * can be set:
                     31:         *
                     32:         * - The behavior of the iterator (either one or the other)
                     33:         *  - SplDoublyLnkedList::IT_MODE_DELETE (Elements are deleted by the iterator)
                     34:         *  - SplDoublyLnkedList::IT_MODE_KEEP   (Elements are traversed by the iterator)
                     35:         *
                     36:         * The default mode is 0 : SplDoublyLnkedList::IT_MODE_LIFO | SplDoublyLnkedList::IT_MODE_KEEP
                     37:         *
                     38:         * @note The iteration's direction is not modifiable for queue instances
                     39:         * @param $mode              New mode of iteration
                     40:         * @throw RuntimeException   If the new mode affects the iteration's direction.
                     41:         */
                     42:        public function setIteratorMode($mode)
                     43:        {
                     44:                if ($mode & parent::IT_MODE_LIFO === parent::IT_MODE_LIFO) {
                     45:                        throw new RuntimeException("Iterators' LIFO/FIFO modes for SplStack/SplQueue objects are frozen");
                     46:                }
                     47: 
                     48:                $this->_it_mode = $mode;
                     49:        }
                     50: 
                     51:        /** @return the first element of the queue.
                     52:         * @note dequeue is an alias of push()
                     53:         * @see splDoublyLinkedList::push()
                     54:         */
                     55:        public function dequeue()
                     56:        {
                     57:                return parent::shift();
                     58:        }
                     59: 
                     60:        /** Pushes an element at the end of the queue.
                     61:         * @param $data variable to add to the queue.
                     62:         * @note enqueue is an alias of shift()
                     63:         * @see splDoublyLinkedList::shift()
                     64:         */
                     65:        public function enqueue($data)
                     66:        {
                     67:                return parent::push($data);
                     68:        }
                     69: }
                     70: 
                     71: ?>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>