[![rayon-badge]][rayon] [![rand-badge]][rand] [![cat-concurrency-badge]][cat-concurrency]
此示例:并行排序字符串 vector。
分配一个空字符串的 vector。par_iter_mut().for_each
会并发填充随机值。虽然存在多种选择,可以对可枚举数据类型进行排序,par_sort_unstable
通常比稳定排序算法快。
extern crate rand;
extern crate rayon;
use rand::{Rng, thread_rng};
use rand::distributions::Alphanumeric;
use rayon::prelude::*;
fn main() {
let mut vec = vec![String::new(); 100_000];
vec.par_iter_mut().for_each(|p| {
let mut rng = thread_rng();
*p = (0..5).map(|_| rng.sample(&Alphanumeric)).collect()
});
vec.par_sort_unstable();
}