Struct petgraph::csr::Csr[][src]

pub struct Csr<N = (), E = (), Ty = Directed, Ix = DefaultIx> { /* fields omitted */ }
Expand description

Compressed Sparse Row (CSR) is a sparse adjacency matrix graph.

CSR is parameterized over:

  • Associated data N for nodes and E for edges, called weights. The associated data can be of arbitrary type.
  • Edge type Ty that determines whether the graph edges are directed or undirected.
  • Index type Ix, which determines the maximum size of the graph.

Using O(|E| + |V|) space.

Self loops are allowed, no parallel edges.

Fast iteration of the outgoing edges of a vertex.

Implementations

Create an empty Csr.

Create a new Csr with n nodes. N must implement Default for the weight of each node.

Example

use petgraph::csr::Csr;
use petgraph::prelude::*;

let graph = Csr::<u8,()>::with_nodes(5);
assert_eq!(graph.node_count(),5);
assert_eq!(graph.edge_count(),0);

assert_eq!(graph[0],0);
assert_eq!(graph[4],0);

Create a new Csr from a sorted sequence of edges

Edges must be sorted and unique, where the sort order is the default order for the pair (u, v) in Rust (u has priority).

Computes in O(|E| + |V|) time.

Example

use petgraph::csr::Csr;
use petgraph::prelude::*;

let graph = Csr::<(),()>::from_sorted_edges(&[
                    (0, 1), (0, 2),
                    (1, 0), (1, 2), (1, 3),
                    (2, 0),
                    (3, 1),
]);

Remove all edges

Adds a new node with the given weight, returning the corresponding node index.

Return true if the edge was added

If you add all edges in row-major order, the time complexity is O(|V|·|E|) for the whole operation.

Panics if a or b are out of bounds.

Computes in O(log |V|) time.

Panics if the node a does not exist.

Computes in O(1) time.

Panics if the node a does not exist.

Computes in O(1) time.

Panics if the node a does not exist.

Computes in O(1) time.

Panics if the node a does not exist.

Return an iterator of all edges of a.

  • Directed: Outgoing edges from a.
  • Undirected: All edges connected to a.

Panics if the node a does not exist.
Iterator element type is EdgeReference<E, Ty, Ix>.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Return the number of edges in the graph.

The adjacency matrix for Csr is a bitmap that’s computed by .adjacency_matrix().

The associated adjacency matrix type

Create the adjacency matrix

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

node identifier

edge identifier

The kind edges in the graph.

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

Return an iterator of all neighbors of a.

  • Directed: Targets of outgoing edges from a.
  • Undirected: Opposing endpoints of all edges connected to a.

Panics if the node a does not exist.
Iterator element type is NodeIndex<Ix>.

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

Convert a to an integer index.

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

The associated map type

Create a new visitor map

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.