News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Matthew Weier O'Phinney's Blog:
Taming SplPriorityQueue
January 18, 2011 @ 12:43:54

Matthew Weier O'Phinney has a new post to his blog today looking at one of the tools the Standard PHP Library (SPL) has to offer developers - the SplPriorityQueue (PHP 5.3+)

SplPriorityQueue is a fantastic new feature of PHP 5.3. However, in trying to utilize it in a few projects recently, I've run into some behavior that's (a) non-intuitive, and (b) in some cases at least, undesired. In this post, I'll present my solutions.

He talks about the "first in, first out" nature of queues and how it differs from a stack (including links to some of the other SPL offerings for both). He then moves into the problems he was seeing - that iteration removes values from the heap and the unexpected order of equal values in the queue. To solve the first problem, he creates an "outer iterator" that creates an "innerQueue" that's protected. The solution for the second issue - the random queue order - is a simple one: priority indexes aren't required to be integers. Strings can be substituted to help make things a bit more unique.

0 comments voice your opinion now!
splpriorityqueue heap stack queue spl tutorial iterate priority index


blog comments powered by Disqus

Similar Posts

Zend Developer Zone: Building AutoComplete Inputs with PHP, PEAR, Dojo and YUI

Stefan Mischook's Blog: Building Objects Video (Parts 1, 2 & 3)

Lorna Mitchell's Blog: PHP OAuth Provider: Authenticate User

Jani Hartikainen's Blog: Zend_Acl part 3: creating and storing dynamic ACLs

Ibuildings techPortal: Doing the Heavy Lifting: Gearman and Magento


Community Events





Don't see your event here?
Let us know!


development bugfix deployment language community api framework series podcast symfony zendserver interview laravel release code tips introduction conference list developer

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework