From ab830ed221bee02414d9f1ee0a0495a749aa3069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Wed, 22 Apr 2026 14:31:11 +0200 Subject: [PATCH] Rename Graph to AppendGraph for future other graph models --- src/models.rs | 36 ++++++++++++++++++------------------ tests/dijkstra.rs | 10 +++++----- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/models.rs b/src/models.rs index 23a0809..e98ca63 100644 --- a/src/models.rs +++ b/src/models.rs @@ -22,7 +22,7 @@ struct IncidenceEntry { neighbor: Vertex, } struct VertexNeighborIterator<'a> { - graph: &'a Graph, + graph: &'a AppendGraph, incidence: Option, } @@ -42,15 +42,15 @@ impl<'a> Iterator for VertexNeighborIterator<'a> { // TODO: Add function to delete vertices. // TODO: Add function to delete edges. // TODO: Add iterator of edges. -pub struct Graph { +pub struct AppendGraph { // TODO: Index 'incidence_headers' by a 'Vertex' instead of 'Vertex.0'? vertices: Vec, incidences: Vec, } -impl Graph { - pub fn new() -> Graph { - Graph { +impl AppendGraph { + pub fn new() -> Self { + Self { vertices: vec![], incidences: vec![], } @@ -66,7 +66,7 @@ impl Graph { } } -impl GraphTopology for Graph { +impl GraphTopology for AppendGraph { type Vertex = Vertex; type Edge = Incidence; @@ -119,14 +119,14 @@ mod tests { #[test] fn add_vertex() { - let mut graph = Graph::new(); + let mut graph = AppendGraph::new(); let v = graph.add_vertex(); assert_ne!(graph.add_vertex(), v, "unexpected duplicate vertex"); } #[test] fn vertex_count_empty() { - let graph = Graph::new(); + let graph = AppendGraph::new(); assert_eq!(graph.vertex_count(), 0, "unexpected vertex count"); } @@ -138,7 +138,7 @@ mod tests { #[test] fn edge_count_empty() { - let graph = Graph::new(); + let graph = AppendGraph::new(); assert_eq!(graph.edge_count(), 0, "unexpected edge count"); } @@ -150,7 +150,7 @@ mod tests { #[test] fn degree_zero() { - let mut graph = Graph::new(); + let mut graph = AppendGraph::new(); let v = graph.add_vertex(); assert_eq!(graph.degree(v), 0, "unexpected non-zero degree"); } @@ -171,7 +171,7 @@ mod tests { #[test] fn are_adjacent_vertex_self() { - let mut graph = Graph::new(); + let mut graph = AppendGraph::new(); let v = graph.add_vertex(); assert_eq!( graph.are_adjacent(v, v), @@ -182,7 +182,7 @@ mod tests { #[test] fn are_adjacent_single_edge() { - let mut graph = Graph::new(); + let mut graph = AppendGraph::new(); let v1 = graph.add_vertex(); let v2 = graph.add_vertex(); assert!(!graph.are_adjacent(v1, v2), "should not be adjacent"); @@ -239,7 +239,7 @@ mod tests { #[test] fn vertices_empty() { - let graph = Graph::new(); + let graph = AppendGraph::new(); assert_eq!( graph.vertices().count(), 0, @@ -264,7 +264,7 @@ mod tests { #[test] fn neighbors_empty() { - let mut graph = Graph::new(); + let mut graph = AppendGraph::new(); let vertex = graph.add_vertex(); assert_eq!( graph.neighbors(vertex).count(), @@ -297,7 +297,7 @@ mod tests { #[test] fn loop_edge() { - let mut graph = Graph::new(); + let mut graph = AppendGraph::new(); let v = graph.add_vertex(); graph.add_edge(v, v); assert_eq!(graph.vertex_count(), 1, "unexpected vertex count"); @@ -325,7 +325,7 @@ mod tests { #[test] fn multiple_edges() { let mult = 3; - let mut graph = Graph::new(); + let mut graph = AppendGraph::new(); let vertices = [graph.add_vertex(), graph.add_vertex()]; for _ in 0..mult { graph.add_edge(vertices[0], vertices[1]); @@ -364,8 +364,8 @@ mod tests { } } - fn make_test_graph() -> (Graph, [Vertex; 10]) { - let mut graph = Graph::new(); + fn make_test_graph() -> (AppendGraph, [Vertex; 10]) { + let mut graph = AppendGraph::new(); let vertices: [Vertex; 10] = core::array::from_fn(|_| graph.add_vertex()); graph.add_edge(vertices[0], vertices[1]); graph.add_edge(vertices[1], vertices[2]); diff --git a/tests/dijkstra.rs b/tests/dijkstra.rs index 6fe87d0..37196da 100644 --- a/tests/dijkstra.rs +++ b/tests/dijkstra.rs @@ -1,10 +1,10 @@ use grapherity::algorithms; -use grapherity::models::Graph; +use grapherity::models::AppendGraph; use grapherity::traits::GraphTopology; #[test] fn dijkstra_single_vertex() { - let mut graph = Graph::new(); + let mut graph = AppendGraph::new(); let v1 = graph.add_vertex(); let (distances, predecessors) = algorithms::dijkstra(&graph, v1); assert_eq!( @@ -30,7 +30,7 @@ fn dijkstra_single_vertex() { #[test] fn dijkstra_disconnected() { - let mut graph = Graph::new(); + let mut graph = AppendGraph::new(); let v1 = graph.add_vertex(); graph.add_vertex(); let (distances, predecessors) = algorithms::dijkstra(&graph, v1); @@ -107,8 +107,8 @@ fn dijkstra() { } } -fn make_test_graph() -> (Graph, [::Vertex; 10]) { - let mut graph = Graph::new(); +fn make_test_graph() -> (AppendGraph, [::Vertex; 10]) { + let mut graph = AppendGraph::new(); let vertices = core::array::from_fn::<_, 10, _>(|_| graph.add_vertex()); graph.add_edge(vertices[0], vertices[1]); graph.add_edge(vertices[1], vertices[2]);