pub(crate) fn largest_first(&self) -> Vec<(Vertex, u32)> {
        // https://dl.acm.org/doi/pdf/10.1145/2402.322385
        // Smallest-Last Ordering and Clustering and Graph Coloring Algorithms
        // Matula and Beck 1983

        let mut return_order = Vec::with_capacity(self.nvertices());
        let nv = self.nvertices();
        let null = std::u32::MAX;

        if nv == 0 {
            return vec![];
        }

        // The Matula and Beck algorithm is inverted here.
        //
        // The algorithm proceeds with nv stages, one for each vertex.
        // At each i-th stage of the algorithm, we maintain:
        //
        // the implicit graph H over all unexplored vertices, defined by
        //   the induced graph from the negation of `explored` as a mask over the
        //   initial graph.
        //
        // `degrees[v]` the current degree of every unexplored vertex v in H
        //
        // `prio` is a priority array, which contains the list of unexplored vertices
        // sorted in ascending order by their degree within H
        //
        // `offsets` is defined such that `prio[offsets[i]..offsets[i+1]]` is exactly
        // all vertices with degree i in H. This holds for all i from 0 to curr_max,
        // where curr_max is the maximum degree in H.
        //
        // `iprio[v]` is the inverse of the priority array holding the index at which
        // vertex `v` is located in `prio` if `v` is unexplored.

        let mut explored = vec![false; nv];
        let mut max_degree = (0..nv).map(|v| self.degree(v as Vertex)).max().unwrap_or(0) as u32;
        let mut offsets = vec![0u32; u(max_degree) + 2];
        (0..nv).for_each(|v| offsets[self.degree(v as Vertex) + 1] += 1);
        cumsum(&mut offsets);
        let mut prio = vec![null; nv];
        let mut iprio = vec![null; nv];
        let mut degrees = vec![null; nv];
        {
            let mut fill_offsets = offsets.clone();
            for v in 0..nv {
                let deg = self.degree(v as Vertex);
                prio[u(fill_offsets[deg])] = v as Vertex;
                iprio[v] = fill_offsets[deg];
                degrees[v] = d(deg);
                fill_offsets[deg] += 1;
            }
        }

        while return_order.len() < nv {
            // pop off the max vertex

            assert!(offsets[u(max_degree)] < offsets[u(max_degree) + 1]);
            let last = offsets[u(max_degree) + 1] - 1;
            let max_vertex = prio[u(last)];

            assert!(iprio[u(max_vertex)] == last);
            assert!(!explored[u(max_vertex)]);
            assert!(degrees[u(max_vertex)] == max_degree);

            iprio[u(max_vertex)] = null;
            degrees[u(max_vertex)] = null;
            prio[u(last)] = null;

            // explore the max vertex

            explored[u(max_vertex)] = true;
            return_order.push((max_vertex, max_degree));

            // reduce unexplored neighbors' degrees by 1

            let mut nbrs = 0;
            for &v in self.neighbors(max_vertex) {
                if explored[u(v)] {
                    continue;
                }

                nbrs += 1;
                assert!(max_degree != null); // no neighbors if null

                let deg = degrees[u(v)];
                let ix = iprio[u(v)];
                assert!(deg > 0); // connected to max_vertex before

                let target_ix = offsets[u(deg)];
                let target = prio[u(target_ix)];
                assert!(iprio[u(target)] == target_ix);
                assert!(!explored[u(target)]);

                // swap with target

                prio[u(target_ix)] = v;
                iprio[u(v)] = target_ix;
                degrees[u(v)] = deg - 1;

                prio[u(ix)] = target;
                iprio[u(target)] = ix;
                assert!(degrees[u(target)] == deg || target == v);

                // move the offset to match new degrees

                offsets[u(deg)] += 1;
            }
            assert!(nbrs == max_degree);

            // reduce the new current maximum degree

            offsets[u(max_degree) + 1] -= 1;
            while offsets[u(max_degree)] == offsets[u(max_degree) + 1] {
                offsets[u(max_degree) + 1] = null;
                if max_degree > 0 {
                    max_degree -= 1;
                } else {
                    max_degree = null;
                    break;
                }
            }
        }

        assert!(max_degree == null);

        return_order
    }
/// Return the largest-first ordering lf, where lf[i].0 is the vertex of maximum
/// degree in the induced subgraph over all vertices lf[i].0 to lf[lf.len() - 1].0.
///
/// In the returned ordering, the first element of the tuple is the vertex, the second
/// is its degree in the induced subgraph mentioned above.
Return the largest-first ordering lf, where lf[i].0 is the vertex of maximum
degree in the induced subgraph over all vertices lf[i].0 to lf[lf.len() - 1].0.

In the returned ordering, the first element of the tuple is the vertex, the second
is its degree in the induced subgraph mentioned above.
Return the largest - first ordering lf where lf [ i ] . 0 is the vertex of maximum degree in the induced subgraph over all vertices lf [ i ] . 0 to lf [ lf . len () - 1 ] . 0 . In the returned ordering the first element of the tuple is the vertex the second is its degree in the induced subgraph mentioned above .
pub(crate) fn largest_first(&self) -> Vec<(Vertex, u32)> {
        // https://dl.acm.org/doi/pdf/10.1145/2402.322385
        // Smallest-Last Ordering and Clustering and Graph Coloring Algorithms
        // Matula and Beck 1983
        let mut return_order = Vec::with_capacity(self.nvertices());
        let nv = self.nvertices();
        let null = std::u32::MAX;
        if nv == 0 {
            return vec![];
        }
        // The Matula and Beck algorithm is inverted here.
        //
        // The algorithm proceeds with nv stages, one for each vertex.
        // At each i-th stage of the algorithm, we maintain:
        //
        // the implicit graph H over all unexplored vertices, defined by
        //   the induced graph from the negation of `explored` as a mask over the
        //   initial graph.
        //
        // `degrees[v]` the current degree of every unexplored vertex v in H
        //
        // `prio` is a priority array, which contains the list of unexplored vertices
        // sorted in ascending order by their degree within H
        //
        // `offsets` is defined such that `prio[offsets[i]..offsets[i+1]]` is exactly
        // all vertices with degree i in H. This holds for all i from 0 to curr_max,
        // where curr_max is the maximum degree in H.
        //
        // `iprio[v]` is the inverse of the priority array holding the index at which
        // vertex `v` is located in `prio` if `v` is unexplored.
        let mut explored = vec![false; nv];
        let mut max_degree = (0..nv).map(|v| self.degree(v as Vertex)).max().unwrap_or(0) as u32;
        let mut offsets = vec![0u32; u(max_degree) + 2];
        (0..nv).for_each(|v| offsets[self.degree(v as Vertex) + 1] += 1);
        cumsum(&mut offsets);
        let mut prio = vec![null; nv];
        let mut iprio = vec![null; nv];
        let mut degrees = vec![null; nv];
        {
            let mut fill_offsets = offsets.clone();
            for v in 0..nv {
                let deg = self.degree(v as Vertex);
                prio[u(fill_offsets[deg])] = v as Vertex;
                iprio[v] = fill_offsets[deg];
                degrees[v] = d(deg);
                fill_offsets[deg] += 1;
            }
        }
        while return_order.len() < nv {
            // pop off the max vertex
            assert!(offsets[u(max_degree)] < offsets[u(max_degree) + 1]);
            let last = offsets[u(max_degree) + 1] - 1;
            let max_vertex = prio[u(last)];
            assert!(iprio[u(max_vertex)] == last);
            assert!(!explored[u(max_vertex)]);
            assert!(degrees[u(max_vertex)] == max_degree);
            iprio[u(max_vertex)] = null;
            degrees[u(max_vertex)] = null;
            prio[u(last)] = null;
            // explore the max vertex
            explored[u(max_vertex)] = true;
            return_order.push((max_vertex, max_degree));
            // reduce unexplored neighbors' degrees by 1
            let mut nbrs = 0;
            for &v in self.neighbors(max_vertex) {
                if explored[u(v)] {
                    continue;
                }
                nbrs += 1;
                assert!(max_degree != null); // no neighbors if null
                let deg = degrees[u(v)];
                let ix = iprio[u(v)];
                assert!(deg > 0); // connected to max_vertex before
                let target_ix = offsets[u(deg)];
                let target = prio[u(target_ix)];
                assert!(iprio[u(target)] == target_ix);
                assert!(!explored[u(target)]);
                // swap with target
                prio[u(target_ix)] = v;
                iprio[u(v)] = target_ix;
                degrees[u(v)] = deg - 1;
                prio[u(ix)] = target;
                iprio[u(target)] = ix;
                assert!(degrees[u(target)] == deg || target == v);
                // move the offset to match new degrees
                offsets[u(deg)] += 1;
            }
            assert!(nbrs == max_degree);
            // reduce the new current maximum degree
            offsets[u(max_degree) + 1] -= 1;
            while offsets[u(max_degree)] == offsets[u(max_degree) + 1] {
                offsets[u(max_degree) + 1] = null;
                if max_degree > 0 {
                    max_degree -= 1;
                } else {
                    max_degree = null;
                    break;
                }
            }
        }
        assert!(max_degree == null);
        return_order
    }
pub ( crate ) fn largest_first ( & self ) -> Vec < ( Vertex , u32 ) > { // https://dl.acm.org/doi/pdf/10.1145/2402.322385 // Smallest-Last Ordering and Clustering and Graph Coloring Algorithms // Matula and Beck 1983 let mut return_order = Vec :: with_capacity ( self . nvertices ( ) ) ; let nv = self . nvertices ( ) ; let null = std :: u32 :: MAX ; if nv == 0 { return vec ! [ ] ; } // The Matula and Beck algorithm is inverted here. // // The algorithm proceeds with nv stages, one for each vertex. // At each i-th stage of the algorithm, we maintain: // // the implicit graph H over all unexplored vertices, defined by //   the induced graph from the negation of `explored` as a mask over the //   initial graph. // // `degrees[v]` the current degree of every unexplored vertex v in H // // `prio` is a priority array, which contains the list of unexplored vertices // sorted in ascending order by their degree within H // // `offsets` is defined such that `prio[offsets[i]..offsets[i+1]]` is exactly // all vertices with degree i in H. This holds for all i from 0 to curr_max, // where curr_max is the maximum degree in H. // // `iprio[v]` is the inverse of the priority array holding the index at which // vertex `v` is located in `prio` if `v` is unexplored. let mut explored = vec ! [ false nv ] ; let mut max_degree = ( 0 .. nv ) . map ( | v | self . degree ( v as Vertex ) ) . max ( ) . unwrap_or ( 0 ) as u32 ; let mut offsets = vec ! [ 0u32 u ( max_degree ) 2 ] ; ( 0 .. nv ) . for_each ( | v | offsets [ self . degree ( v as Vertex ) + 1 ] += 1 ) ; cumsum ( & mut offsets ) ; let mut prio = vec ! [ null nv ] ; let mut iprio = vec ! [ null nv ] ; let mut degrees = vec ! [ null nv ] ; { let mut fill_offsets = offsets . clone ( ) ; for v in 0 .. nv { let deg = self . degree ( v as Vertex ) ; prio [ u ( fill_offsets [ deg ] ) ] = v as Vertex ; iprio [ v ] = fill_offsets [ deg ] ; degrees [ v ] = d ( deg ) ; fill_offsets [ deg ] += 1 ; } } while return_order . len ( ) < nv { // pop off the max vertex assert ! ( offsets [ u ( max_degree ) ] offsets [ u ( max_degree ) 1 ] ) ; let last = offsets [ u ( max_degree ) + 1 ] - 1 ; let max_vertex = prio [ u ( last ) ] ; assert ! ( iprio [ u ( max_vertex ) ] last ) ; assert ! ( explored [ u ( max_vertex ) ] ) ; assert ! ( degrees [ u ( max_vertex ) ] max_degree ) ; iprio [ u ( max_vertex ) ] = null ; degrees [ u ( max_vertex ) ] = null ; prio [ u ( last ) ] = null ; // explore the max vertex explored [ u ( max_vertex ) ] = true ; return_order . push ( ( max_vertex , max_degree ) ) ; // reduce unexplored neighbors' degrees by 1 let mut nbrs = 0 ; for & v in self . neighbors ( max_vertex ) { if explored [ u ( v ) ] { continue ; } nbrs += 1 ; assert ! ( max_degree null ) ; // no neighbors if null let deg = degrees [ u ( v ) ] ; let ix = iprio [ u ( v ) ] ; assert ! ( deg 0 ) ; // connected to max_vertex before let target_ix = offsets [ u ( deg ) ] ; let target = prio [ u ( target_ix ) ] ; assert ! ( iprio [ u ( target ) ] target_ix ) ; assert ! ( explored [ u ( target ) ] ) ; // swap with target prio [ u ( target_ix ) ] = v ; iprio [ u ( v ) ] = target_ix ; degrees [ u ( v ) ] = deg - 1 ; prio [ u ( ix ) ] = target ; iprio [ u ( target ) ] = ix ; assert ! ( degrees [ u ( target ) ] deg target v ) ; // move the offset to match new degrees offsets [ u ( deg ) ] += 1 ; } assert ! ( nbrs max_degree ) ; // reduce the new current maximum degree offsets [ u ( max_degree ) + 1 ] -= 1 ; while offsets [ u ( max_degree ) ] == offsets [ u ( max_degree ) + 1 ] { offsets [ u ( max_degree ) + 1 ] = null ; if max_degree > 0 { max_degree -= 1 ; } else { max_degree = null ; break ; } } } assert ! ( max_degree null ) ; return_order }
Return the largest-first ordering lf, where lf[i].0 is the vertex of maximum
degree in the induced subgraph over all vertices lf[i].0 to lf[lf.len() - 1].0.
Return the largest - first ordering lf where lf [ i ] . 0 is the vertex of maximum degree in the induced subgraph over all vertices lf [ i ] . 0 to lf [ lf . len () - 1 ] . 0 .
&self
&self