Struct petgraph::adj::List [−][src]
An adjacency list with labeled edges.
Can be interpreted as a directed graph with unweighted nodes.
This is the most simple adjacency list you can imagine. Graph, in contrast,
maintains both the list of successors and predecessors for each node,
which is a different trade-off.
Allows parallel edges and self-loops.
This data structure is append-only (except for [clear]), so indices
returned at some point for a given graph will stay valid with this same
graph until it is dropped or [clear] is called.
Space consumption: O(|E|).
Implementations
impl<E, Ix: IndexType> List<E, Ix>[src]
pub fn new() -> List<E, Ix>[src]
Creates a new, empty adjacency list.
pub fn with_capacity(nodes: usize) -> List<E, Ix>[src]
Creates a new, empty adjacency list tailored for nodes nodes.
pub fn clear(&mut self)[src]
Removes all nodes and edges from the list.
pub fn edge_count(&self) -> usize[src]
Returns the number of edges in the list
Computes in O(|V|) time.
pub fn add_node(&mut self) -> NodeIndex<Ix>[src]
Adds a new node to the list. This allocates a new Vec and then should
run in amortized O(1) time.
pub fn add_node_with_capacity(&mut self, successors: usize) -> NodeIndex<Ix>[src]
Adds a new node to the list. This allocates a new Vec and then should
run in amortized O(1) time.
pub fn add_node_from_edges<I: Iterator<Item = (NodeIndex<Ix>, E)>>(
&mut self,
edges: I
) -> NodeIndex<Ix>[src]
&mut self,
edges: I
) -> NodeIndex<Ix>
Adds a new node to the list by giving its list of successors and the corresponding weigths.
pub fn add_edge(
&mut self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>,
weight: E
) -> EdgeIndex<Ix>[src]
&mut self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>,
weight: E
) -> EdgeIndex<Ix>
Add an edge from a to b to the graph, with its associated
data weight.
Return the index of the new edge.
Computes in O(1) time.
Panics if the source node does not exist.
Note: List allows adding parallel (“duplicate”) edges. If you want
to avoid this, use .update_edge(a, b, weight) instead.
pub fn edge_endpoints(
&self,
e: EdgeIndex<Ix>
) -> Option<(NodeIndex<Ix>, NodeIndex<Ix>)>[src]
&self,
e: EdgeIndex<Ix>
) -> Option<(NodeIndex<Ix>, NodeIndex<Ix>)>
Accesses the source and target of edge e
Computes in O(1)
pub fn edge_indices_from(&self, a: NodeIndex<Ix>) -> OutgoingEdgeIndices<Ix>ⓘNotable traits for OutgoingEdgeIndices<Ix>
impl<Ix> Iterator for OutgoingEdgeIndices<Ix> where
Ix: IndexType, type Item = EdgeIndex<Ix>;[src]
Notable traits for OutgoingEdgeIndices<Ix>
impl<Ix> Iterator for OutgoingEdgeIndices<Ix> where
Ix: IndexType, type Item = EdgeIndex<Ix>;pub fn contains_edge(&self, a: NodeIndex<Ix>, b: NodeIndex<Ix>) -> bool[src]
Lookups whether there is an edge from a to b.
Computes in O(e') time, where e' is the number of successors of a.
pub fn find_edge(
&self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>
) -> Option<EdgeIndex<Ix>>[src]
&self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>
) -> Option<EdgeIndex<Ix>>
Lookups whether there is an edge from a to b.
Computes in O(e') time, where e' is the number of successors of a.
pub fn node_indices(&self) -> NodeIndices<Ix>ⓘNotable traits for NodeIndices<Ix>
impl<Ix> Iterator for NodeIndices<Ix> type Item = Ix;[src]
Notable traits for NodeIndices<Ix>
impl<Ix> Iterator for NodeIndices<Ix> type Item = Ix;Returns an iterator over all node indices of the graph.
Consuming the whole iterator take O(|V|).
pub fn edge_indices(&self) -> EdgeIndices<'_, E, Ix>ⓘNotable traits for EdgeIndices<'a, E, Ix>
impl<'a, E, Ix: IndexType> Iterator for EdgeIndices<'a, E, Ix> type Item = EdgeIndex<Ix>;[src]
Notable traits for EdgeIndices<'a, E, Ix>
impl<'a, E, Ix: IndexType> Iterator for EdgeIndices<'a, E, Ix> type Item = EdgeIndex<Ix>;Returns an iterator over all edge indices of the graph.
Consuming the whole iterator take O(|V| + |E|).
Trait Implementations
impl<E, Ix: IndexType> Build for List<E, Ix>[src]
fn add_node(&mut self, _weight: ()) -> NodeIndex<Ix>[src]
Adds a new node to the list. This allocates a new Vec and then should
run in amortized O(1) time.
fn add_edge(
&mut self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>,
weight: E
) -> Option<EdgeIndex<Ix>>[src]
&mut self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>,
weight: E
) -> Option<EdgeIndex<Ix>>
Add an edge from a to b to the graph, with its associated
data weight.
Return the index of the new edge.
Computes in O(1) time.
Panics if the source node does not exist.
Note: List allows adding parallel (“duplicate”) edges. If you want
to avoid this, use .update_edge(a, b, weight) instead.
fn update_edge(
&mut self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>,
weight: E
) -> EdgeIndex<Ix>[src]
&mut self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>,
weight: E
) -> EdgeIndex<Ix>
Updates or adds an edge from a to b to the graph, with its associated
data weight.
Return the index of the new edge.
Computes in O(e') time, where e' is the number of successors of a.
Panics if the source node does not exist.
impl<E: Clone, Ix: Clone> Clone for List<E, Ix> where
Ix: IndexType, [src]
Ix: IndexType,
impl<E, Ix: IndexType> Data for List<E, Ix>[src]
type NodeWeight = ()
type EdgeWeight = E
impl<E, Ix: IndexType> DataMap for List<E, Ix>[src]
fn node_weight(&self, n: Self::NodeId) -> Option<&()>[src]
fn edge_weight(&self, e: EdgeIndex<Ix>) -> Option<&E>[src]
Accesses the weight of edge e
Computes in O(1)
impl<E, Ix: IndexType> DataMapMut for List<E, Ix>[src]
fn node_weight_mut(&mut self, n: Self::NodeId) -> Option<&mut ()>[src]
fn edge_weight_mut(&mut self, e: EdgeIndex<Ix>) -> Option<&mut E>[src]
Accesses the weight of edge e
Computes in O(1)
impl<E, Ix> Debug for List<E, Ix> where
E: Debug,
Ix: IndexType, [src]
E: Debug,
Ix: IndexType,
impl<E: Default, Ix: Default> Default for List<E, Ix> where
Ix: IndexType, [src]
Ix: IndexType,
impl<E, Ix> GraphBase for List<E, Ix> where
Ix: IndexType, [src]
Ix: IndexType,
impl<E, Ix: IndexType> GraphProp for List<E, Ix>[src]
impl<'a, Ix: IndexType, E> IntoEdgeReferences for &'a List<E, Ix>[src]
type EdgeRef = EdgeReference<'a, E, Ix>
type EdgeReferences = EdgeReferences<'a, E, Ix>
fn edge_references(self) -> Self::EdgeReferences[src]
impl<'a, Ix: IndexType, E> IntoEdges for &'a List<E, Ix>[src]
impl<'a, E, Ix: IndexType> IntoNeighbors for &'a List<E, Ix>[src]
type Neighbors = Neighbors<'a, E, Ix>
fn neighbors(self, a: NodeIndex<Ix>) -> Self::Neighbors[src]
Returns an iterator of all nodes with an edge starting from a.
Panics if a is out of bounds.
Use List::edge_indices_from instead if you do not want to borrow the adjacency list while
iterating.
impl<'a, E, Ix: IndexType> IntoNodeIdentifiers for &'a List<E, Ix>[src]
type NodeIdentifiers = NodeIndices<Ix>
fn node_identifiers(self) -> NodeIndices<Ix>ⓘNotable traits for NodeIndices<Ix>
impl<Ix> Iterator for NodeIndices<Ix> type Item = Ix;[src]
Notable traits for NodeIndices<Ix>
impl<Ix> Iterator for NodeIndices<Ix> type Item = Ix;impl<'a, Ix: IndexType, E> IntoNodeReferences for &'a List<E, Ix>[src]
type NodeRef = NodeIndex<Ix>
type NodeReferences = NodeIndices<Ix>
fn node_references(self) -> Self::NodeReferences[src]
impl<E, Ix: IndexType> NodeCompactIndexable for List<E, Ix>[src]
impl<E, Ix: IndexType> NodeCount for List<E, Ix>[src]
fn node_count(&self) -> usize[src]
Returns the number of nodes in the list
Computes in O(1) time.
impl<E, Ix: IndexType> NodeIndexable for List<E, Ix>[src]
fn node_bound(&self) -> usize[src]
fn to_index(&self, a: Self::NodeId) -> usize[src]
fn from_index(&self, i: usize) -> Self::NodeId[src]
impl<E, Ix> Visitable for List<E, Ix> where
Ix: IndexType, [src]
Ix: IndexType,
type Map = FixedBitSet
The associated map type
fn visit_map(&self) -> FixedBitSet[src]
fn reset_map(&self, map: &mut Self::Map)[src]
Auto Trait Implementations
impl<E, Ix> RefUnwindSafe for List<E, Ix> where
E: RefUnwindSafe,
Ix: RefUnwindSafe, [src]
E: RefUnwindSafe,
Ix: RefUnwindSafe,
impl<E, Ix> Send for List<E, Ix> where
E: Send,
Ix: Send, [src]
E: Send,
Ix: Send,
impl<E, Ix> Sync for List<E, Ix> where
E: Sync,
Ix: Sync, [src]
E: Sync,
Ix: Sync,
impl<E, Ix> Unpin for List<E, Ix> where
E: Unpin,
Ix: Unpin, [src]
E: Unpin,
Ix: Unpin,
impl<E, Ix> UnwindSafe for List<E, Ix> where
E: UnwindSafe,
Ix: UnwindSafe, [src]
E: UnwindSafe,
Ix: UnwindSafe,
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> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn clone_into(&self, target: &mut T)[src]
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>,