Struct petgraph::adj::List [−][src]
Expand description
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
Creates a new, empty adjacency list tailored for nodes
nodes.
Returns the number of edges in the list
Computes in O(|V|) time.
Adds a new node to the list. This allocates a new Vec
and then should
run in amortized O(1) time.
Adds a new node to the list. This allocates a new Vec
and then should
run in amortized O(1) time.
Adds a new node to the list by giving its list of successors and the corresponding weigths.
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.
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>;
impl<Ix> Iterator for OutgoingEdgeIndices<Ix> where
Ix: IndexType, type Item = 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
.
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;
pub fn node_indices(&self) -> NodeIndices<Ix>ⓘNotable traits for NodeIndices<Ix>impl<Ix> Iterator for NodeIndices<Ix> type Item = 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>;
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>;
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
Adds a new node to the list. This allocates a new Vec
and then should
run in amortized O(1) time.
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.
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.
type NodeWeight = ()
type EdgeWeight = E
Accesses the weight of edge e
Computes in O(1)
Accesses the weight of edge e
Computes in O(1)
Returns the number of edges in the list
Computes in O(|V|) time.
The adjacency matrix for List is a bitmap that’s computed by
.adjacency_matrix()
.
type AdjMatrix = FixedBitSet
type AdjMatrix = FixedBitSet
The associated adjacency matrix type
Create the adjacency matrix
Return true if there is an edge from a
to b
, false otherwise. Read more
type EdgeRef = EdgeReference<'a, E, Ix>
type EdgeReferences = EdgeReferences<'a, E, Ix>
type NodeIdentifiers = NodeIndices<Ix>
fn node_identifiers(self) -> NodeIndices<Ix>ⓘNotable traits for NodeIndices<Ix>impl<Ix> Iterator for NodeIndices<Ix> type Item = Ix;
impl<Ix> Iterator for NodeIndices<Ix> type Item = Ix;
type NodeReferences = NodeIndices<Ix>
Returns the number of nodes in the list
Computes in O(1) time.
Return an upper bound of the node indices in the graph (suitable for the size of a bitmap). Read more
Convert i
to a node index. i
must be a valid value in the graph.
type Map = FixedBitSet
type Map = FixedBitSet
The associated map type
Create a new visitor map
Auto Trait Implementations
impl<E, Ix> RefUnwindSafe for List<E, Ix> where
E: RefUnwindSafe,
Ix: RefUnwindSafe,
impl<E, Ix> UnwindSafe for List<E, Ix> where
E: UnwindSafe,
Ix: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more