cairo_lang_utils::graph_algos::graph_node

Trait GraphNode

Source
pub trait GraphNode: Sized + Clone {
    type NodeId: PartialEq + Eq + Hash + Clone;

    // Required methods
    fn get_neighbors(&self) -> Vec<Self>;
    fn get_id(&self) -> Self::NodeId;

    // Provided method
    fn get_neighbors_in_given_scc(&self, scc: Vec<Self::NodeId>) -> Vec<Self> { ... }
}
Expand description

A trait for a node in a graph. Note that a GraphNode has to be able to provide its neighbors by itself, without additional information.

Required Associated Types§

Source

type NodeId: PartialEq + Eq + Hash + Clone

The type used to identify the nodes in the graph.

Required Methods§

Source

fn get_neighbors(&self) -> Vec<Self>

Returns a list of the node’s neighbors. Must be stable for the SCC result to be stable. i.e. if the output for a node here doesn’t change between different runs, the computed SCC of the node is guaranteed to also not change.

Source

fn get_id(&self) -> Self::NodeId

Gets the node’s ID.

Provided Methods§

Source

fn get_neighbors_in_given_scc(&self, scc: Vec<Self::NodeId>) -> Vec<Self>

Helper function to get the neighbors of the node, given its SCC. Default-implemented and thus can be used in simple implementations of get_neighbors_in_scc.

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§