fn look_for_cycle(
    current: Group,
    ictriggers: &AHashMap<Group, Vec<SpawnTrigger>>,
    visited: &mut Vec<Group>,
    inputs: &mut AHashSet<Group>,
    outputs: &mut AHashSet<Group>,
    cycle_points: &mut AHashSet<Group>,
    all: &mut Vec<Connection>,
) {
    if let Some(connections) = ictriggers.get(&current) {
        for SpawnTrigger {
            target: g,
            delay,
            trigger,
        } in connections
        {
            if visited.contains(g) {
                //println!("cycle detected");
                outputs.insert(current);
                inputs.insert(*g);
                all.push(Connection {
                    start_group: current,
                    end_group: *g,
                    delay: *delay,
                    trigger: *trigger,
                });
                cycle_points.insert(current);

                return;
            }

            visited.push(current);

            look_for_cycle(*g, ictriggers, visited, inputs, outputs, cycle_points, all);

            assert_eq!(visited.pop(), Some(current));
        }
    }
}
// set triggers that make cycles to inputs and outputs
set triggers that make cycles to inputs and outputs
set triggers that make cycles to inputs and outputs
fn look_for_cycle(
    current: Group,
    ictriggers: &AHashMap<Group, Vec<SpawnTrigger>>,
    visited: &mut Vec<Group>,
    inputs: &mut AHashSet<Group>,
    outputs: &mut AHashSet<Group>,
    cycle_points: &mut AHashSet<Group>,
    all: &mut Vec<Connection>,
) {
    if let Some(connections) = ictriggers.get(&current) {
        for SpawnTrigger {
            target: g,
            delay,
            trigger,
        } in connections
        {
            if visited.contains(g) {
                //println!("cycle detected");
                outputs.insert(current);
                inputs.insert(*g);
                all.push(Connection {
                    start_group: current,
                    end_group: *g,
                    delay: *delay,
                    trigger: *trigger,
                });
                cycle_points.insert(current);
                return;
            }
            visited.push(current);
            look_for_cycle(*g, ictriggers, visited, inputs, outputs, cycle_points, all);
            assert_eq!(visited.pop(), Some(current));
        }
    }
}
fn look_for_cycle ( current : Group , ictriggers : & AHashMap < Group , Vec < SpawnTrigger > > , visited : & mut Vec < Group > , inputs : & mut AHashSet < Group > , outputs : & mut AHashSet < Group > , cycle_points : & mut AHashSet < Group > , all : & mut Vec < Connection > , ) { if let Some ( connections ) = ictriggers . get ( & current ) { for SpawnTrigger { target : g , delay , trigger , } in connections { if visited . contains ( g ) { //println!("cycle detected"); outputs . insert ( current ) ; inputs . insert ( * g ) ; all . push ( Connection { start_group : current , end_group : * g , delay : * delay , trigger : * trigger , } ) ; cycle_points . insert ( current ) ; return ; } visited . push ( current ) ; look_for_cycle ( * g , ictriggers , visited , inputs , outputs , cycle_points , all ) ; assert_eq ! ( visited pop ( ) Some ( current ) ) ; } } }
set triggers that make cycles to inputs and outputs
set triggers that make cycles to inputs and outputs
current
Group
ictriggers
&AHashMap<Group, Vec<SpawnTrigger>>
visited
&mut Vec<Group>
inputs
&mut AHashSet<Group>
outputs
&mut AHashSet<Group>
cycle_points
&mut AHashSet<Group>
all
&mut Vec<Connection>