Skip to main content

learned_sort

Function learned_sort 

Source
pub fn learned_sort<T>(arr: &mut [T])
where T: Ord + Copy + Send + Sync + Into<i64>,
Expand description

Sorts a slice using the Learned Partition Sort algorithm.

This algorithm achieves O(N) complexity on well-distributed numerical data by learning the data distribution and using it to directly calculate element positions.

§Algorithm

  1. For small inputs (< 8192 elements), falls back to sort_unstable
  2. Samples data to find min/max bounds
  3. Distributes elements to buckets based on calculated positions
  4. Sorts each bucket in parallel using Rayon

§Examples

use learned_partition_sort::learned_sort;

let mut data: Vec<i64> = vec![5, 2, 8, 1, 9];
learned_sort(&mut data);
assert_eq!(data, vec![1, 2, 5, 8, 9]);