pub trait GraphEnginewhere
    Self: Sized,{
    type NodeIter: Iterator<Item = usize>;

    // Required methods
    fn graph_kind(&self) -> GraphKind;
    fn has_node(&self, node_id: usize) -> Option<usize>;
    fn count_nodes(&self) -> usize;
    fn traverse_nodes(&self) -> NodesVisitor<'_, Self> ;
    fn has_edge<E: Into<EdgeQuery>>(&self, edge: E) -> Option<usize>;
    fn traverse_edges(&self) -> EdgesVisitor<'_, Self> ;
    fn count_edges(&self) -> usize;

    // Provided methods
    fn get_node_degree(&self, node_id: usize) -> Result<usize, GraphError> { ... }
    fn size_hint(&self) -> usize { ... }
}
Expand description

Represent a graph storage, with a set of nodes and edges.

Examples

use graph_theory::GraphEngine;

Required Associated Types§

Required Methods§

source

fn graph_kind(&self) -> GraphKind

Check the graph kind, it can be directed or undirected.

Examples
use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
assert_eq!(CompleteGraph::one_way(5).has_node(5), true);
assert_eq!(CompleteGraph::one_way(5).has_node(6), false);
source

fn has_node(&self, node_id: usize) -> Option<usize>

Check if the node exists, return the node id if exists.

Examples
use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
assert_eq!(CompleteGraph::one_way(5).has_node(5), true);
assert_eq!(CompleteGraph::one_way(5).has_node(6), false);
source

fn count_nodes(&self) -> usize

Count the number of nodes in the graph.

Examples
use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
assert_eq!(CompleteGraph::one_way(5).count_nodes(), 5);
source

fn traverse_nodes(&self) -> NodesVisitor<'_, Self>

Traverse all nodes in the graph.

Examples
use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
let mut graph = CompleteGraph::one_way(5);
assert_eq!(graph.traverse_nodes().count(), 20)
source

fn has_edge<E: Into<EdgeQuery>>(&self, edge: E) -> Option<usize>

Check if the edge exists, return the node id if exists.

Examples
use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
assert_eq!(CompleteGraph::one_way(5).has_node(5), true);
assert_eq!(CompleteGraph::one_way(5).has_node(6), false);
source

fn traverse_edges(&self) -> EdgesVisitor<'_, Self>

Get the edges of the graph.

use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
let mut graph = CompleteGraph::one_way(5);
assert_eq!(graph.traverse_nodes().count(), 20)
source

fn count_edges(&self) -> usize

Count the number of edges in the graph.

Examples
assert_eq!(CycleGraph::one_way(5).count_edges(), 5);
assert_eq!(CycleGraph::two_way(5).count_edges(), 10);
assert_eq!(StarGraph::one_way(5).count_edges(), 5);
assert_eq!(StarGraph::two_way(5).count_edges(), 10);
assert_eq!(CompleteGraph::one_way(5).count_edges(), 5);
assert_eq!(CompleteGraph::one_way(5).count_edges(), 10);

Provided Methods§

source

fn get_node_degree(&self, node_id: usize) -> Result<usize, GraphError>

Check if the node exists, return the node id if exists.

Return None if the node does not exist.

Examples
use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
assert_eq!(CompleteGraph::one_way(5).count_nodes(), 5);
source

fn size_hint(&self) -> usize

Query the total space occupied by the structure, return 0 if failed to query

Note that this volume contains garbage data, call [GraphEngine::shrink] at the right time to perform garbage collection.

Implementors§