pub fn relabel(g: &mut Graph) {
    debug_assert!((0..g.size())
        .map(|i| g.neighbors(i).map(|j| g.bonds().get(i, j)).sum())
        .all(|x: u8| x < 5));

    // Contains a new name for every node.
    let mut names: Vec<Name> = Vec::with_capacity(g.size());

    // Contains an index of the names in sorted order.
    let mut name_ids: BTreeSet<Name> = BTreeSet::new();

    let mut compressed_labels = BTreeSet::new();

    // relabel all the nodes
    for i in 0..g.size() {
        // The new name for a node is a list of its neighbors.
        // For that, we iterate through all of its adjacent nodes
        // and note the node label as well as the amount of edges between the node and its neighbor.
        let mut name: [(u8, usize); 4] = [(0, 0); 4];

        compressed_labels.insert(g.atoms()[i]);

        for (idx, p) in g
            .neighbors(i as usize)
            .map(|j| (*g.bonds().get(i as usize, j), g.atoms()[j]))
            .enumerate()
            .take(4)
        {
            name[idx] = p;
        }

        // The adjacent nodes are sorted by node label and number of bonds.
        name.sort_unstable();

        // Insert into arrays.
        names.push(name);
        name_ids.insert(name);
    }

    // assign ids to the names, where the lexicographically smallest name has the smallest id.
    let name_ids: BTreeMap<Name, usize> = name_ids
        .into_iter()
        .enumerate()
        .map(|(name_id, name)| (name, name_id))
        .collect();

    let label_ids: BTreeMap<usize, usize> = compressed_labels
        .into_iter()
        .enumerate()
        .map(|(new_label, label)| (label, new_label))
        .collect();

    let chunk = name_ids.len() + 2;
    for (i, a) in g.atoms_mut().iter_mut().enumerate() {
        let new_label = label_ids[a];
        let b = new_label * chunk + name_ids[&names[i]];
        // println!("atom {}: {} + {} = {}", i, a, atoms2[i], b);
        *a = b;
    }
}
/// Relabels the graph according to its immediate neighbors.
Relabels the graph according to its immediate neighbors.
Relabels the graph according to its immediate neighbors .
pub fn relabel(g: &mut Graph) {
    debug_assert!((0..g.size())
        .map(|i| g.neighbors(i).map(|j| g.bonds().get(i, j)).sum())
        .all(|x: u8| x < 5));
    // Contains a new name for every node.
    let mut names: Vec<Name> = Vec::with_capacity(g.size());
    // Contains an index of the names in sorted order.
    let mut name_ids: BTreeSet<Name> = BTreeSet::new();
    let mut compressed_labels = BTreeSet::new();
    // relabel all the nodes
    for i in 0..g.size() {
        // The new name for a node is a list of its neighbors.
        // For that, we iterate through all of its adjacent nodes
        // and note the node label as well as the amount of edges between the node and its neighbor.
        let mut name: [(u8, usize); 4] = [(0, 0); 4];
        compressed_labels.insert(g.atoms()[i]);
        for (idx, p) in g
            .neighbors(i as usize)
            .map(|j| (*g.bonds().get(i as usize, j), g.atoms()[j]))
            .enumerate()
            .take(4)
        {
            name[idx] = p;
        }
        // The adjacent nodes are sorted by node label and number of bonds.
        name.sort_unstable();
        // Insert into arrays.
        names.push(name);
        name_ids.insert(name);
    }
    // assign ids to the names, where the lexicographically smallest name has the smallest id.
    let name_ids: BTreeMap<Name, usize> = name_ids
        .into_iter()
        .enumerate()
        .map(|(name_id, name)| (name, name_id))
        .collect();
    let label_ids: BTreeMap<usize, usize> = compressed_labels
        .into_iter()
        .enumerate()
        .map(|(new_label, label)| (label, new_label))
        .collect();
    let chunk = name_ids.len() + 2;
    for (i, a) in g.atoms_mut().iter_mut().enumerate() {
        let new_label = label_ids[a];
        let b = new_label * chunk + name_ids[&names[i]];
        // println!("atom {}: {} + {} = {}", i, a, atoms2[i], b);
        *a = b;
    }
}
pub fn relabel ( g : & mut Graph ) { debug_assert ! ( ( 0 g size ( ) ) map ( i g neighbors ( i ) map ( j g bonds ( ) get ( i j ) ) sum ( ) ) all ( x u8 x 5 ) ) ; // Contains a new name for every node. let mut names : Vec < Name > = Vec :: with_capacity ( g . size ( ) ) ; // Contains an index of the names in sorted order. let mut name_ids : BTreeSet < Name > = BTreeSet :: new ( ) ; let mut compressed_labels = BTreeSet :: new ( ) ; // relabel all the nodes for i in 0 .. g . size ( ) { // The new name for a node is a list of its neighbors. // For that, we iterate through all of its adjacent nodes // and note the node label as well as the amount of edges between the node and its neighbor. let mut name : [ ( u8 , usize ) ; 4 ] = [ ( 0 , 0 ) ; 4 ] ; compressed_labels . insert ( g . atoms ( ) [ i ] ) ; for ( idx , p ) in g . neighbors ( i as usize ) . map ( | j | ( * g . bonds ( ) . get ( i as usize , j ) , g . atoms ( ) [ j ] ) ) . enumerate ( ) . take ( 4 ) { name [ idx ] = p ; } // The adjacent nodes are sorted by node label and number of bonds. name . sort_unstable ( ) ; // Insert into arrays. names . push ( name ) ; name_ids . insert ( name ) ; } // assign ids to the names, where the lexicographically smallest name has the smallest id. let name_ids : BTreeMap < Name , usize > = name_ids . into_iter ( ) . enumerate ( ) . map ( | ( name_id , name ) | ( name , name_id ) ) . collect ( ) ; let label_ids : BTreeMap < usize , usize > = compressed_labels . into_iter ( ) . enumerate ( ) . map ( | ( new_label , label ) | ( label , new_label ) ) . collect ( ) ; let chunk = name_ids . len ( ) + 2 ; for ( i , a ) in g . atoms_mut ( ) . iter_mut ( ) . enumerate ( ) { let new_label = label_ids [ a ] ; let b = new_label * chunk + name_ids [ & names [ i ] ] ; // println!("atom {}: {} + {} = {}", i, a, atoms2[i], b); * a = b ; } }
Relabels the graph according to its immediate neighbors.
Relabels the graph according to its immediate neighbors .
g
&mut Graph