Just another of many already existing and probably better Sorted Linked List implementations.
This is proof of my know-how. Use at your own risk.
PHP is great tool, but if you need to use optimized data structures, other than just hashmap (PHP array) or PHP objects, I strongly recommend you to use another programming language.
For example Sorted Linked List has great implementation in Rust language
Also do not forget that there are many structures, like B-Tree (balanced tree) and search techniques like Tree traversal. Choose what suites your need most.
There are many ways, how to sort data. With increasing data size and demand of speed a simple PHP array sort became insufficient.
Sorted Linked List keeps non-unique data in a sequence, sorted by their values, by various comparing algorithms.
Its main advantage is very small memory footprint to sort data, even on very large data set and even during change of the data set.
Time complexity to sort data is O(n)
(linear), where n is the number of items in the list.
Time complexity to insert new value is O(1)
, if you already know the position for new value. Otherwise O(n)
(search
for position) + O(1)
(insert new value).