Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/ sort Public

Collection of hand-crafted sorting algorithms made for experimentation and fun.

License

Notifications You must be signed in to change notification settings

libslm/sort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

2 Commits

Repository files navigation

Libslm (Life is boring so let's make) Sort

Version License

πŸ“š Indexing

πŸ§ͺ Introduction

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.

⚠️ Use at your own risk.

i️ 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.

✨ Features

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

🧩 Supported Algorithms

Algorithm Stable(1) Best Avarage Worst Avarage Time(2)
Bubblesort βœ… n n2 n2 ~176.84 ms
Heapsort πŸ”² n log n n log n n log n ~1.27 ms
Insertionsort βœ… n n2 n2 ~128.91 ms
Introsort πŸ”² n log n n log n n log n ~0.99 ms
Mergesort βœ… n log n n log n n log n ~1.83 ms
Quicksort πŸ”² n log n n log n n2 ~1.19 ms
Selectionsort πŸ”² n2 n2 n2 ~79.68 ms
Shellsort πŸ”² n log n n log n n4/3 ~1.78 ms
Timsort βœ… n n log n n log n ~0.92 ms

(1) A sorting algorithm is said to be stable if two objects with equal keys appear in the same order in sorted output as they appear in the input array to be sorted.

(2) Avarage time is calculated by running 10,000 random arrays, and taking the medien of the results.

πŸ’‘ Usage Example

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]

πŸ›£οΈ Roadmap

  • βœ… Initial release with working algorithms
  • πŸ”² Better error messages and typings
  • πŸ”² Add unit tests
  • πŸ”² Visualization tool (maybe...)

πŸ“ Notes

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.

  • All 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.

About

Collection of hand-crafted sorting algorithms made for experimentation and fun.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /