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:
Re-exports§
pub use petgraph;
Modules§
- Module for centrality algorithms.
- Module for coloring algorithms.
- Module for connectivity and cut algorithms.
- Module for algorithms that work on DAGs.
- This module contains the
DistanceMap
trait which is used inshortest_path
. - This module contains common error types and trait impls.
- This module contains generator functions for building graphs
- This module defines traits that extend PetGraph’s graph data structures.
- Module for maximum weight matching algorithms.
- Module for planar graphs.
- Module for shortest path algorithms.
- Module for swapping tokens
- Module for graph traversal algorithms.
Type Aliases§
- A convenient type alias that by default assumes no error can happen.