SSSPAlgorithm

Struct SSSPAlgorithm 

Source
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: SSSPGraph

The underlying graph structure.

Implementations§

Source§

impl SSSPAlgorithm

Source

pub fn new(n: usize) -> Self

Creates a new SSSPAlgorithm instance with an empty graph of n nodes.

§Arguments
  • n - The number of nodes in the graph.
§Examples
use sssp_lib::SSSPAlgorithm;

let algo = SSSPAlgorithm::new(10);
Source

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));
Source

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§

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> 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<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.