#order #rank #indices

reorder

Reorder a slice based on a slice of indices

5 stable releases

2.1.3 Mar 26, 2022
2.1.2 Jan 13, 2022
2.0.1 Dec 31, 2021
2.0.0 Apr 14, 2021
1.0.0 Dec 12, 2018

#13 in #rank


Used in kayak_ui

MIT/Apache

4KB

Simple crate that will reorder a slice based on a slice of indices without an auxiliary array.

Check it out on crates.io and github and docs.rs.

Example

fn main() {
    
    let (mut arr, mut ind, res) = (
        [50, 40, 70, 60, 90, 10],
        [03, 00, 04, 01, 02, 05],
        [40, 60, 90, 50, 70, 10],
    );
    reorder_index(&mut arr, &mut ind);
    assert_eq!(arr, res);
}

lib.rs:

Simple crate that will reorder a slice based on a slice of indices without an auxiliary array. See https://www.geeksforgeeks.org/reorder-a-array-according-to-given-indexes/

No runtime deps