Trait UndirectedGraph

Source
pub trait UndirectedGraph:
    BaseGraph
    + DefaultGraph
    + PartialOrdGraph
    + SubGraph {
    type NeighborsIter<'a>: Iterator<Item = usize> + FusedIterator
       where Self: 'a;

    // Required method
    fn neighbors(&self, x: usize) -> Self::NeighborsIter<'_>;

    // Provided methods
    fn is_neighbor(&self, x: usize, y: usize) -> bool { ... }
    fn degree(&self, x: usize) -> usize { ... }
}
Expand description

Undirected graph trait.

Required Associated Types§

Source

type NeighborsIter<'a>: Iterator<Item = usize> + FusedIterator where Self: 'a

Neighbors iterator type.

Required Methods§

Source

fn neighbors(&self, x: usize) -> Self::NeighborsIter<'_>

Neighbors iterator.

Iterates over the vertex set $Ne(\mathcal{G}, X)$ of a given vertex $X$.

§Panics

Panics if the vertex identifier does not exist in the graph.

§Examples
use causal_hub::prelude::*;

// Define edge set.
let e = EdgeList::from([("A", "B"), ("C", "A"), ("A", "A")]);

// Build a graph.
let g = Graph::from(e);

// Choose vertex.
let x = g.vertex("A");

// Use the neighbors iterator.
assert!(g.neighbors(x).eq([0, 1, 2]));

// Use the associated macro 'Ne!'.
assert!(g.neighbors(x).eq(Ne!(g, x)));

Provided Methods§

Source

fn is_neighbor(&self, x: usize, y: usize) -> bool

Checks neighbor vertices in the graph.

Checks whether a vertex $Y$ is neighbor of another vertex $X$ or not.

§Panics

At least one of the vertex indexes does not exist in the graph.

§Examples
use causal_hub::prelude::*;

// Define edge set.
let e = EdgeList::from([("A", "B"), ("C", "A"), ("A", "A")]);

// Build a graph.
let g = Graph::from(e);

// Choose an edge.
let (x, y) = (g.vertex("A"), g.vertex("B"));

// Check edge.
assert!(g.is_neighbor(x, y));
assert!(Ne!(g, x).any(|z| z == y))
Source

fn degree(&self, x: usize) -> usize

Degree of a vertex.

Computes the degree of a given vertex, i.e. $|Ne(\mathcal{G}, X)|$.

§Panics

The vertex index does not exist in the graph.

§Examples
use causal_hub::prelude::*;

// Define edge set.
let e = EdgeList::from([("A", "B"), ("C", "A"), ("A", "A")]);

// Build a graph.
let mut g = Graph::from(e);

// Choose a vertex.
let x = g.vertex("A");

// Check degree.
assert_eq!(g.degree(x), 3);
assert_eq!(g.degree(x), Ne!(g, x).count());

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§