pub struct Graph {
pub node_count: usize,
pub edges: Vec<GraphEdge>,
}Expand description
Simple sparse graph with node count and edge list
Fields§
§node_count: usize§edges: Vec<GraphEdge>Implementations§
Source§impl Graph
impl Graph
Sourcepub fn new(node_count: usize) -> Self
pub fn new(node_count: usize) -> Self
Create a new empty graph with node_count nodes and no edges
Sourcepub fn add_edge(&mut self, from: usize, to: usize, weight: f32)
pub fn add_edge(&mut self, from: usize, to: usize, weight: f32)
Add a directed edge from → to with the given weight
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Total number of edges
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
BFS from node 0 to check if all nodes are reachable (i.e. graph is connected).
Treats edges as undirected for the connectivity check.
Sourcepub fn adjacency_matrix(&self) -> Vec<Vec<f32>>
pub fn adjacency_matrix(&self) -> Vec<Vec<f32>>
Build a dense adjacency matrix (node_count × node_count).
For undirected usage the matrix is symmetric (both from→to and to→from are set).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Graph
impl RefUnwindSafe for Graph
impl Send for Graph
impl Sync for Graph
impl Unpin for Graph
impl UnsafeUnpin for Graph
impl UnwindSafe for Graph
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more