Trait MutableGraph

Source
pub trait MutableGraph: GraphEngine {
    // Required methods
    fn insert_node(&mut self, node_id: usize) -> bool;
    fn create_node(&mut self) -> usize;
    fn remove_node_with_edges(&mut self, node_id: usize);
    fn insert_edge_with_nodes<E>(&mut self, edge: E) -> EdgeInsertID
       where E: Edge;
    fn remove_edge<E>(&mut self, edge: E)
       where E: Into<EdgeQuery>;

    // Provided methods
    fn remove_node(&mut self, node_id: usize) { ... }
    fn insert_edge<E>(&mut self, edge: E) -> EdgeInsertID
       where E: Edge { ... }
    fn shrink(&mut self) { ... }
}
Expand description

Mark a graph engine that can add and delete edges or points

Required Methods§

Source

fn insert_node(&mut self, node_id: usize) -> bool

Insert a node without any neighbors (edges).

§Examples
use graph_theory::{graph_engines::AdjacencyNodeDict, GraphEngine};
let mut graph = AdjacencyNodeDict::default();
assert_eq!(graph.count_nodes(), 0);
graph.insert_node(5);
assert_eq!(graph.count_nodes(), 1);
Source

fn create_node(&mut self) -> usize

Insert a node without any neighbors (edges).

§Examples
use graph_theory::{graph_engines::AdjacencyNodeDict, GraphEngine};
let mut graph = AdjacencyNodeDict::default();
assert_eq!(graph.count_nodes(), 0);
graph.insert_node(5);
assert_eq!(graph.count_nodes(), 1);
Source

fn remove_node_with_edges(&mut self, node_id: usize)

Remove the given node and all edges connected to it.

§Examples
use graph_theory::{graph_engines::AdjacencyNodeDict, GraphEngine};
let mut graph = AdjacencyNodeDict::default();
assert_eq!(graph.count_nodes(), 0);
graph.insert_node(5);
assert_eq!(graph.count_nodes(), 1);
Source

fn insert_edge_with_nodes<E>(&mut self, edge: E) -> EdgeInsertID
where E: Edge,

Insert edge to graph, if the nodes does not exist, also insert them.

§Panics
  • No such ability

Not all graph engine supports insert edge.

§Examples
use graph_theory::GraphEngine;
Source

fn remove_edge<E>(&mut self, edge: E)
where E: Into<EdgeQuery>,

Remove edge by given edge-id or start and end node-id.

§Panics
  • No such ability

Not all graph engine supports insert edge.

§Examples
use graph_theory::GraphEngine;

Provided Methods§

Source

fn remove_node(&mut self, node_id: usize)

Remove the given node.

§Undefined Behavior
  • If the node has any edges, the behavior is undefined.

It is recommended to remove all edges before removing the node, see [GraphEngine::remove_node_with_edges].

§Examples
use graph_theory::{graph_engines::AdjacencyNodeDict, GraphEngine};
let mut graph = AdjacencyNodeDict::default();
assert_eq!(graph.count_nodes(), 0);
graph.insert_node(5);
assert_eq!(graph.count_nodes(), 1);
Source

fn insert_edge<E>(&mut self, edge: E) -> EdgeInsertID
where E: Edge,

Insert a edge between two nodes.

§Undefined Behaviors
  • If the nodes does not exist, the behavior is undefined.

It is recommended to check the existence of the nodes before inserting the edge, see [GraphEngine::insert_edge_with_nodes].

  • Insert undirected edge to directed graph.

Two edges will be inserted, but only return last edge’s id.

§Panics
  • No such ability

Not all graph engine supports insert edge.

  • Insert disconnected edge

Meaningless, don’t do that.

§Examples
use graph_theory::GraphEngine;
Source

fn shrink(&mut self)

Remove invalid edges and nodes to improve the efficiency of subsequent queries.

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.

Implementors§