pub trait Graph {
// Required methods
fn node_count(&self) -> usize;
fn neighbors(&self, node: usize) -> Vec<usize>;
// Provided method
fn out_degree(&self, node: usize) -> usize { ... }
}Expand description
Owned-neighbor graph adapter. The simplest adapter to implement — each
neighbors(node) call returns a fresh Vec.
Node ids are dense, 0..node_count(). An edge u -> v is expressed by
v appearing in neighbors(u). Duplicates are allowed but operators
assume unique neighbors; deduplicate upstream if needed.
Prefer GraphRef when the operator reads neighbors repeatedly in a hot
loop — allocation cost of owned Vec compounds.
Required Methods§
Sourcefn node_count(&self) -> usize
fn node_count(&self) -> usize
Number of nodes in the graph. Must be stable across calls.
Provided Methods§
Sourcefn out_degree(&self, node: usize) -> usize
fn out_degree(&self, node: usize) -> usize
Number of out-neighbors of node. Default calls neighbors(node).len();
override if out-degree is cheaper to compute without materializing the list.