petgraph::adj

Struct List

Source
pub struct List<E, Ix = DefaultIx>
where Ix: IndexType,
{ /* private fields */ }
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§

Source§

impl<E, Ix: IndexType> List<E, Ix>

Source

pub fn new() -> List<E, Ix>

Creates a new, empty adjacency list.

Source

pub fn with_capacity(nodes: usize) -> List<E, Ix>

Creates a new, empty adjacency list tailored for nodes nodes.

Source

pub fn clear(&mut self)

Removes all nodes and edges from the list.

Source

pub fn edge_count(&self) -> usize

Returns the number of edges in the list

Computes in O(|V|) time.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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)

Source

pub fn edge_indices_from(&self, a: NodeIndex<Ix>) -> OutgoingEdgeIndices<Ix>

Source

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.

Source

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.

Source

pub fn node_indices(&self) -> NodeIndices<Ix>

Returns an iterator over all node indices of the graph.

Consuming the whole iterator take O(|V|).

Source

pub fn edge_indices(&self) -> EdgeIndices<'_, E, Ix>

Returns an iterator over all edge indices of the graph.

Consuming the whole iterator take O(|V| + |E|).

Trait Implementations§

Source§

impl<E, Ix: IndexType> Build for List<E, Ix>

Source§

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.

Source§

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.

Source§

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.

Source§

impl<E: Clone, Ix> Clone for List<E, Ix>
where Ix: IndexType + Clone,

Source§

fn clone(&self) -> List<E, Ix>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E, Ix: IndexType> Data for List<E, Ix>

Source§

impl<E, Ix: IndexType> DataMap for List<E, Ix>

Source§

fn edge_weight(&self, e: EdgeIndex<Ix>) -> Option<&E>

Accesses the weight of edge e

Computes in O(1)

Source§

fn node_weight(&self, n: Self::NodeId) -> Option<&()>

Source§

impl<E, Ix: IndexType> DataMapMut for List<E, Ix>

Source§

fn edge_weight_mut(&mut self, e: EdgeIndex<Ix>) -> Option<&mut E>

Accesses the weight of edge e

Computes in O(1)

Source§

fn node_weight_mut(&mut self, n: Self::NodeId) -> Option<&mut ()>

Source§

impl<E, Ix> Debug for List<E, Ix>
where E: Debug, Ix: IndexType,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E: Default, Ix> Default for List<E, Ix>
where Ix: IndexType + Default,

Source§

fn default() -> List<E, Ix>

Returns the “default value” for a type. Read more
Source§

impl<E, Ix: IndexType> EdgeCount for List<E, Ix>

Source§

fn edge_count(&self) -> usize

Returns the number of edges in the list

Computes in O(|V|) time.

Source§

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().

Source§

type AdjMatrix = FixedBitSet

The associated adjacency matrix type
Source§

fn adjacency_matrix(&self) -> FixedBitSet

Create the adjacency matrix
Source§

fn is_adjacent( &self, matrix: &FixedBitSet, a: NodeIndex<Ix>, b: NodeIndex<Ix>, ) -> bool

Return true if there is an edge from a to b, false otherwise. Read more
Source§

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

Source§

type NodeId = Ix

node identifier
Source§

type EdgeId = EdgeIndex<Ix>

edge identifier
Source§

impl<E, Ix: IndexType> GraphProp for List<E, Ix>

Source§

type EdgeType = Directed

The kind of edges in the graph.
Source§

fn is_directed(&self) -> bool

Source§

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

Source§

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

Source§

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

Source§

fn edges(self, a: Self::NodeId) -> Self::Edges

Source§

impl<'a, E, Ix: IndexType> IntoNeighbors for &'a List<E, Ix>

Source§

fn neighbors(self, a: NodeIndex<Ix>) -> Self::Neighbors

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.

Source§

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

Source§

impl<'a, E, Ix: IndexType> IntoNodeIdentifiers for &'a List<E, Ix>

Source§

impl<'a, Ix: IndexType, E> IntoNodeReferences for &'a List<E, Ix>

Source§

impl<E, Ix: IndexType> NodeCount for List<E, Ix>

Source§

fn node_count(&self) -> usize

Returns the number of nodes in the list

Computes in O(1) time.

Source§

impl<E, Ix: IndexType> NodeIndexable for List<E, Ix>

Source§

fn node_bound(&self) -> usize

Return an upper bound of the node indices in the graph (suitable for the size of a bitmap).
Source§

fn to_index(&self, a: Self::NodeId) -> usize

Convert a to an integer index.
Source§

fn from_index(&self, i: usize) -> Self::NodeId

Convert i to a node index. i must be a valid value in the graph.
Source§

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

Source§

type Map = FixedBitSet

The associated map type
Source§

fn visit_map(&self) -> FixedBitSet

Create a new visitor map
Source§

fn reset_map(&self, map: &mut Self::Map)

Reset the visitor map (and resize to new size of graph if needed)
Source§

impl<E, Ix: IndexType> NodeCompactIndexable for List<E, Ix>

Auto Trait Implementations§

§

impl<E, Ix> Freeze for List<E, Ix>

§

impl<E, Ix> RefUnwindSafe for List<E, Ix>

§

impl<E, Ix> Send for List<E, Ix>
where Ix: Send, E: Send,

§

impl<E, Ix> Sync for List<E, Ix>
where Ix: Sync, E: Sync,

§

impl<E, Ix> Unpin for List<E, Ix>
where Ix: Unpin, E: Unpin,

§

impl<E, Ix> UnwindSafe for List<E, Ix>
where Ix: UnwindSafe, E: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.