Skip to main content

Crate thanos_sort

Crate thanos_sort 

Source
Expand description

§Thanos Sort 🗿

⚠️ WARNING: THIS CRATE IS A JOKE. DO NOT USE FOR ACTUAL SORTING.⚠️

Thanos Sort “sorts” by repeatedly snapping away half the elements until one survivor remains. Perfectly balanced, as all things should be.

§Examples

Basic usage with mutable reference:

let mut data = vec![1, 2, 3, 4, 5];
let history = thanos_sort::thanos_sort(&mut data);

// Only one survivor remains
assert_eq!(data.len(), 1);
// History tracks each snap
assert_eq!(history.len(), 4); // 5 -> 3 -> 2 -> 1

If you need to keep the original data:

let original = vec![1, 2, 3, 4, 5];
let (survivor, history) = thanos_sort::thanos_sort_owned(&original);

// Original is unchanged
assert_eq!(original.len(), 5);
// Survivor is the result
assert_eq!(survivor.len(), 1);

Use data.sort_unstable() instead.

Functions§

thanos_sort
Thanos sorts by randomly halving the array until one survivor remains.
thanos_sort_owned
Owned version of Thanos sort that preserves the original data.