#sorting #array #quick-sort #ord

nightly no-std staticsort

Implements a macro providing a compile-time quicksort function for arrays of any length, containing any primitive Copy type with a PartialOrd implementation

7 unstable releases

0.4.2 Dec 26, 2021
0.4.1 May 22, 2021
0.4.0 Sep 29, 2020
0.3.0 Mar 13, 2020
0.1.4 Dec 20, 2019

#1614 in Data structures

Download history 1/week @ 2024-09-23 69/week @ 2024-09-30 2/week @ 2024-10-07 2/week @ 2024-10-28 2/week @ 2024-11-18 5/week @ 2024-11-25 4/week @ 2024-12-02 77/week @ 2024-12-09

88 downloads per month

MIT/Apache

8KB
93 lines

Latest Version Rustc Version nightly

Build status

Implements a macro providing a compile-time quicksort function for arrays of any length, containing any primitive Copy type with a PartialOrd implementation.

Contributions/suggestions/etc. very welcome!

Minimum supported Rust version: due to the use of unstable const fn features, this is a nightly-only crate at the moment.

Fully #![no_std] compatible by default.

Note: as of version 0.3.0, specifying #![feature(const_fn, const_if_match, const_loop)] locally in your own source is no longer necessary to use the macro.

A basic usage example:

use staticsort::staticsort;

const X: [usize; 12] = [1, 6, 2, 5, 3, 4, 7, 12, 8, 11, 9, 10];

const Y: [f64; 12] = [
  1.0, 6.0, 2.0, 5.0,
  3.0, 4.0, 7.0, 12.0,
  8.0, 11.0, 9.0, 10.0,
];

// The macro takes the following parameters in the order they're
// listed: type to sort, index to start at, index to end at, and
// either the name of an existing `const` array variable or just
// a directly-passed "anonymous" array.

// Sort all of X:
static XX: [usize; 12] = staticsort!(usize, 0, 11, X);
// Just sort half of Y:
static YY: [f64; 12] = staticsort!(f64, 0, 6, Y);
// Sort all of an array that's the same as X, but passed
// directly as a parameter:
static ZZ: [usize; 12] = staticsort!(
  usize,
  0,
  11,
  [1, 6, 2, 5, 3, 4, 7, 12, 8, 11, 9, 10]
);

fn main() {
  // Prints: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
  println!("XX: {:?}", XX);
  // Prints: [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 12.0, 8.0, 11.0, 9.0, 10.0]
  println!("YY: {:?}", YY);
  // Prints: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
  println!("ZZ: {:?}", ZZ);
}

License:

Licensed under either the MIT license or version 2.0 of the Apache License. Your choice as to which! Any source code contributions will be dual-licensed in the same fashion.

No runtime deps