pub fn generate_finite_group<G>(
    generators: &[G],
    mut g_fn: impl FnMut(&G, &G) -> G,
) -> Vec<G>
where G: Hash + Eq + Clone,
{
    use std::collections::{HashSet, VecDeque};
    assert!(generators.len() > 0, "empty groups do not exist!");

    let mut seen = HashSet::new();
    let mut out = vec![];

    let mut queue: VecDeque<_> = generators.iter().cloned().collect();

    while let Some(g) = queue.pop_front() {
        if seen.insert(g.clone()) {
            queue.extend(generators.iter().map(|h| g_fn(&g, h)));
            out.push(g);
        }
    }
    out
}
/// Generates a finite group from a non-empty set of generators.
///
/// The generators may contain duplicates or extraneous elements.
///
/// The order of the output is arbitrary, but consistent for
/// inputs that are related by a group isomorphism.
Generates a finite group from a non-empty set of generators.
The generators may contain duplicates or extraneous elements.

The order of the output is arbitrary, but consistent for
inputs that are related by a group isomorphism.
Generates a finite group from a non - empty set of generators . The generators may contain duplicates or extraneous elements . The order of the output is arbitrary but consistent for inputs that are related by a group isomorphism .
pub fn generate_finite_group<G>(
    generators: &[G],
    mut g_fn: impl FnMut(&G, &G) -> G,
) -> Vec<G>
where G: Hash + Eq + Clone,
{
    use std::collections::{HashSet, VecDeque};
    assert!(generators.len() > 0, "empty groups do not exist!");
    let mut seen = HashSet::new();
    let mut out = vec![];
    let mut queue: VecDeque<_> = generators.iter().cloned().collect();
    while let Some(g) = queue.pop_front() {
        if seen.insert(g.clone()) {
            queue.extend(generators.iter().map(|h| g_fn(&g, h)));
            out.push(g);
        }
    }
    out
}
pub fn generate_finite_group < G > ( generators : & [ G ] , mut g_fn : impl FnMut ( & G , & G ) -> G , ) -> Vec < G > where G : Hash + Eq + Clone , { use std :: collections :: { HashSet , VecDeque } ; assert ! ( generators len ( ) 0 " " ) ; let mut seen = HashSet :: new ( ) ; let mut out = vec ! [ ] ; let mut queue : VecDeque < _ > = generators . iter ( ) . cloned ( ) . collect ( ) ; while let Some ( g ) = queue . pop_front ( ) { if seen . insert ( g . clone ( ) ) { queue . extend ( generators . iter ( ) . map ( | h | g_fn ( & g , h ) ) ) ; out . push ( g ) ; } } out }
Generates a finite group from a non-empty set of generators.
Generates a finite group from a non - empty set of generators .
generators
&[G]
g_fn
impl FnMut(&G, &G) -> G
generators
&[G]
g_fn
impl FnMut(&G, &G) -> G