Welcome to this library—a chaotic collection of experiments, half-baked ideas, and random bursts of inspiration. This is not a polished, production-ready framework but rather a playground for concepts that may or may not evolve into something useful.
Because of its experimental nature, stability is not guaranteed. Features may change, disappear, or break without warning. If you're looking for a dependable tool, you might want to look elsewhere. But if you're here for curiosity, exploration, or sheer madness, welcome aboard!
Use at your own risk, and enjoy the ride.
Libslm Sort is designed to let you tinker with sorting in a variety of ways, offering full control over the comparison function, the range of the array you’re sorting, and even the algorithm you want to use. Whether you're optimizing code, trying to understand sorting techniques, or just procrastinating by playing with data.
Disclaimer: This library is built with curiosity in mind. It's stable-ish, but don't use it in production unless you want to embrace the chaos.
- Multiple sorting algorithms implemented from scratch
- Plug-and-play comparison logic (
CompareFunction
) - Custom sort ranges (
start
,end
) - Benchmarked and battle-tested (by one very bored developer)
Algorithm | Stable | Best | Avarage | Worst | Avarage Time⁽¹⁾ |
---|---|---|---|---|---|
Bubblesort | ✅ | O(N) | O(N²) | O(N²) | 176.84 ms |
Heapsort | 🔲 | O(N log N) | O(N log N) | O(N log N) | 1.27 ms |
Insertionsort | ✅ | O(N) | O(N²) | O(N²) | 128.91 ms |
Introsort | 🔲 | O(N log N) | O(N log N) | O(N log N) | 0.99 ms |
Mergesort | ✅ | O(N log N) | O(N log N) | O(N log N) | 1.83 ms |
Quicksort | 🔲 | O(N log N) | O(log N) | O(N²) | 1.19 ms |
Selectionsort | 🔲 | O(N²) | O(N²) | O(N²) | 79.68 ms |
Shellsort | 🔲 | O(N log N) | O(log N) | O(N²) | 1.78 ms |
Timsort | 🔲 | O(N log N) | O(log N) | O(N²) | 0.92 ms |
⁽¹⁾ Avarage time is calculated by running 10,000 random arrays, and taking the medien of the results.
import { quicksort, CompareFunction } from 'libslm-sort';
const data = [5, 3, 8, 1, 2];
const compare: CompareFunction = (a, b) => {
if (a > b) return 1;
if (a < b) return -1;
return 0;
};
const sorted = quicksort(data, 0, data.length - 1, compare);
console.log(sorted); // [1, 2, 3, 5, 8]
- ✅ Initial release with working algorithms
- 🔲 Better error messages and typings
- 🔲 Add unit tests
- 🔲 Visualization tool (maybe...)
Since this library is experimental, these implementations may change or expand over time. Use them as needed, tweak them as desired, and embrace the chaos.
- Most of the sorting functions are written from scratch.
- They support custom ranges and comparison logic.
- You can help! Feel free to open issues or PRs.