PHP Classes
Icontem

File: queue.class.php4


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Michal Golebiowski  >  FIFO Queue  >  queue.class.php4  
File: queue.class.php4
Role: Class source
Content type: text/plain
Description: Queue class for PHP 4
Class: FIFO Queue
Implementation of FIFO (First In First Out) queue
 

Contents

Class file image Download
<?php
/**
* Queue class - under PHP 4
*
* @description This is an implementation of FIFO (First In First Out) queue.
*
* @copyright (c) 2003 Michal 'Seth' Golebiowski <sethmail at poczta dot fm>
*   Released under the GNU General Public License
*   license is attached to package in license.txt file
*
* @updated 10.08.2003
*
* @example example.php4 Simple example of puting ang geting datas from queue
*
* @requirement PHP 4
*
*
*
*
* @greetings goes to all developers from Poland especially from php.pl :-)
*/


/**
* Default size of queue
*/
define'QUEUE_DEFAULT_SIZE'15 );


/**
* Implementation of FIFO queue
* @version 1.9
*/
class Queue
{
  var
    
$arrQueue,       // Array of queue items
    
$intBegin,       // Begin of queue - head
    
$intEnd,         // End of queue - tail
    
$intArraySize,   // Size of array
    
$intCurrentSize// Current size of array


  /**
  * Queue constructor
  * @param int $intQueue - size of queue
  */
  
function Queue$intSize QUEUE_DEFAULT_SIZE )
  {
    
$this->arrQueue     = Array();
    
$this->intArraySize $intSize;

    
$this->Clear();
  }
  

  
/**
  * Add item to queue
  * @param obj &$objQueueItem - queue item object
  * @return true if added to queue or false if queue is full and item could not be added
  */
  
function Put( &$objQueueItem  )
  {
    if ( 
$this->intCurrentSize >= $this->intArraySize )
    {
      return 
false;
    }

    if ( 
$this->intEnd == $this->intArraySize )
    {
      
$this->intEnd 0;
    }
    else
    {
      
$this->intEnd++;
    }
    
    
$this->arrQueue$this->intEnd ] = $objQueueItem;
    
$this->intCurrentSize++;
    
    return 
true;
  }
  

  
/**
  * Get item from queue
  * @return object (queue iteme) or false if there is now items in queue
  */
  
function Get()
  {
    if ( 
$this->IsEmpty() ){
      return 
false;
    }
    
    
$objItem $this->arrQueue[$this->intBegin];
    
    if ( 
$this->intBegin == $this->intArraySize )
    {
      
$this->intBegin 0;
    }
    else
    {
      
$this->intBegin++;
    }
    
    
$this->intCurrentSize--;
    
    return 
$objItem;
  }


  
/**
  * Check if queue is empty
  * @return true if it is empty or false if not
  */
  
function IsEmpty()
  {
    return ( 
$this->intCurrentSize == true false );
  }


  
/**
  * Clear queue
  */
  
function Clear()
  {
    
$this->arrCurrentSize 0;
    
$this->intBegin       0;
    
$this->intEnd         $this->intArraySize 1;
  }
}
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products