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
sourceimpl<E, Ix: IndexType> List<E, Ix>
impl<E, Ix: IndexType> List<E, Ix>
sourcepub fn with_capacity(nodes: usize) -> List<E, Ix>
pub fn with_capacity(nodes: usize) -> List<E, Ix>
Creates a new, empty adjacency list tailored for nodes
nodes.
sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Returns the number of edges in the list
Computes in O(|V|) time.
sourcepub fn add_node(&mut self) -> NodeIndex<Ix>
pub fn add_node(&mut self) -> NodeIndex<Ix>
Adds a new node to the list. This allocates a new Vec
and then should
run in amortized O(1) time.
sourcepub fn add_node_with_capacity(&mut self, successors: usize) -> NodeIndex<Ix>
pub fn add_node_with_capacity(&mut self, successors: usize) -> NodeIndex<Ix>
Adds a new node to the list. This allocates a new Vec
and then should
run in amortized O(1) time.
sourcepub fn add_node_from_edges<I: Iterator<Item = (NodeIndex<Ix>, E)>>(
&mut self,
edges: I
) -> NodeIndex<Ix>
pub fn add_node_from_edges<I: Iterator<Item = (NodeIndex<Ix>, E)>>(
&mut self,
edges: I
) -> NodeIndex<Ix>
Adds a new node to the list by giving its list of successors and the corresponding weigths.
sourcepub fn add_edge(
&mut self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>,
weight: E
) -> EdgeIndex<Ix>
pub fn add_edge(
&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.
sourcepub fn edge_endpoints(
&self,
e: EdgeIndex<Ix>
) -> Option<(NodeIndex<Ix>, NodeIndex<Ix>)>
pub fn edge_endpoints(
&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>;
Ix: IndexType, type Item = EdgeIndex<Ix>;
sourcepub fn contains_edge(&self, a: NodeIndex<Ix>, b: NodeIndex<Ix>) -> bool
pub fn contains_edge(&self, a: NodeIndex<Ix>, b: NodeIndex<Ix>) -> bool
Lookups whether there is an edge from a
to b
.
Computes in O(e’) time, where e’ is the number of successors of a
.
sourcepub fn find_edge(
&self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>
) -> Option<EdgeIndex<Ix>>
pub fn find_edge(
&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
.
sourcepub 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;
Returns an iterator over all node indices of the graph.
Consuming the whole iterator take O(|V|).
sourcepub 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>;
Returns an iterator over all edge indices of the graph.
Consuming the whole iterator take O(|V| + |E|).
Trait Implementations
sourceimpl<E, Ix: IndexType> Build for List<E, Ix>
impl<E, Ix: IndexType> Build for List<E, Ix>
sourcefn add_node(&mut self, _weight: ()) -> NodeIndex<Ix>
fn add_node(&mut self, _weight: ()) -> NodeIndex<Ix>
Adds a new node to the list. This allocates a new Vec
and then should
run in amortized O(1) time.
sourcefn add_edge(
&mut self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>,
weight: E
) -> Option<EdgeIndex<Ix>>
fn add_edge(
&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.
sourcefn update_edge(
&mut self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>,
weight: E
) -> EdgeIndex<Ix>
fn update_edge(
&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.
sourceimpl<E, Ix: IndexType> Data for List<E, Ix>
impl<E, Ix: IndexType> Data for List<E, Ix>
type NodeWeight = ()
type EdgeWeight = E
sourceimpl<E, Ix: IndexType> DataMap for List<E, Ix>
impl<E, Ix: IndexType> DataMap for List<E, Ix>
sourcefn edge_weight(&self, e: EdgeIndex<Ix>) -> Option<&E>
fn edge_weight(&self, e: EdgeIndex<Ix>) -> Option<&E>
Accesses the weight of edge e
Computes in O(1)
fn node_weight(&self, n: Self::NodeId) -> Option<&()>
sourceimpl<E, Ix: IndexType> DataMapMut for List<E, Ix>
impl<E, Ix: IndexType> DataMapMut for List<E, Ix>
sourcefn edge_weight_mut(&mut self, e: EdgeIndex<Ix>) -> Option<&mut E>
fn edge_weight_mut(&mut self, e: EdgeIndex<Ix>) -> Option<&mut E>
Accesses the weight of edge e
Computes in O(1)
fn node_weight_mut(&mut self, n: Self::NodeId) -> Option<&mut ()>
sourceimpl<E, Ix: IndexType> EdgeCount for List<E, Ix>
impl<E, Ix: IndexType> EdgeCount for List<E, Ix>
sourcefn edge_count(&self) -> usize
fn edge_count(&self) -> usize
Returns the number of edges in the list
Computes in O(|V|) time.
sourceimpl<E, Ix> GetAdjacencyMatrix for List<E, Ix>where
Ix: IndexType,
impl<E, Ix> GetAdjacencyMatrix for List<E, Ix>where
Ix: IndexType,
The adjacency matrix for List is a bitmap that’s computed by
.adjacency_matrix()
.
type AdjMatrix = FixedBitSet
type AdjMatrix = FixedBitSet
sourcefn adjacency_matrix(&self) -> FixedBitSet
fn adjacency_matrix(&self) -> FixedBitSet
sourcefn is_adjacent(
&self,
matrix: &FixedBitSet,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>
) -> bool
fn is_adjacent(
&self,
matrix: &FixedBitSet,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>
) -> bool
sourceimpl<'a, Ix: IndexType, E> IntoEdgeReferences for &'a List<E, Ix>
impl<'a, Ix: IndexType, E> IntoEdgeReferences for &'a List<E, Ix>
type EdgeRef = EdgeReference<'a, E, Ix>
type EdgeReferences = EdgeReferences<'a, E, Ix>
fn edge_references(self) -> Self::EdgeReferences
sourceimpl<'a, E, Ix: IndexType> IntoNeighbors for &'a List<E, Ix>
impl<'a, E, Ix: IndexType> IntoNeighbors for &'a List<E, Ix>
sourceimpl<'a, E, Ix: IndexType> IntoNodeIdentifiers for &'a List<E, Ix>
impl<'a, E, Ix: IndexType> IntoNodeIdentifiers for &'a List<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;
sourceimpl<'a, Ix: IndexType, E> IntoNodeReferences for &'a List<E, Ix>
impl<'a, Ix: IndexType, E> IntoNodeReferences for &'a List<E, Ix>
type NodeRef = Ix
type NodeReferences = NodeIndices<Ix>
fn node_references(self) -> Self::NodeReferences
sourceimpl<E, Ix: IndexType> NodeCount for List<E, Ix>
impl<E, Ix: IndexType> NodeCount for List<E, Ix>
sourcefn node_count(&self) -> usize
fn node_count(&self) -> usize
Returns the number of nodes in the list
Computes in O(1) time.
sourceimpl<E, Ix: IndexType> NodeIndexable for List<E, Ix>
impl<E, Ix: IndexType> NodeIndexable for List<E, Ix>
sourcefn node_bound(&self) -> usize
fn node_bound(&self) -> usize
sourcefn from_index(&self, i: usize) -> Self::NodeId
fn from_index(&self, i: usize) -> Self::NodeId
i
to a node index. i
must be a valid value in the graph.