Add GraphTopology trait and use it to interface graph model with algorithm

This commit is contained in:
2026-04-22 14:26:35 +02:00
parent 489ed6d506
commit da9ba7b0ad
5 changed files with 79 additions and 53 deletions
+12
View File
@@ -0,0 +1,12 @@
pub trait GraphTopology {
type Vertex: Copy + Eq;
fn vertex_count(&self) -> usize;
fn edge_count(&self) -> usize;
fn degree(&self, v: Self::Vertex) -> usize;
fn are_adjacent(&self, v1: Self::Vertex, v2: Self::Vertex) -> bool;
fn vertices(&self) -> impl Iterator<Item = Self::Vertex>;
fn neighbors(&self, v: Self::Vertex) -> impl Iterator<Item = Self::Vertex>;
fn add_vertex(&mut self) -> Self::Vertex;
fn add_edge(&mut self, v1: Self::Vertex, v2: Self::Vertex);
}