开发者

PHP Data Structures (Java-like) Collections

I'm wondering about the merits of creating a small library, probably for personal use which specifies a few data structures such as Linked Lists, Trees (Binary, AVL, e开发者_如何学JAVAtc...), Hash Lookup Tables, and the like.

Some of these would be built on top of the native PHP array, as it acts as many of these types, and some potentially wouldn't.

My question is really, would it make sense to build any of these classes - especially those which may not build upon the native array? I'm talking here about the computational practicality, and don't especially want to get into the dynamic vs. typed language argument (I'm still interested in hearing anything interesting and relevant on that topic as an aside).

Is it mad to build these (possibly more efficient, logically) data-structures using classes when we have a C implementation of a basic array?

Thanks..


Have a look at SPL

http://php.net/manual/en/book.spl.php

and read Matthew Turland's New Spl Features in PHP 5.3 for a discussion of those data structures.


There is already the http://php.net/manual/en/book.spl.php which may cover what you want but if building these would be interesting for you and improve your PHP/general coding skills then I think it would be a very good idea.

May also be a good library to release to a wider audience and something to put on your CV.


This is a late answer but this this would help someone looking for PHP data structures. PHP 7 introduces an extension called ds providing specialized data structures as an alternative to the array.

The ds,

  • uses the Ds\ namespace.
  • has 3 interfaces namely,Collection, Sequence and Hashable.
  • has 8 classes namely, Vector, Deque,Queue, PriorityQueue, Map, Set, Stack, and Pair.

For more information checkout the Manual and also This blog post has some awesome information including benchmarks.


If you are looking into performance, you may create a php module (like SPL) that gives access to these structures (as they are already implemented in C).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜