use core::marker::PhantomData; use crate::{inner::Inner, Permutation}; /// Decomposes permutations into disjoint cycles. #[derive(Clone, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)] #[must_use] pub struct Decomposer { array: [u8; ELEMENTS], index: u8, phantom: PhantomData, } impl Iterator for Decomposer { type Item = Permutation; fn next(&mut self) -> Option { while let Some(x) = self.array.get(self.index as usize) { let mut x1 = *x; let mut i = self.index; self.index += 1; if x1 != i { let mut arr = Permutation::::DEFAULT_ARRAY; while i != x1 { arr[i as usize] = x1; self.array[i as usize] = i; i = x1; x1 = self.array[i as usize]; } let perm = Permutation::::calculate_unchecked(arr, |x| *x); return Some(perm); } } None } } impl From> for Decomposer { fn from(perm: Permutation) -> Self { Self { array: perm.get_array(), index: 0, phantom: core::marker::PhantomData, } } }