pub trait Builderwhere
Self: Sized,{
type Graph;
type Node: Copy + Eq;
type Edge: Copy + Eq;
Show 13 methods
// Required methods
fn with_capacities(nnodes: usize, nedges: usize) -> Self;
fn reserve(&mut self, nnodes: usize, nedges: usize);
fn num_nodes(&self) -> usize;
fn num_edges(&self) -> usize;
fn add_node(&mut self) -> Self::Node;
fn add_edge(&mut self, u: Self::Node, v: Self::Node) -> Self::Edge;
fn node2id(&self, u: Self::Node) -> usize;
fn edge2id(&self, e: Self::Edge) -> usize;
fn id2node(&self, uid: usize) -> Self::Node;
fn id2edge(&self, eid: usize) -> Self::Edge;
fn into_graph(self) -> Self::Graph;
// Provided methods
fn new() -> Self { ... }
fn add_nodes(&mut self, n: usize) -> Vec<Self::Node> { ... }
}
Expand description
A trait to construct graphs.
In general graphs are static objects. In order to build a graph, one should use a graph builder and, once the construction is complete, convert it into a graph.
This 2-level approach is used because some graph implementations be unstable if the graph is modified (e.g., the node numbers might change). The builder approach allows to separate construction and use of a graph.
Required Associated Types§
Required Methods§
sourcefn with_capacities(nnodes: usize, nedges: usize) -> Self
fn with_capacities(nnodes: usize, nedges: usize) -> Self
Create a new, empty builder.
The builder might be passed a guess of the number of nodes and edges. This might be used to reserve the appropriate internal memory, but is no strict requirement for the number of nodes and edges to be added to the graph.
sourcefn reserve(&mut self, nnodes: usize, nedges: usize)
fn reserve(&mut self, nnodes: usize, nedges: usize)
Reserve memory for a certain number of nodes and edges.
sourcefn into_graph(self) -> Self::Graph
fn into_graph(self) -> Self::Graph
Turn the builder into a graph.