pub struct AdjacencyList<T, M> { /* private fields */ }Expand description
Represents a pointer bag design for an adjacency list graph representation.
Nodes are identified by stable Vec indices for the lifetime of the graph.
Implementations§
Source§impl<T, M> AdjacencyList<T, M>where
T: PartialEq,
impl<T, M> AdjacencyList<T, M>where
T: PartialEq,
Sourcepub fn add_node(&mut self, data: T) -> usize
pub fn add_node(&mut self, data: T) -> usize
Creates and adds a new vertex for the specified data
Sourcepub fn add_directed_link(
&mut self,
origin: usize,
destination: usize,
metadata: Option<M>,
)
pub fn add_directed_link( &mut self, origin: usize, destination: usize, metadata: Option<M>, )
Creates and adds a new edge from an originating vertex to a
destination vertex with an optional metadata element M such
as a weight. Origin and destination arguments are positional
for directed graphs.
Sourcepub fn add_undirected_link(
&mut self,
first: usize,
second: usize,
metadata: Option<M>,
)where
M: Clone,
pub fn add_undirected_link(
&mut self,
first: usize,
second: usize,
metadata: Option<M>,
)where
M: Clone,
Creates and adds a new undirected edge from one node to another
node with an optional metadata element M such
as a weight.
Sourcepub fn get_node(&self, index: usize) -> Option<&Node<T, M>>
pub fn get_node(&self, index: usize) -> Option<&Node<T, M>>
Returns a reference to a node for a given index.
Sourcepub fn nodes(&self) -> &Vec<Node<T, M>>
pub fn nodes(&self) -> &Vec<Node<T, M>>
Returns an iterable collection over all vertices in the graph
Sourcepub fn nodes_iter(&self) -> impl Iterator<Item = &Node<T, M>>
pub fn nodes_iter(&self) -> impl Iterator<Item = &Node<T, M>>
Returns an iterator over all vertices in the graph
pub fn out_links(&self, index: usize) -> &[Link<M>]
Sourcepub fn out_links_iter(&self, index: usize) -> impl Iterator<Item = &Link<M>>
pub fn out_links_iter(&self, index: usize) -> impl Iterator<Item = &Link<M>>
Returns an iterator over all outgoing links for a given node
Sourcepub fn in_links(&self, index: usize) -> Vec<&Link<M>>
pub fn in_links(&self, index: usize) -> Vec<&Link<M>>
Returns an iterator over incoming links from a given node
Sourcepub fn in_links_iter(
&self,
index: usize,
) -> impl Iterator<Item = (&Node<T, M>, &Link<M>)>
pub fn in_links_iter( &self, index: usize, ) -> impl Iterator<Item = (&Node<T, M>, &Link<M>)>
Returns an iterator over all incoming links to a given node
Sourcepub fn links(&self) -> Vec<(&Node<T, M>, &Link<M>)>
pub fn links(&self) -> Vec<(&Node<T, M>, &Link<M>)>
Returns an iteratable collection over all links in the graph as { (u, (u → v)) | u ∈ V, (u → v) ∈ Adj[u] }
Sourcepub fn links_iter(&self) -> impl Iterator<Item = (&Node<T, M>, &Link<M>)>
pub fn links_iter(&self) -> impl Iterator<Item = (&Node<T, M>, &Link<M>)>
Returns an iterator over all links in the graph