Sort in parallel

    0

    0

    Giovanny Gongora

    Codiga's Rust Recipes

    sort a vector

    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();
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.