Гитхаб расширения: https://github.com/php-ds/ds
Статья: https://medium.com/@rtheunissen/efficient-data-structures-for-php-7-9dda7af674cd#.21kca1cnm
Статья: https://medium.com/@rtheunissen/efficient-data-structures-for-php-7-9dda7af674cd#.21kca1cnm
PHP has one data structure to rule them all. The array is a complex, flexible, master-of-none, hybrid data structure, combining the behaviour of a list and a linked map. But we use it for everything, because PHP is pragmatic: “dealing with things sensibly and realistically in a way that is based on practical rather than theoretical considerations”. An array gets the job done, even though you wouldn’t study it in a Computer Science course. Unfortunately, with flexibility comes complexity.
The recent release of PHP 7 caused a lot of excitement in the PHP community. We couldn't wait to start using the new features and get a taste of the ~2x performance boost. One of the reasons why it runs that much faster is because the array was redesigned. But it’s still the same structure, “optimised for everything; optimised for nothing” with room for improvement.
“What about the SPL data structures?”
Unfortunately… they’re terrible. They did offer some benefits prior to PHP 7, but have been neglected to the point of having no practical value.
“Why can’t we just fix and improve them?”
We could, but I believe their design and implementation is so poor that it would be better to replace them with something brand new.
“SPL data structures are horribly designed.” — Anthony Ferrara
Introducing: php-ds, a data structure extension for PHP 7.
This post briefly covers the behaviour and performance benefits of each structure. There is also a list of answers to expected questions at the end.
Github: https://github.com/php-ds
Namespace: Ds\
Interfaces: Collection, Sequence, Hashable
Classes: Vector, Deque, Stack, Queue, PriorityQueue, Map, Set