Skip to main content

Sccs

Struct Sccs 

Source
pub struct Sccs { /* private fields */ }
Expand description

The SCCs (strongly connected components) of a graph, as components::sccs_of returns them.

It is a NodePartition whose groups are the SCCs, numbered by SCC ID 0..scc_count(). scc_of returns the SCC of a node and nodes_of the nodes of an SCC. contains_cycle distinguishes the SCCs with a cycle from those of a single node without one. condense returns the DAG (directed acyclic graph) of the SCCs. Java’s Sccs extends NodePartition; this type dereferences to its NodePartition instead. So every method of a partition applies, and a &Sccs is accepted where a &NodePartition is.

Every node is in exactly one SCC; a node that lies on no cycle is an SCC of its own. SCC IDs are in reverse topological order: every edge between two SCCs goes from the higher SCC ID to the lower one, so SCC 0 has no edges to other SCCs. The nodes of each SCC are in ascending order. Here, dependencies are the dependencies between the packages of a program, and names holds the names of the packages. The example groups the packages by SCC, in the order of the SCC IDs. In this order, each package comes after the packages it uses, and the packages that use each other come together:

// The SCCs in reverse topological order, each as the names of its packages.
let sccs = components::sccs_of(&dependencies);
let build_order: Vec<Vec<&str>> = (0..sccs.scc_count())
    .map(|scc| {
        sccs.nodes_of(scc)
            .iter()
            .map(|&node| names[node as usize])
            .collect()
    })
    .collect();
// build_order: [["util"], ["cli"], ["json"], ["model", "storage"], ["service"],
//               ["ui"], ["app"]]

Instances are immutable and safe to share between threads (Send and Sync).

Memory: 4 x (2 x node_count + scc_count) bytes; the graph is shared, not copied.

Implementations§

Source§

impl Sccs

Source

pub fn scc_of(&self, node: u32) -> u32

Returns the SCC ID of node. Equivalent to get(node), which is never None here.

Time: O(1).

§Panics

With an index out of bounds message if node is not in 0..node_count().

Source

pub fn scc_count(&self) -> u32

Returns the number of SCCs. Equivalent to group_count.

Time: O(1).

Source

pub fn contains_cycle(&self, scc: u32) -> bool

Returns whether SCC scc contains a cycle: whether it has more than one node, or a single node with a self-loop.

Time: O(1) for an SCC of more than one node, O(log out_degree(v)) for an SCC of a single node v.

§Panics

With an index out of bounds message if scc is not in 0..scc_count().

Source

pub fn is_strongly_connected(&self) -> bool

Returns whether the graph is strongly connected: whether it has at most one SCC. Equivalent to scc_count() <= 1.

A graph without nodes counts as strongly connected.

Time: O(1).

Source

pub fn as_partition(&self) -> &NodePartition

Returns the SCCs as a plain NodePartition; the same as dereferencing.

Time: O(1).

Source

pub fn into_partition(self) -> NodePartition

Returns the SCCs as a plain NodePartition, handed over.

Time: O(1).

Source§

impl Sccs

Source

pub fn get(&self, id: u32) -> Option<u32>

Returns the index that id maps to, or None if id is not mapped - Java’s -1.

In a partition, it is the group of id.

Time: O(1).

§Panics

With an index out of bounds message if id is not in 0..index_count().

Source

pub fn is_mapped(&self, id: u32) -> bool

Returns whether id is mapped. Equivalent to get(id).is_some().

Time: O(1).

§Panics

With an index out of bounds message if id is not in 0..index_count().

Source

pub fn is_partial(&self) -> bool

Returns whether some index is not mapped. Equivalent to mapped_count() < index_count().

Time: O(1).

Source

pub fn mapped_count(&self) -> u32

Returns the number of indices that are mapped; in a partition, the number of indices that belong to a group.

Time: O(1).

Source

pub fn index_count(&self) -> u32

Returns the number of indices this mapping maps from, mapped or not.

It is the length of the arrays that gather returns and that reduce takes.

Time: O(1).

Methods from Deref<Target = NodePartition>§

Source

pub fn node_count(&self) -> u32

Returns the number of nodes of the partitioned graph, in a group or not. Equivalent to index_count.

Time: O(1).

Source

pub fn nodes_of(&self, group: u32) -> SortedIntView<'_>

Returns the nodes in group group, in ascending order. Equivalent to indices_of(group).

The result is a view of this partition’s own array, not a copy.

Time: O(1).

§Panics

With an index out of bounds message if group is not in 0..group_count().

Source

pub fn condense(&self) -> Graph

Returns the condensed graph, with a node for each group and an edge between two groups wherever an edge of the partitioned graph runs between them.

The node IDs of the condensed graph are the group IDs. It has the edge g -> h if a node in group g has an out-node in group h and g != h. Edges within a group and edges from or to a node in no group are left out. The edges from one group to another become a single edge. graphs::edge_partition tells which edges are behind each edge of the condensed graph. For an Sccs, the condensed graph is acyclic.

The condensed graph is built anew on every call, not cached: keep the result to use it more than once.

Time: O(node_count + edge_count + group_count), plus O(d log d) for each group with d out-nodes in the result. Memory: 4 x (group_count + condensed_edge_count) bytes for the result, where condensed_edge_count is its edge count; while it runs, 1 bit per group and up to 6 x condensed_edge_count bytes more.

Source

pub fn group_count(&self) -> u32

Returns the number of groups.

Time: O(1).

Source

pub fn indices_of(&self, group: u32) -> SortedIntView<'_>

Returns the indices in group group, in ascending order.

The result is a view of this partition’s own array, not a copy.

Time: O(1).

§Panics

With an index out of bounds message if group is not in 0..group_count().

Source

pub fn size_of(&self, group: u32) -> u32

Returns the number of indices in group group.

Time: O(1).

§Panics

With an index out of bounds message if group is not in 0..group_count().

Source

pub fn reduce<T: Copy>( &self, values: &[T], identity: T, combine: impl FnMut(T, T) -> T, ) -> Vec<T>

Returns one value per group, combined from the values of its indices.

For each group, starts from identity and combines the result so far with the value of each index in the group, in ascending order of the indices. A group without indices gets identity, and the values of indices in no group are left out. The result is indexed by group ID. combine is called with the result so far and the value of the next index, and returns the two combined. This is one generic function for every Copy type; Java has one per primitive type. reduce_into does the same for other types.

Time: O(index_count + group_count). Memory: size_of::<T>() x group_count bytes for the result.

§Panics

With an invalid argument message if values.len() != index_count().

Source

pub fn reduce_into<T: Clone>( &self, values: &[T], group_values: &mut [T], combine: impl FnMut(T, &T) -> T, )

Writes one value per group into group_values, combined from the values of the indices of that group. This is the form of reduce for values that are not Copy - Java’s overload reduce(T[], T[], BinaryOperator).

For each group, starts from a clone of the value of its first index and combines the result so far with the value of each further index, in ascending order of the indices. That takes one clone per group; Java folds references. combine is called with the result so far and a reference to the value of the next index, and returns the two combined. A group without indices keeps its entry in group_values, and the values of indices in no group are left out. The borrow rules guarantee that the two slices are not the same; Java checks this.

Time: O(index_count + group_count).

§Panics

With an invalid argument message if values.len() != index_count() or group_values.len() != group_count().

Source

pub fn get(&self, id: u32) -> Option<u32>

Returns the index that id maps to, or None if id is not mapped - Java’s -1.

In a partition, it is the group of id.

Time: O(1).

§Panics

With an index out of bounds message if id is not in 0..index_count().

Source

pub fn is_mapped(&self, id: u32) -> bool

Returns whether id is mapped. Equivalent to get(id).is_some().

Time: O(1).

§Panics

With an index out of bounds message if id is not in 0..index_count().

Source

pub fn is_partial(&self) -> bool

Returns whether some index is not mapped. Equivalent to mapped_count() < index_count().

Time: O(1).

Source

pub fn mapped_count(&self) -> u32

Returns the number of indices that are mapped; in a partition, the number of indices that belong to a group.

Time: O(1).

Source

pub fn index_count(&self) -> u32

Returns the number of indices this mapping maps from, mapped or not.

It is the length of the arrays that gather returns and that reduce takes.

Time: O(1).

Trait Implementations§

Source§

impl AsRef<NodePartition> for Sccs

Source§

fn as_ref(&self) -> &NodePartition

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Sccs

Source§

fn clone(&self) -> Sccs

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Sccs

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for Sccs

Source§

type Target = NodePartition

The resulting type after dereferencing.
Source§

fn deref(&self) -> &NodePartition

Dereferences the value.
Source§

impl IndexMapping for Sccs

Source§

fn get(&self, id: u32) -> Option<u32>

Returns the index that id maps to, or None if id is not mapped - Java’s -1. Read more
Source§

fn is_mapped(&self, id: u32) -> bool

Returns whether id is mapped. Equivalent to get(id).is_some(). Read more
Source§

fn is_partial(&self) -> bool

Returns whether some index is not mapped. Equivalent to mapped_count() < index_count(). Read more
Source§

fn mapped_count(&self) -> u32

Returns the number of indices that are mapped; in a partition, the number of indices that belong to a group. Read more
Source§

fn index_count(&self) -> u32

Returns the number of indices this mapping maps from, mapped or not. Read more
Source§

impl IndexPartition for Sccs

Source§

fn group_count(&self) -> u32

Returns the number of groups. Read more
Source§

fn indices_of(&self, group: u32) -> SortedIntView<'_>

Returns the indices in group group, in ascending order. Read more
Source§

fn size_of(&self, group: u32) -> u32

Returns the number of indices in group group. Read more
Source§

fn reduce<T: Copy>( &self, values: &[T], identity: T, combine: impl FnMut(T, T) -> T, ) -> Vec<T>

Returns one value per group, combined from the values of its indices. Read more
Source§

fn reduce_into<T: Clone>( &self, values: &[T], group_values: &mut [T], combine: impl FnMut(T, &T) -> T, )

Writes one value per group into group_values, combined from the values of the indices of that group. This is the form of reduce for values that are not Copy - Java’s overload reduce(T[], T[], BinaryOperator). Read more

Auto Trait Implementations§

§

impl Freeze for Sccs

§

impl RefUnwindSafe for Sccs

§

impl Send for Sccs

§

impl Sync for Sccs

§

impl Unpin for Sccs

§

impl UnsafeUnpin for Sccs

§

impl UnwindSafe for Sccs

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.