#sorting #cycle #optimal #minimum

cycle-sort

Simple generic Cycle sort implementation

4 releases (2 breaking)

0.3.0 Apr 5, 2019
0.2.0 Aug 29, 2018
0.1.1 Feb 23, 2018
0.1.0 Feb 23, 2018

#6 in #optimal


Used in crate-race

Apache-2.0

10KB
183 lines

cycle-sort

crates.io Documentation

Rust library for sorting slices using Cycle sort. The functions follow the same semantics as in the standard library. I built this to learn Rust.


lib.rs:

Simple Cycle sort implementation.

Cycle sort is an unstable comparison sort that minimizes the number of writes. It has a best- and worst-case performance of O(n^2), making it slow on large sets of data. It is useful when writes are expensive and want to be reduced.

Because the algorithm performs in O(n^2) for sorted lists, you may want to consider checking if sorting is necessary before actually sorting.

Safety

If the comparison function passed to cycle_sort_by or the key extraction function passed to cycle_sort_by_key panics, the data being sorted is likely to end up in an invalid state.

No runtime deps