pub struct AdjacencyMatrix<'a>(pub &'a [Vec<f64>]);Expand description
Row-major adjacency-matrix adapter.
Wraps an existing &[Vec<f64>] where matrix[i][j] is the weight of edge
i -> j and 0.0 means no edge. Suitable for small or dense graphs where
a matrix is the natural representation; for sparse graphs prefer an
adjacency-list adapter like PetgraphRef.
§Example
use graphops::{AdjacencyMatrix, Graph};
// 3-node directed cycle: 0 -> 1 -> 2 -> 0
let m = vec![
vec![0.0, 1.0, 0.0],
vec![0.0, 0.0, 1.0],
vec![1.0, 0.0, 0.0],
];
let g = AdjacencyMatrix(&m);
assert_eq!(g.node_count(), 3);
assert_eq!(g.neighbors(0), vec![1]);Tuple Fields§
§0: &'a [Vec<f64>]Trait Implementations§
Source§impl<'a> Graph for AdjacencyMatrix<'a>
impl<'a> Graph for AdjacencyMatrix<'a>
Source§fn node_count(&self) -> usize
fn node_count(&self) -> usize
Number of nodes in the graph. Must be stable across calls.
Source§fn out_degree(&self, node: usize) -> usize
fn out_degree(&self, node: usize) -> usize
Number of out-neighbors of
node. Default calls neighbors(node).len();
override if out-degree is cheaper to compute without materializing the list.Source§impl<'a> WeightedGraph for AdjacencyMatrix<'a>
impl<'a> WeightedGraph for AdjacencyMatrix<'a>
Auto Trait Implementations§
impl<'a> Freeze for AdjacencyMatrix<'a>
impl<'a> RefUnwindSafe for AdjacencyMatrix<'a>
impl<'a> Send for AdjacencyMatrix<'a>
impl<'a> Sync for AdjacencyMatrix<'a>
impl<'a> Unpin for AdjacencyMatrix<'a>
impl<'a> UnsafeUnpin for AdjacencyMatrix<'a>
impl<'a> UnwindSafe for AdjacencyMatrix<'a>
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> 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