scandum/quadsort
FreeQuadsort is a branchless stable adaptive mergesort faster than quicksort.
FreeFree tier
About scandum/quadsort
Quadsort is a stable bottom-up adaptive branchless merge sort implemented in C. It outperforms quicksort on random, ordered, and reverse-order data by using a quad swap analyzer that processes elements 4 at a time, reducing branch mispredictions. The algorithm detects ordered or reverse-order blocks with minimal comparisons and performs branchless swaps. It also employs a ping-pong quad merge to merge four blocks simultaneously, minimizing memory moves. Benchmarks and visualizations are provided in the repository.
Key Features
Branchless stable adaptive merge sort
Quad swap analyzer: processes 8 elements at a time with minimal comparisons
Detects ordered and reverse-order data efficiently
Branchless parity merge and swaps
Ping-pong quad merge reduces memory moves
Bottom-up merge sort design
Faster than quicksort on random, ordered, and reverse data
Benchmarks and visualization available
Pros & Cons
Pros
- Faster than quicksort on many data distributions (random, ordered, reverse)
- Branchless design reduces branch mispredictions significantly
- Stable sort (preserves order of equal elements)
- Adaptive to data patterns, minimizing comparisons on ordered data
- Open-source and free to use
- Well-documented with benchmarks and visualizations
Best For
Sorting large datasets where branch mispredictions are costlyStable sorting requirements in C programsPerformance-critical applications needing consistent sorting speedSorting partially ordered or reverse-order data efficiently
FAQ
How does quadsort compare to quicksort?
Quadsort is typically faster than quicksort on random, ordered, and reverse-order data due to its branchless design and adaptive behavior. Benchmarks in the repository show it outperforming quicksort consistently.
What does 'quad' refer to in quadsort?
The name comes from processing elements 4 at a time (quads) during the initial analysis and swapping phase, as well as merging 4 blocks simultaneously in the ping-pong quad merge.
Is quadsort a stable sort?
Yes, quadsort is a stable sorting algorithm, meaning it preserves the relative order of equal elements.
What programming language is quadsort implemented in?
Quadsort is implemented in C and is available as an open-source library on GitHub.