Download the PHP package the-jj/spl-collections-sort without Composer
On this page you can find all versions of the php package the-jj/spl-collections-sort. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download the-jj/spl-collections-sort
More information about the-jj/spl-collections-sort
Files in the-jj/spl-collections-sort
Package spl-collections-sort
Short Description Helper library for sorting Spl data structures
License MIT
Informations about the package spl-collections-sort
SPL collections sort
Several methods for sorting SPL datastructures. Currently only SplFixedArray
objects are supported. Should be fast with big arrays as well.
Basic usage
All sorting algorithms accept SplFixedArray
object as first argument and optional comparison callback function as second argument. Sorting is done in place.
- Insertion sort
- Quicksort
- Mergesort
- Fallback to standard PHP array
sort()
Insertion sort
Custom comparison function
Boundaries
Additionally, insertion sort accepts two more arguments - boundaries $low
and $high
:
Quicksort
Non-recursive implementation is used, which makes it viable for sorting big arrays. Upon reaching subsets of 5 elements or less, falls back to insertion sort.
Custom comparison function
Mergesort
A bottom-up (non-recursive) implementation is used.
Usage? You guessed it:
Custom comparison function
Array sort
There is one more sorting method - array sort that uses PHP's sort()
(or usort()
) method. Usage is same as with the above algorithms:
Custom comparison function
Why?
When using a regular PHP array, we are offered a vast array (no pun intended) of sorting functions. However, no such thing is offered for SplFixedArray
objects in vanilla PHP.
This library is to change that. Currently it offers several methods for sorting SplFixedArray
objects. In the future, I might add support for other structures (that make sense to be sorted, like doubly-linked list?).