Skip to main content

Graph

Trait Graph 

Source
pub trait Graph {
    type NodeId: Copy + Eq + Hash + Ord + Debug;
    type EdgeId: Copy + Eq + Hash + Ord + Debug;
    type Hasher: BuildHasher + Default;
    type Node<'graph>: Node<'graph, Graph = Self>
       where Self: 'graph;
    type Edge<'graph>: Edge<'graph, Graph = Self>
       where Self: 'graph;

    // Required methods
    fn get_node(&self, id: Self::NodeId) -> Option<Self::Node<'_>>;
    fn get_edge(&self, id: Self::EdgeId) -> Option<Self::Edge<'_>>;
    fn nodes(&self) -> impl Iterator<Item = Self::Node<'_>> + '_;
    fn edges(&self) -> impl Iterator<Item = Self::Edge<'_>> + '_;

    // Provided methods
    fn dfs(&self, root: Self::NodeId) -> DfsIter<'_, Directed, Self> 
       where Self: Sized { ... }
    fn undirected_dfs(
        &self,
        root: Self::NodeId,
    ) -> DfsIter<'_, Undirected, Self> 
       where Self: Sized { ... }
}
Expand description

A typed graph container.

The graph is parameterized by:

  • NodeId: strongly typed node identifier
  • EdgeId: strongly typed edge identifier

Required Associated Types§

Source

type NodeId: Copy + Eq + Hash + Ord + Debug

Source

type EdgeId: Copy + Eq + Hash + Ord + Debug

Source

type Hasher: BuildHasher + Default

Hasher backing the graph’s incident-edge sets and DFS bookkeeping.

The trait is generic over the hasher rather than pinning a concrete one: picking a fixed-seed hasher (e.g. rustc_hash::FxBuildHasher) makes predecessors()/successors() iteration order deterministic across runs, whereas the std default (RandomState) reseeds per process.

Source

type Node<'graph>: Node<'graph, Graph = Self> where Self: 'graph

Source

type Edge<'graph>: Edge<'graph, Graph = Self> where Self: 'graph

Required Methods§

Source

fn get_node(&self, id: Self::NodeId) -> Option<Self::Node<'_>>

Gets a node in the graph by its identifier, if it exists.

Source

fn get_edge(&self, id: Self::EdgeId) -> Option<Self::Edge<'_>>

Source

fn nodes(&self) -> impl Iterator<Item = Self::Node<'_>> + '_

Iterates over all nodes in insertion identifier order.

Source

fn edges(&self) -> impl Iterator<Item = Self::Edge<'_>> + '_

Iterates over all edges in insertion identifier order.

Provided Methods§

Source

fn dfs(&self, root: Self::NodeId) -> DfsIter<'_, Directed, Self>
where Self: Sized,

A dfs iterator over the graph starting from the root, if present.

Source

fn undirected_dfs(&self, root: Self::NodeId) -> DfsIter<'_, Undirected, Self>
where Self: Sized,

A dfs iterator over the graph treating edges as undirected.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<NodeId: Identifier, EdgeId: Identifier, NodeData, EdgeData> Graph for OwningGraph<NodeId, EdgeId, NodeData, EdgeData>

Source§

type NodeId = NodeId

Source§

type EdgeId = EdgeId

Source§

type Hasher = RandomState

Source§

type Node<'a> = NodeRef<'a, NodeId, EdgeId, NodeData, EdgeData> where Self: 'a

Source§

type Edge<'a> = EdgeRef<'a, NodeId, EdgeId, NodeData, EdgeData> where Self: 'a