v1.0 — ANSI C, Open Source

Polysort

n-wayAdaptive merge sort. Merge arity scales with your data — from quadsort-style 4-way to K-way heap merge with K up to 1024.

$ make && ./bench

n=100000 ints, 5 reps

algorithm time (s)

qsort 0.006082

polysort 0.010978

_

0
Max K (merge arity)
0
Merge Passes at 1B
0+
Lines of C
0
Run Block Size

The Paper

Full specification, run-time analysis, benchmarks, and distributed extensions.

Your browser does not support inline PDF viewing.

Download PDF

Benchmarks

Polysort vs qsort and distributed variants on 100K random integers, 5 runs each.

bench.c — cc -O2
FASTESTqsort
0.006082s
polysort
0.010978s
mr_sort (4,4)
0.011209s
spark_sort (4)
0.009962s
dryad_sort (4)
0.012673s
N = 100,000 integers5 repetitionsmacOS, cc -O2

All algorithms produce correctly sorted output. Library qsort is fastest at this scale — Polysort is designed to scale as n and K grow.

How It Works

Four phases from raw input to fully sorted output.

01

Run Building

Divide array into blocks of 32, sort each with insertion sort.

02

Choose K

K = clamp(4, √n, 1024). Merge arity scales with input size.

03

K-Way Merge

Min-heap merge of up to K runs. Stable — tie-break by run index.

04

Ping-Pong Buffers

Alternate between base and auxiliary buffer. Copy back when done.

Distributed Extensions

Three distributed sorting paradigms, all built on the same core primitives: run building and K-way merge.

mr_sortM mappers × R reducers (default: 4×4)

MapReduce Sort

Two-phase sort: map-side polysort per chunk, shuffle-partition by sampled split points, then K-way merge per reducer.

spark_sortP partitions (default: 4)

Spark Sort

Range-partition unsorted input in one pass, sort each partition independently with polysort, then concatenate.

dryad_sortFan-in K (default: 4)

Dryad Sort

Recursive K-way merge tree: split into K sub-ranges, sort recursively, merge with single K-way pass.

Why Polysort?

Designed for scalability, stability, and seamless integration.

K

N-Way Adaptive Merge

Merge arity K scales with input size — K ≈ √n, capped at 1024. Fewer passes as data grows.

Stable Sort

Preserves relative order of equal elements via min-heap tie-breaking by run index.

()

qsort-Compatible API

Drop-in replacement for standard C qsort with the same function signature.

O

O(n) Extra Space

Single merge buffer plus run descriptors. Falls back to in-place sort on allocation failure.

Distributed Extensions

MapReduce, Spark, and Dryad-style sorting — all built on the same core primitives.

Industrial Strength

ANSI C, modular architecture, full test coverage, and permissive license.