| Crates.io | learned-partition-sort |
| lib.rs | learned-partition-sort |
| version | 0.1.0 |
| created_at | 2026-01-08 06:51:25.621299+00 |
| updated_at | 2026-01-08 06:51:25.621299+00 |
| description | A high-performance distribution-based sorting algorithm that learns data patterns to achieve O(N) complexity |
| homepage | |
| repository | https://github.com/keeth/learned-partition-sort |
| max_upload_size | |
| id | 2029671 |
| size | 55,713 |
A distribution-based sorting algorithm that achieves O(N) complexity by calculating element positions directly, bypassing comparison overhead.
Throughput (Melem/s) — higher is better
┌──────────────────────────────────────────────┐
100K uniform │████████████████████████████████ 145 (+66%)
1M uniform │██████████████████████████ 90 (+32%)
10M uniform │█████████████████████ 62 (+29%)
└──────────────────────────────────────────────┘
vs slice::sort_unstable
Full results: docs/BENCHMARKS.md
[dependencies]
learned-partition-sort = "0.1"
use learned_partition_sort::learned_sort;
let mut data: Vec<i64> = vec![5, 2, 8, 1, 9, 3, 7, 4, 6];
learned_sort(&mut data);
assert_eq!(data, vec![1, 2, 3, 4, 5, 6, 7, 8, 9]);
The algorithm assumes roughly uniform distribution. For adversarial inputs (all duplicates), it gracefully degrades to O(N log N).
| Scenario | Recommendation |
|---|---|
| N ≥ 100K, numerical data | ✅ Use LPS |
| N < 32K | ⚠️ Falls back to sort_unstable automatically |
| Memory constrained | ❌ LPS requires O(N) auxiliary space |
| Non-numeric types | ❌ Use std sort |
Ord + Copy + Send + Sync numeric typesThis project was built with significant assistance from AI coding assistants:
The project direction, architecture decisions, and performance validation were human-driven. The LLMs served as powerful pair-programming partners, dramatically accelerating development while the human maintained creative control.
Issues and PRs welcome. Please run cargo test and cargo clippy before submitting.
MIT — see LICENSE