[−][src]Struct algorithms_edu::algo::graph::WeightedUndirectedAdjacencyMatrixCondensed
An adjacency matrix representing an undirected graph is symmetric with respect to the main diagonal,
i.e. g[i][j]
= g[j][i]
. Thus, only half of the values in the matrix need to be stored. In addition,
The assumption that g[i][i] = 0
works fine in most cases, so weights representing these self-pointing
edges are also not stored.
Thus a condensed matrix stores only g[i][j]
where i < j
in a vector of length ${}^{n}C_{2} = \dfrac{n(n-1)}{2}$
(n-choose-2). For example, in a graph with 4 vertices, the 6 weights in the condensed vector represents
g[0 -> 1], g[0 -> 2], g[0 -> 3], g[1 -> 2], g[1 -> 3], g[2 -> 3]
, respectively.
Implementations
impl WeightedUndirectedAdjacencyMatrixCondensed
[src]
pub fn new(node_count: usize) -> Self
[src]
pub fn from_adjacency_list(inp: &WeightedAdjacencyList) -> Self
[src]
Build a WeightedUndirectedAdjacencyMatrixCondensed
from WeightedAdjacencyList
.
The graph must be undirected. Even if the WeightedAdjacencyList
were build with
directed edges, they are treated as undirected edges.
Panics
Panics if the WeightedAdjacencyList
contains both g[i -> j]
and g[j -> i]
but
their weights differ
pub fn from_slice(inp: &[f64]) -> Self
[src]
Builds a WeightedUndirectedAdjacencyMatrixCondensed
from its inner representation.
pub fn edges(&self) -> impl Iterator<Item = (usize, usize, f64)> + '_
[src]
Iterate over all pairs of nodes (i, j)
where i < j
with the weight associated with the pair.
Each item is a tuple of 3: (i, j, weight)
.
Note that only (i, j)
but not (j, i)
is outputted.
pub fn node_count(&self) -> usize
[src]
Number of nodes (vertices) in the graph
pub fn resized(&self, new_node_count: usize) -> Self
[src]
Trait Implementations
impl Debug for WeightedUndirectedAdjacencyMatrixCondensed
[src]
impl Display for WeightedUndirectedAdjacencyMatrixCondensed
[src]
impl From<WeightedAdjacencyList> for WeightedUndirectedAdjacencyMatrixCondensed
[src]
pub fn from(inp: WeightedAdjacencyList) -> Self
[src]
impl Index<(usize, usize)> for WeightedUndirectedAdjacencyMatrixCondensed
[src]
This allows indexing into graphs represented by WeightedUndirectedAdjacencyMatrixCondensed
easier.
For example, for a graph g
, either g[(i, j)]
or g[(j, i)]
will give the weight associated with node
i
and node j
(remember the graph is undirected)
type Output = f64
The returned type after indexing.
pub fn index(&self, (i, j): (usize, usize)) -> &Self::Output
[src]
impl IndexMut<(usize, usize)> for WeightedUndirectedAdjacencyMatrixCondensed
[src]
Auto Trait Implementations
impl RefUnwindSafe for WeightedUndirectedAdjacencyMatrixCondensed
[src]
impl Send for WeightedUndirectedAdjacencyMatrixCondensed
[src]
impl Sync for WeightedUndirectedAdjacencyMatrixCondensed
[src]
impl Unpin for WeightedUndirectedAdjacencyMatrixCondensed
[src]
impl UnwindSafe for WeightedUndirectedAdjacencyMatrixCondensed
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,