fn add_random_edge(&mut self, mut original_edge: OriginalEdge)
    {
        let n = self.graph.vertex_count();
        let die = Uniform::from(0..n as u32);
        let mut first = die.sample(self.rng());
        let mut second = die.sample(self.rng());
        loop{
            // no self loops
            // not the same edge again!
            // no existing edge
            if first == second ||
                (first == original_edge.from && second == original_edge.to)
                || (first == original_edge.to && second == original_edge.from)
                || self.graph.get_mut_unchecked(first as usize)
                    .is_adjacent(second as usize)
            {
                first = die.sample(self.rng());
                second = die.sample(self.rng());
            } else {
                break;
            }

        }

        let mut create_edge = |from: u32, to: u32, mut edge: OriginalEdge| {
            edge.set_origin_false();
            let from_usize = from as usize;
            let to_usize = to as usize;
            let (vertex_from, vertex_to) = self.graph
                .get_2_mut(from_usize, to_usize);
            
            // create edge from --> to
            let (vec_to, vec_original) = vertex_from.edges_mut();
            vec_to.push(to_usize);
            vec_original.push(edge);
            // create edge to --> from
            let (vec_to, vec_original) = vertex_to.edges_mut();
            edge.swap_direction();
            vec_to.push(from_usize);
            vec_original.push(edge)
        };

        if first == original_edge.to || second == original_edge.from {
            original_edge.swap_direction();
            create_edge(second, first, original_edge)
        } else {
            create_edge(first, second, original_edge)
        }
    }
// Adding a random edge, that does not exist right now and is not "originalEdge"
Adding a random edge, that does not exist right now and is not "originalEdge"
Adding a random edge that does not exist right now and is not " originalEdge "
fn add_random_edge(&mut self, mut original_edge: OriginalEdge)
    {
        let n = self.graph.vertex_count();
        let die = Uniform::from(0..n as u32);
        let mut first = die.sample(self.rng());
        let mut second = die.sample(self.rng());
        loop{
            // no self loops
            // not the same edge again!
            // no existing edge
            if first == second ||
                (first == original_edge.from && second == original_edge.to)
                || (first == original_edge.to && second == original_edge.from)
                || self.graph.get_mut_unchecked(first as usize)
                    .is_adjacent(second as usize)
            {
                first = die.sample(self.rng());
                second = die.sample(self.rng());
            } else {
                break;
            }
        }
        let mut create_edge = |from: u32, to: u32, mut edge: OriginalEdge| {
            edge.set_origin_false();
            let from_usize = from as usize;
            let to_usize = to as usize;
            let (vertex_from, vertex_to) = self.graph
                .get_2_mut(from_usize, to_usize);
            // create edge from --> to
            let (vec_to, vec_original) = vertex_from.edges_mut();
            vec_to.push(to_usize);
            vec_original.push(edge);
            // create edge to --> from
            let (vec_to, vec_original) = vertex_to.edges_mut();
            edge.swap_direction();
            vec_to.push(from_usize);
            vec_original.push(edge)
        };
        if first == original_edge.to || second == original_edge.from {
            original_edge.swap_direction();
            create_edge(second, first, original_edge)
        } else {
            create_edge(first, second, original_edge)
        }
    }
fn add_random_edge ( & mut self , mut original_edge : OriginalEdge ) { let n = self . graph . vertex_count ( ) ; let die = Uniform :: from ( 0 .. n as u32 ) ; let mut first = die . sample ( self . rng ( ) ) ; let mut second = die . sample ( self . rng ( ) ) ; loop { // no self loops // not the same edge again! // no existing edge if first == second || ( first == original_edge . from && second == original_edge . to ) || ( first == original_edge . to && second == original_edge . from ) || self . graph . get_mut_unchecked ( first as usize ) . is_adjacent ( second as usize ) { first = die . sample ( self . rng ( ) ) ; second = die . sample ( self . rng ( ) ) ; } else { break ; } } let mut create_edge = | from : u32 , to : u32 , mut edge : OriginalEdge | { edge . set_origin_false ( ) ; let from_usize = from as usize ; let to_usize = to as usize ; let ( vertex_from , vertex_to ) = self . graph . get_2_mut ( from_usize , to_usize ) ; // create edge from --> to let ( vec_to , vec_original ) = vertex_from . edges_mut ( ) ; vec_to . push ( to_usize ) ; vec_original . push ( edge ) ; // create edge to --> from let ( vec_to , vec_original ) = vertex_to . edges_mut ( ) ; edge . swap_direction ( ) ; vec_to . push ( from_usize ) ; vec_original . push ( edge ) } ; if first == original_edge . to || second == original_edge . from { original_edge . swap_direction ( ) ; create_edge ( second , first , original_edge ) } else { create_edge ( first , second , original_edge ) } }
Adding a random edge, that does not exist right now and is not "originalEdge"
Adding a random edge that does not exist right now and is not " originalEdge "
&mut self
original_edge
OriginalEdge
&mut self
original_edge
OriginalEdge