7个不稳定版本
0.4.2 | 2021年12月26日 |
---|---|
0.4.1 | 2021年5月22日 |
0.4.0 | 2020年9月29日 |
0.3.0 | 2020年3月13日 |
0.1.4 | 2019年12月20日 |
在 数据结构 中排名第 950
每月下载量 38
8KB
93 行
实现一个宏,为任意长度的数组提供编译时的快速排序函数,数组中包含任何具有PartialOrd实现的原始Copy类型。
欢迎贡献/建议等!
最低支持的Rust版本:由于使用了不稳定的功能,目前这是一个仅适用于nightly的crate。
默认完全兼容#![no_std]
。
注意:从版本0.3.0开始,在本地源中指定#![feature(const_fn, const_if_match, const_loop)]
不再必要以使用宏。
基本使用示例
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);
}
许可证
受MIT许可证或Apache许可证2.0版本的许可。您可以选择!任何源代码贡献将以相同的方式进行双许可。