GraphUpdate

Trait GraphUpdate 

Source
pub trait GraphUpdate: Graph {
    // Required method
    fn add_node(&mut self, node: Self::Node) -> Self::NodeIx;

    // Provided methods
    fn add_edge(
        &mut self,
        edge: Self::Edge,
        from: Self::NodeIx,
        to: Self::NodeIx,
    ) -> Self::EdgeIx { ... }
    unsafe fn add_edge_unchecked(
        &mut self,
        edge: Self::Edge,
        from: Self::NodeIx,
        to: Self::NodeIx,
    ) -> Self::EdgeIx { ... }
    fn append<G>(&mut self, other: G)
       where Self: Sized,
             G: GraphUpdate<Node = Self::Node, Edge = Self::Edge> + GraphRemove { ... }
}
Expand description

Trait for graphs that support adding nodes and edges.

This trait extends the base Graph trait with mutation operations for adding new nodes and edges to the graph. It provides both checked and unchecked variants for performance-critical scenarios.

§Examples

use gotgraph::prelude::*;

let mut graph: VecGraph<i32, &str> = VecGraph::default();

graph.scope_mut(|mut ctx| {
    let node1 = ctx.add_node(42);
    let node2 = ctx.add_node(100);
    let edge = ctx.add_edge("connects", node1, node2);
     
    println!("Added edge between {} and {}",
             ctx.node(node1), ctx.node(node2));
});

Required Methods§

Source

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

Adds a new node to the graph with the given data.

§Parameters
  • node: The data to store in the new node
§Returns

The index of the newly created node.

§Examples
use gotgraph::prelude::*;

let mut graph: VecGraph<&str, ()> = VecGraph::default();
graph.scope_mut(|mut ctx| {
    let node = ctx.add_node("Alice");
});

Provided Methods§

Source

fn add_edge( &mut self, edge: Self::Edge, from: Self::NodeIx, to: Self::NodeIx, ) -> Self::EdgeIx

Adds a new edge to the graph between two nodes.

This method includes bounds checking to ensure both endpoint nodes exist.

§Parameters
  • edge: The data to store in the new edge
  • from: The source node index
  • to: The target node index
§Returns

The index of the newly created edge.

§Panics

Panics if either from or to node indices don’t exist in the graph.

§Examples
use gotgraph::prelude::*;

let mut graph: VecGraph<i32, &str> = VecGraph::default();
graph.scope_mut(|mut ctx| {
    let n1 = ctx.add_node(1);
    let n2 = ctx.add_node(2);
    let edge = ctx.add_edge("connection", n1, n2);
});
Source

unsafe fn add_edge_unchecked( &mut self, edge: Self::Edge, from: Self::NodeIx, to: Self::NodeIx, ) -> Self::EdgeIx

Adds a new edge to the graph between two nodes without bounds checking.

§Safety

The caller must ensure that both from and to node indices exist in the graph (i.e., exists_node_index(from) and exists_node_index(to) both return true). Using invalid node indices results in undefined behavior.

§Parameters
  • edge: The data to store in the new edge
  • from: The source node index
  • to: The target node index
§Returns

The index of the newly created edge.

Source

fn append<G>(&mut self, other: G)
where Self: Sized, G: GraphUpdate<Node = Self::Node, Edge = Self::Edge> + GraphRemove,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: GraphUpdate> GraphUpdate for &mut T

Source§

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

Source§

fn add_edge( &mut self, edge: Self::Edge, from: Self::NodeIx, to: Self::NodeIx, ) -> Self::EdgeIx

Source§

unsafe fn add_edge_unchecked( &mut self, edge: Self::Edge, from: Self::NodeIx, to: Self::NodeIx, ) -> Self::EdgeIx

Source§

fn append<G>(&mut self, other: G)
where Self: Sized, G: GraphUpdate<Node = Self::Node, Edge = Self::Edge> + GraphRemove,

Implementors§

Source§

impl<'scope, G: GraphUpdate> GraphUpdate for Context<'scope, G>

Source§

impl<N, E> GraphUpdate for VecGraph<N, E>