Struct WeightedAdjacencyMatrix

Source
pub struct WeightedAdjacencyMatrix { /* private fields */ }
Expand description

Dense graphs, are sometimes more efficient to be represented as adjacency matrices. A WeightedAdjacencyMatrix is based on a Matrix of size n * n where n is the number of nodes (vertices) in the graph. For a WeightedAdjacencyMatrix g, g[i][j] is the weight of the edge pointing from node i to node j. By convention, for two nodes i and j that are not connected, g[i][j] = INFINITY, and each node by default has a weight of 0 to point to itself (i.e. g[i][i] = 0).

Implementations§

Source§

impl WeightedAdjacencyMatrix

Source

pub fn with_size(n: usize) -> Self

Source

pub fn node_count(&self) -> usize

Number of nodes in the graph.

Source

pub fn from_adjacency_list(inp: &WeightedAdjacencyList) -> Self

Converts a WeightedAdjacencyList to WeightedAdjacencyMatrix

Source

pub fn from_inner(matrix: Vec<Vec<f64>>) -> Self

Builds a WeightedAdjacencyMatrix from its underlying representation.

Trait Implementations§

Source§

impl Display for WeightedAdjacencyMatrix

Pretty-prints a small graph represented by an adjacency matrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Vec<Vec<f64>>> for WeightedAdjacencyMatrix

For convinience

Source§

fn from(matrix: Vec<Vec<f64>>) -> Self

Converts to this type from the input type.
Source§

impl From<WeightedAdjacencyList> for WeightedAdjacencyMatrix

For convinience

Source§

fn from(inp: WeightedAdjacencyList) -> Self

Converts to this type from the input type.
Source§

impl Index<usize> for WeightedAdjacencyMatrix

This allows us to access the weight of edge i -> j in graph g by g[i][j] rather than g.inner[i][j]

Source§

type Output = Vec<f64>

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.