pub struct SSSPAlgorithm {
pub graph: SSSPGraph,
}Expand description
A library for Single Source Shortest Path (SSSP) algorithms in graphs.
This crate provides an implementation of SSSP using a bounded-memory shortest path algorithm. It is designed for efficiency on large graphs with constraints on memory and computation.
Fields§
§graph: SSSPGraphThe underlying graph structure.
Implementations§
Source§impl SSSPAlgorithm
impl SSSPAlgorithm
Sourcepub fn run(&self, source: usize) -> HashMap<usize, f64>
pub fn run(&self, source: usize) -> HashMap<usize, f64>
Runs the SSSP algorithm from the given source node.
Returns a HashMap where keys are node indices and values are the shortest distances from the source. If the source is invalid (out of bounds), returns an empty HashMap.
§Arguments
source- The index of the source node.
§Examples
use sssp_lib::SSSPAlgorithm;
let mut algo = SSSPAlgorithm::new(3);
algo.graph.add_edge(0, 1, 1.0);
algo.graph.add_edge(1, 2, 2.0);
let dists = algo.run(0);
assert_eq!(dists.get(&2), Some(&3.0));Sourcepub fn generate_large_random(n: usize, edges_per_node: usize) -> Self
pub fn generate_large_random(n: usize, edges_per_node: usize) -> Self
Generates a large random graph for performance testing.
Creates a graph with n nodes, where each node has approximately edges_per_node outgoing edges.
Edge weights are random floats between 0.0 and 10.0.
§Arguments
n- The number of nodes.edges_per_node- The average number of outgoing edges per node.
§Examples
use sssp_lib::SSSPAlgorithm;
let algo = SSSPAlgorithm::generate_large_random(100, 5);Auto Trait Implementations§
impl Freeze for SSSPAlgorithm
impl RefUnwindSafe for SSSPAlgorithm
impl Send for SSSPAlgorithm
impl Sync for SSSPAlgorithm
impl Unpin for SSSPAlgorithm
impl UnwindSafe for SSSPAlgorithm
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more