Crate rustworkx_core

source ·
Expand description

§rustworkx-core

rustworkx-core is a graph algorithm crate built on top of petgraph. It offers a set of functions that are used in the larger rustworkx project but implemented in a generic manner for use by downstream rust projects.

§Usage

First add this crate to your Cargo.toml:

[dependencies]
rustworkx-core = "0.11"

Then in your code, it may be used something like this:

use rustworkx_core::petgraph;
use rustworkx_core::centrality::betweenness_centrality;

let g = petgraph::graph::UnGraph::<i32, ()>::from_edges(&[
    (1, 2), (2, 3), (3, 4), (1, 4)
]);
// Calculate the betweenness centrality
let output = betweenness_centrality(&g, false, false, 200);
assert_eq!(
    vec![Some(0.0), Some(0.5), Some(0.5), Some(0.5), Some(0.5)],
    output
);

§Algorithm Modules

The crate provides the following graph algorithm modules

§Graph Extensions

The crate also provides traits which extend petgraph types with additional methods, when imported.

For example, the contract_nodes method becomes available for applicable graph types when the following trait is imported:

use petgraph::prelude::*;
use rustworkx_core::graph_ext::ContractNodesDirected;

let mut dag: StableDiGraph<char, usize> = StableDiGraph::default();
let m = dag.contract_nodes([], 'm', true).unwrap();

See the documentation of graph_ext for a full listing of the available extensions and their compatibility with petgraph types.

§Release Notes

The release notes for rustworkx-core are included as part of the rustworkx documentation which is hosted at:

https://www.rustworkx.org/release_notes.html

Re-exports§

Modules§

Type Aliases§

  • A convenient type alias that by default assumes no error can happen.