fn permute_and_undo<T>(permutation: &[usize], items: &mut Vec<T>, is_apply: bool) {
    let mut cache_: HashSet<usize> = std::collections::HashSet::new();
    permutation
        .iter()
        .enumerate()
        .for_each(|(i, p)| match is_apply {
            true => {
                if !cache_.contains(p) {
                    items.swap(i, *p);
                    cache_.insert(i);
                    cache_.insert(*p);
                }
            }
            false => {
                if !cache_.contains(&i) {
                    items.swap(i, *p);
                    cache_.insert(i);
                    cache_.insert(*p);
                }
            }
        });
}
/// applies or un-applies permutation
applies or un-applies permutation
applies or un - applies permutation
fn permute_and_undo<T>(permutation: &[usize], items: &mut Vec<T>, is_apply: bool) {
    let mut cache_: HashSet<usize> = std::collections::HashSet::new();
    permutation
        .iter()
        .enumerate()
        .for_each(|(i, p)| match is_apply {
            true => {
                if !cache_.contains(p) {
                    items.swap(i, *p);
                    cache_.insert(i);
                    cache_.insert(*p);
                }
            }
            false => {
                if !cache_.contains(&i) {
                    items.swap(i, *p);
                    cache_.insert(i);
                    cache_.insert(*p);
                }
            }
        });
}
fn permute_and_undo < T > ( permutation : & [ usize ] , items : & mut Vec < T > , is_apply : bool ) { let mut cache_ : HashSet < usize > = std :: collections :: HashSet :: new ( ) ; permutation . iter ( ) . enumerate ( ) . for_each ( | ( i , p ) | match is_apply { true => { if ! cache_ . contains ( p ) { items . swap ( i , * p ) ; cache_ . insert ( i ) ; cache_ . insert ( * p ) ; } } false => { if ! cache_ . contains ( & i ) { items . swap ( i , * p ) ; cache_ . insert ( i ) ; cache_ . insert ( * p ) ; } } } ) ; }
applies or un-applies permutation
applies or un - applies permutation
permutation
&[usize]
items
&mut Vec<T>
is_apply
bool
permutation
&[usize]
items
&mut Vec<T>
is_apply
bool