Guys,

PHP arrays are a great one-size-fits-all data structure. But like all
one-size-fits-all <anything>, jack-of-all-trades usually means master of
none.

There are definitely benefits to using specific data structures if
implemented correctly under the hood.

A good example of this is a Queue. Implemented properly using a
Singly-Linked-List or Doubly-Linked-List, inserts are O(1), peeks are O(1)
and removals are O(1). Compare that to an array based
queue implementation where inserts are O(1) and peeks are O(1) but removals
are O(n)... (or inserts and removals are reversed).

For low volume logic, the array can substitute for more custom data
structures quite easily. But for needs with more data (or more
transactions), there's no replacement for a proper data structure...



To the original question:

I would love to see not just more data structures, but better designed ones
in core.

For example, with SPLStack http://php.net/manual/en/class.splstack.php
1. Why the heck does it have unshift() as well as push()? A stack is a
One-way-in, one-way-out data structure, why are both exposed?
2. Why the heck does it implement ArrayAccess? Again, completely defeats
the point of a stack
3. Why does it *extend* DLL? A Stack can be implemented with a DLL, but it
is *not* a DLL. Huge difference...

Now, there was some discussion by some of us about re-doing the entire spl
data structures a while ago. This git repo (PHP) is the evolution of that
idea. https://github.com/morrisonlevi/Ardent

Now it's not written with the explicit intent of replacing SPL. It's
written in an attempt to try to get the data structures designed right.
Then, it may be ported to PECL, and then finally may be proposed to core.


As far as MAP, we already have one:
http://php.net/manual/en/class.splobjectstorage.php

My $0.02 at least,

Anthony


On Tue, Dec 18, 2012 at 1:09 PM, Ángel González <keis...@gmail.com> wrote:

> On 18/12/12 15:43, Victor Berchet wrote:
> > Dear all:
> >
> > I would like to get your feedback on implementing some more data
> > structure in the PHP core.
> (...)
>
> I think this could be summarised as "allow objects as keys for arrays".
> Which would give the Map behavior.
> Implementing Set from that is straightforward.
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Reply via email to