pub fn connect(&mut self, a: usize, b: usize) {
        let a_root = self.root(a);
        let b_root = self.root(b);
        if a_root == b_root {
            // already connected
            return;
        }
        // balance by linking root of smaller tree to root of larger tree
        if self.sizes[a_root] < self.sizes[b_root] {
            self.nodes[a_root] = b_root;
            self.sizes[b_root] += self.sizes[a_root];
        } else {
            self.nodes[b_root] = a_root;
            self.sizes[a_root] += self.sizes[b_root];
        }
    }
/// Connects the two given nodes.
/// 
/// # Arguments
/// * `a` ID of the first node.
/// * `b` ID of the second node.
/// 
/// # Example
/// ```
/// let mut graph = wuf::Graph::new(10);
/// let node1 = 0;
/// let node2 = 1;
/// graph.connect(node1, node2);
/// ```
Connects the two given nodes.
Connects the two given nodes .
pub fn connect(&mut self, a: usize, b: usize) {
        let a_root = self.root(a);
        let b_root = self.root(b);
        if a_root == b_root {
            // already connected
            return;
        }
        // balance by linking root of smaller tree to root of larger tree
        if self.sizes[a_root] < self.sizes[b_root] {
            self.nodes[a_root] = b_root;
            self.sizes[b_root] += self.sizes[a_root];
        } else {
            self.nodes[b_root] = a_root;
            self.sizes[a_root] += self.sizes[b_root];
        }
    }
pub fn connect ( & mut self , a : usize , b : usize ) { let a_root = self . root ( a ) ; let b_root = self . root ( b ) ; if a_root == b_root { // already connected return ; } // balance by linking root of smaller tree to root of larger tree if self . sizes [ a_root ] < self . sizes [ b_root ] { self . nodes [ a_root ] = b_root ; self . sizes [ b_root ] += self . sizes [ a_root ] ; } else { self . nodes [ b_root ] = a_root ; self . sizes [ a_root ] += self . sizes [ b_root ] ; } }
Connects the two given nodes.
Connects the two given nodes .
&mut self
a
usize
b
usize
&mut self
a
usize
b
usize
example
None