Trait rs_graph::builder::Builder

source ·
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§

source

type Graph

The graph type produced by this builder.

source

type Node: Copy + Eq

The type of a nodes.

source

type Edge: Copy + Eq

The type of an edge.

Required Methods§

source

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.

source

fn reserve(&mut self, nnodes: usize, nedges: usize)

Reserve memory for a certain number of nodes and edges.

source

fn num_nodes(&self) -> usize

Return the current number of nodes.

source

fn num_edges(&self) -> usize

Return the current number of nodes.

source

fn add_node(&mut self) -> Self::Node

Add a new node.

source

fn add_edge(&mut self, u: Self::Node, v: Self::Node) -> Self::Edge

Add a new edge.

source

fn node2id(&self, u: Self::Node) -> usize

Return a unique id of a node.

source

fn edge2id(&self, e: Self::Edge) -> usize

Return a unique id of an edge.

source

fn id2node(&self, uid: usize) -> Self::Node

Return the node with a certain id.

source

fn id2edge(&self, eid: usize) -> Self::Edge

Return the edge with a certain id.

source

fn into_graph(self) -> Self::Graph

Turn the builder into a graph.

Provided Methods§

source

fn new() -> Self

Create a new, empty builder.

source

fn add_nodes(&mut self, n: usize) -> Vec<Self::Node>

Add n new nodes.

Implementors§

source§

impl<ID> Builder for VecGraphBuilder<ID>where ID: PrimInt + Unsigned,

§

type Graph = VecGraph<ID>

§

type Node = Node<ID>

§

type Edge = Edge<ID>

source§

impl<ID, N, E> Builder for LinkedListGraphBuilder<ID, N, E>where ID: PrimInt + Unsigned + 'static, N: Default, E: Default,

§

type Graph = LinkedListGraph<ID, N, E>

§

type Node = Node<ID>

§

type Edge = Edge<ID>