VisionSort builds a probabilistic model of your data's distribution before touching most elements — then predicts where each value belongs, falling back to comparisons only when it isn't sure.
Existing sorts extract one bit of information per comparison: A > B or A < B. VisionSort extracts two: the element's position, and a model update that sharpens predictions for every element not yet processed.
Each phase has a defined cost and a clear output. Phases 1–3 build the picture. Phase 4 does the work — cheapening as it goes. Phase 5 integrates.
Each segment is scored on disorder and entropy independently. The combination determines which of four sort routes is applied. Only one quadrant requires full O(n log n) treatment.
VisionSort works on any type that implements PartialOrd + Into<f64> + Copy.
All standard numeric types work out of the box.
use visionsort::vision_sort; fn main() { let mut data = vec![3.0_f64, 1.0, 4.0, 1.0, 5.0, 9.0, 2.0, 6.0]; vision_sort(&mut data); println!("{:?}", data); // [1.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 9.0] }
use visionsort::VisionSort; fn main() { let mut data = vec![5.0_f64, 2.0, 8.0, 1.0, 9.0, 3.0]; let mut sorter = VisionSort::new(); sorter.sort(&mut data); // Inspect the distribution model post-sort println!("entropy: {}", sorter.model.entropy); println!("observations: {}", sorter.model.observations); println!("anchors: {:?}", sorter.model.anchors); }
use visionsort::vision_sort; // Sort by timestamp — implement Into<f64> on your key #[derive(Clone, Copy, PartialEq, PartialOrd)] struct Event { timestamp: f64, payload: u32, } impl Into<f64> for Event { fn into(self) -> f64 { self.timestamp } } fn main() { let mut events = vec![ Event { timestamp: 1700.0, payload: 42 }, Event { timestamp: 1500.0, payload: 11 }, ]; vision_sort(&mut events); }
# Cargo.toml [package] name = "my-project" version = "0.1.0" edition = "2021" [dependencies] visionsort = { path = "../visionsort" } # Then: cargo build # Then: cargo test (16 tests, all green)