pub fn cyclic_decomposition(&self) -> Cycles {
        // keep track of visited indices
        let mut visited = vec![false; self.len()];

        Cycles {
            cycles: (0..self.len())
                .filter_map(|i| {
                    if !visited[i] {
                        let mut current = i;
                        let mut cycle = vec![current];

                        loop {
                            visited[current] = true;
                            // follow the cycle
                            current = self.indices[current];

                            if current == i {
                                break;
                            }
                            // cycles are disjoint
                            debug_assert!(!visited[current]);

                            cycle.push(current);
                        }
                        // if internal representation is reversed, cycles need to be reversed
                        // accordingly (a reverse cycle is the inverse permutation)
                        if self.inv {
                            cycle.reverse()
                        }
                        Some(cycle)
                    } else {
                        None
                    }
                })
                .collect(),
        }
    }
/// Compute the cyclic decomposition of the permutation.
///
/// A cyclic permutation is a permutation that cyclicly maps a subset of the elements of a
/// set, while fixing the other elements in place. e.g the permutation created by
/// `Permutation::from_vec(vec![1, 2, 3, 0, 4])` is a cycle of the indices (0, 1, 2, 3) while
/// 4 is fixed in place.
///
/// A cycle decomposition of a permutation is a set of disjoint cyclic permutations which,
/// when composed together, form the original permutation.
///
/// Since a cycle is just a series of swaps, applying it to a collection is a matter of
/// swapping elements and so can be done in-place, and likewise for a composition of disjoint
/// cycles, which is why this decomposition is useful.
///
/// For more information see https://groupprops.subwiki.org/wiki/Understanding_the_cycle_decomposition
///
Compute the cyclic decomposition of the permutation.
A cyclic permutation is a permutation that cyclicly maps a subset of the elements of a
set, while fixing the other elements in place. e.g the permutation created by
`Permutation::from_vec(vec![1, 2, 3, 0, 4])` is a cycle of the indices (0, 1, 2, 3) while
4 is fixed in place.

A cycle decomposition of a permutation is a set of disjoint cyclic permutations which,
when composed together, form the original permutation.

Since a cycle is just a series of swaps, applying it to a collection is a matter of
swapping elements and so can be done in-place, and likewise for a composition of disjoint
cycles, which is why this decomposition is useful.


Compute the cyclic decomposition of the permutation . A cyclic permutation is a permutation that cyclicly maps a subset of the elements of a set while fixing the other elements in place . e . g the permutation created by ` Permutation :: from_vec ( vec! [ 1 2 3 0 4 ] ) ` is a cycle of the indices ( 0 1 2 3 ) while 4 is fixed in place . A cycle decomposition of a permutation is a set of disjoint cyclic permutations which when composed together form the original permutation . Since a cycle is just a series of swaps applying it to a collection is a matter of swapping elements and so can be done in - place and likewise for a composition of disjoint cycles which is why this decomposition is useful .
pub fn cyclic_decomposition(&self) -> Cycles {
        // keep track of visited indices
        let mut visited = vec![false; self.len()];
        Cycles {
            cycles: (0..self.len())
                .filter_map(|i| {
                    if !visited[i] {
                        let mut current = i;
                        let mut cycle = vec![current];
                        loop {
                            visited[current] = true;
                            // follow the cycle
                            current = self.indices[current];
                            if current == i {
                                break;
                            }
                            // cycles are disjoint
                            debug_assert!(!visited[current]);
                            cycle.push(current);
                        }
                        // if internal representation is reversed, cycles need to be reversed
                        // accordingly (a reverse cycle is the inverse permutation)
                        if self.inv {
                            cycle.reverse()
                        }
                        Some(cycle)
                    } else {
                        None
                    }
                })
                .collect(),
        }
    }
pub fn cyclic_decomposition ( & self ) -> Cycles { // keep track of visited indices let mut visited = vec ! [ false self len ( ) ] ; Cycles { cycles : ( 0 .. self . len ( ) ) . filter_map ( | i | { if ! visited [ i ] { let mut current = i ; let mut cycle = vec ! [ current ] ; loop { visited [ current ] = true ; // follow the cycle current = self . indices [ current ] ; if current == i { break ; } // cycles are disjoint debug_assert ! ( visited [ current ] ) ; cycle . push ( current ) ; } // if internal representation is reversed, cycles need to be reversed // accordingly (a reverse cycle is the inverse permutation) if self . inv { cycle . reverse ( ) } Some ( cycle ) } else { None } } ) . collect ( ) , } }
Compute the cyclic decomposition of the permutation.
Compute the cyclic decomposition of the permutation .
&self
&self