[−][src]Struct algorithms_edu::algo::graph::WeightedAdjacencyList
A graph represented by a weighted adjacency list.
Under the hood, a weighted adjacency list is a Vec
of Vec
of Edge
s.
For an adjacency list g
, g[i]
is a Vec
of edges pointing from i
to other nodes (vertices).
Thus, the number of nodes is implied by the len
of the (outer) Vec
.
For each node i
that do not have outgoing edges, g[i]
is an empty vector.
Implementations
impl WeightedAdjacencyList
[src]
impl WeightedAdjacencyList
[src]
pub fn dfs(&self, start: usize) -> usize
[src]
Perform a depth first search on a graph with n nodes from a starting point to count the number of nodes in a given component.
In this particular implementation we just increment a counter each time we visit a new node. This, by itself, is not of much use, but you'll soon see that many other advanced algorithms are based on this DFS prototype.
impl WeightedAdjacencyList
[src]
impl WeightedAdjacencyList
[src]
impl WeightedAdjacencyList
[src]
pub fn bellman_ford(&self, start: usize) -> Vec<f64>
[src]
impl WeightedAdjacencyList
[src]
impl WeightedAdjacencyList
[src]
pub fn toposort(&self) -> Vec<usize>
[src]
pub fn toposort_khan(&self) -> Vec<usize>
[src]
Imagine building a program with dependencies
pub fn dag_shortest_path(&self, start: usize) -> Vec<f64>
[src]
impl WeightedAdjacencyList
[src]
pub fn with_size(n: usize) -> Self
[src]
Initialize an empty adjacency list that can hold up to n nodes.
pub fn is_empty(&self) -> bool
[src]
Is the graph devoid of vertices?
pub fn add_directed_edge(&mut self, u: usize, v: usize, weight: f64)
[src]
Add a directed edge from node u
to node v
with weight weight
.
pub fn add_undirected_edge(&mut self, u: usize, v: usize, weight: f64)
[src]
Add an undirected edge between nodes u
and v
.
pub fn new_directed(size: usize, edges: &[(usize, usize, f64)]) -> Self
[src]
pub fn new_undirected(size: usize, edges: &[(usize, usize, f64)]) -> Self
[src]
pub fn new_directed_unweighted(size: usize, edges: &[[usize; 2]]) -> Self
[src]
pub fn new_undirected_unweighted(size: usize, edges: &[[usize; 2]]) -> Self
[src]
pub fn edges(&self) -> impl Iterator<Item = (usize, usize, f64)> + '_
[src]
Iterates over all edges in the gragh.
Each item is a tuples of 3: (from, to, weight)
pub fn edge_count(&self) -> usize
[src]
Number of edges in the graph
pub fn nodes(&self) -> impl Iterator<Item = (usize, &Vec<Edge>)>
[src]
Iterates over all nodes in the graph.
Each item is a tuple of the node id and a Vec
of all its outgoing edges
pub fn node_count(&self) -> usize
[src]
Number of nodes (vertices) in the graph
Trait Implementations
impl Debug for WeightedAdjacencyList
[src]
impl Display for WeightedAdjacencyList
[src]
Pretty-prints a small graph represented by a weighted adjacency list
The graph is first converted to a WeightedAdjacencyMatrix
before being printed
impl From<WeightedAdjacencyList> for WeightedAdjacencyMatrix
[src]
For convinience
pub fn from(inp: WeightedAdjacencyList) -> Self
[src]
impl From<WeightedAdjacencyList> for WeightedUndirectedAdjacencyMatrixCondensed
[src]
pub fn from(inp: WeightedAdjacencyList) -> Self
[src]
impl Index<usize> for WeightedAdjacencyList
[src]
Allows the outgoing edges of a node to be accessed easily.
Auto Trait Implementations
impl RefUnwindSafe for WeightedAdjacencyList
[src]
impl Send for WeightedAdjacencyList
[src]
impl Sync for WeightedAdjacencyList
[src]
impl Unpin for WeightedAdjacencyList
[src]
impl UnwindSafe for WeightedAdjacencyList
[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>,