Adam
Adam

Reputation: 5141

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, etc...), 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..

Upvotes: 4

Views: 1322

Answers (4)

RanjanaLK
RanjanaLK

Reputation: 693

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.

Upvotes: 1

vissi
vissi

Reputation: 2334

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).

Upvotes: 0

KingCrunch
KingCrunch

Reputation: 131881

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.

Upvotes: 2

Steve Claridge
Steve Claridge

Reputation: 11080

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.

Upvotes: 1

Related Questions