Trait DirectedGraph

Source
pub trait DirectedGraph:
    BaseGraph
    + DefaultGraph
    + PartialOrdGraph
    + SubGraph {
    type AncestorsIter<'a>: Iterator<Item = usize> + FusedIterator
       where Self: 'a;
    type ParentsIter<'a>: Iterator<Item = usize> + FusedIterator
       where Self: 'a;
    type ChildrenIter<'a>: Iterator<Item = usize> + FusedIterator
       where Self: 'a;
    type DescendantsIter<'a>: Iterator<Item = usize> + FusedIterator
       where Self: 'a;

    // Required methods
    fn ancestors(&self, x: usize) -> Self::AncestorsIter<'_>;
    fn parents(&self, x: usize) -> Self::ParentsIter<'_>;
    fn children(&self, x: usize) -> Self::ChildrenIter<'_>;
    fn descendants(&self, x: usize) -> Self::DescendantsIter<'_>;

    // Provided methods
    fn is_ancestor(&self, x: usize, y: usize) -> bool { ... }
    fn is_parent(&self, x: usize, y: usize) -> bool { ... }
    fn is_child(&self, x: usize, y: usize) -> bool { ... }
    fn is_descendant(&self, x: usize, y: usize) -> bool { ... }
    fn in_degree(&self, x: usize) -> usize { ... }
    fn out_degree(&self, x: usize) -> usize { ... }
}
Expand description

Directed graph trait.

Required Associated Types§

Source

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

Ancestors iterator type.

Source

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

Parents iterator type.

Source

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

Children iterator type.

Source

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

Descendants iterator type.

Required Methods§

Source

fn ancestors(&self, x: usize) -> Self::AncestorsIter<'_>

Ancestors iterator.

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

§Panics

The vertex label 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 = DiGraph::from(e);

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

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

// Use the associated macro 'An!'.
assert!(g.ancestors(x).eq(An!(g, x)));
Source

fn parents(&self, x: usize) -> Self::ParentsIter<'_>

Parents iterator.

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

§Panics

The vertex label 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 = DiGraph::from(e);

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

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

// Use the associated macro 'Pa!'.
assert!(g.parents(x).eq(Pa!(g, x)));
Source

fn children(&self, x: usize) -> Self::ChildrenIter<'_>

Children iterator.

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

§Panics

The vertex label 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 = DiGraph::from(e);

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

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

// Use the associated macro 'Ch!'.
assert!(g.children(x).eq(Ch!(g, x)));
Source

fn descendants(&self, x: usize) -> Self::DescendantsIter<'_>

Descendants iterator.

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

§Panics

The vertex label 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 = DiGraph::from(e);

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

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

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

Provided Methods§

Source

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

Checks ancestor vertices in the graph.

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

§Panics

At least one of the vertex identifiers 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 = DiGraph::from(e);

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

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

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

Checks parent vertices in the graph.

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

§Panics

At least one of the vertex identifiers 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 = DiGraph::from(e);

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

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

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

Checks children vertices in the graph.

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

§Panics

At least one of the vertex identifiers 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 = DiGraph::from(e);

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

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

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

Checks descendant vertices in the graph.

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

§Panics

At least one of the vertex identifiers 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 = DiGraph::from(e);

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

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

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

In-degree of a given vertex.

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

§Panics

The vertex label 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 = DiGraph::from(e);

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

// Check degree.
assert_eq!(g.in_degree(x), 2);
assert_eq!(g.in_degree(x), Pa!(g, x).count());
Source

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

Out-degree of a given vertex.

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

§Panics

The vertex label 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 = DiGraph::from(e);

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

// Check degree.
assert_eq!(g.out_degree(x), 2);
assert_eq!(g.out_degree(x), Ch!(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§

Source§

impl DirectedGraph for DirectedDenseAdjacencyMatrixGraph

Source§

type AncestorsIter<'a> = AncestorsIterator<'a>

Source§

type ParentsIter<'a> = ParentsIterator<'a>

Source§

type ChildrenIter<'a> = ChildrenIterator<'a>

Source§

type DescendantsIter<'a> = DescendantsIterator<'a>