Struct petgraph::adj::List[][src]

pub struct List<E, Ix = DefaultIx> where
    Ix: IndexType
{ /* fields omitted */ }

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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 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 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]

impl<E: Default, Ix: Default> Default for List<E, Ix> where
    Ix: IndexType
[src]

impl<E, Ix> GraphBase for List<E, Ix> where
    Ix: IndexType
[src]

type NodeId = NodeIndex<Ix>

node identifier

type EdgeId = EdgeIndex<Ix>

edge identifier

impl<E, Ix: IndexType> GraphProp for List<E, Ix>[src]

type EdgeType = Directed

The kind edges in the graph.

impl<'a, Ix: IndexType, E> IntoEdgeReferences for &'a List<E, Ix>[src]

type EdgeRef = EdgeReference<'a, E, Ix>

type EdgeReferences = EdgeReferences<'a, E, Ix>

impl<'a, Ix: IndexType, E> IntoEdges for &'a List<E, Ix>[src]

type Edges = OutgoingEdgeReferences<'a, E, Ix>

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>

impl<'a, Ix: IndexType, E> IntoNodeReferences for &'a List<E, Ix>[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]

impl<E, Ix> Visitable for List<E, Ix> where
    Ix: IndexType
[src]

type Map = FixedBitSet

The associated map type

Auto Trait Implementations

impl<E, Ix> RefUnwindSafe for List<E, Ix> where
    E: RefUnwindSafe,
    Ix: RefUnwindSafe
[src]

impl<E, Ix> Send for List<E, Ix> where
    E: Send,
    Ix: Send
[src]

impl<E, Ix> Sync for List<E, Ix> where
    E: Sync,
    Ix: Sync
[src]

impl<E, Ix> Unpin for List<E, Ix> where
    E: Unpin,
    Ix: Unpin
[src]

impl<E, Ix> UnwindSafe for List<E, Ix> where
    E: UnwindSafe,
    Ix: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.