From 6a0c426c77ed36a16b31e2df06336215a1bdd8f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Fri, 3 Jul 2026 21:43:55 +0200 Subject: [PATCH 1/7] Rename find_path* algorithms to dfs_find_path* --- src/algorithms.rs | 6 +++--- src/testing/find_path_testing.rs | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/algorithms.rs b/src/algorithms.rs index a2620b8..730ed4c 100644 --- a/src/algorithms.rs +++ b/src/algorithms.rs @@ -261,14 +261,14 @@ where (visited, None) } -pub fn find_path(graph: &G, source: G::Vertex, target: G::Vertex) -> Option> +pub fn dfs_find_path(graph: &G, source: G::Vertex, target: G::Vertex) -> Option> where G: GraphTopology, { - find_path_where(graph, source, |v| v == target) + dfs_find_path_where(graph, source, |v| v == target) } -pub fn find_path_where(graph: &G, source: G::Vertex, predicate: P) -> Option> +pub fn dfs_find_path_where(graph: &G, source: G::Vertex, predicate: P) -> Option> where G: GraphTopology, P: Fn(G::Vertex) -> bool, diff --git a/src/testing/find_path_testing.rs b/src/testing/find_path_testing.rs index c7cfbdc..ead7839 100644 --- a/src/testing/find_path_testing.rs +++ b/src/testing/find_path_testing.rs @@ -7,7 +7,7 @@ macro_rules! find_path_tests { let mut graph = <$T>::new(); let v = graph.add_vertex(); assert_eq!( - $crate::algorithms::find_path(&graph, v, v), + $crate::algorithms::dfs_find_path(&graph, v, v), Some(vec![]), "path from source to itself should be empty" ); @@ -17,7 +17,7 @@ macro_rules! find_path_tests { fn find_path_disconnected() { let (graph, vertices) = make_test_graph_disconnected(); assert_eq!( - $crate::algorithms::find_path(&graph, vertices[0], vertices[1]), + $crate::algorithms::dfs_find_path(&graph, vertices[0], vertices[1]), None, "no path should exist to disconnected vertex" ); @@ -30,7 +30,7 @@ macro_rules! find_path_tests { let v1 = graph.add_vertex(); let v2 = graph.add_vertex(); let e = graph.add_edge(v1, v2); - let path = $crate::algorithms::find_path(&graph, v1, v2) + let path = $crate::algorithms::dfs_find_path(&graph, v1, v2) .expect("path should exist between adjacent vertices"); assert_eq!( path.len(), @@ -43,7 +43,7 @@ macro_rules! find_path_tests { #[test] fn find_path() { let (graph, vertices, _, _) = make_test_graph(); - let path = $crate::algorithms::find_path(&graph, vertices[0], vertices[9]) + let path = $crate::algorithms::dfs_find_path(&graph, vertices[0], vertices[9]) .expect(&format!( "path should exist between connected vertices {:?} and {:?}", vertices[0], vertices[9] @@ -57,7 +57,7 @@ macro_rules! find_path_tests { let mut graph = <$T>::new(); let v = graph.add_vertex(); assert_eq!( - $crate::algorithms::find_path_where(&graph, v, |u| u == v), + $crate::algorithms::dfs_find_path_where(&graph, v, |u| u == v), Some(vec![]), "path from source to itself should be empty" ); @@ -67,7 +67,7 @@ macro_rules! find_path_tests { fn find_path_where_disconnected() { let (graph, vertices) = make_test_graph_disconnected(); assert_eq!( - $crate::algorithms::find_path_where(&graph, vertices[0], |v| v == vertices[1]), + $crate::algorithms::dfs_find_path_where(&graph, vertices[0], |v| v == vertices[1]), None, "no path should exist to disconnected vertex" ); @@ -77,7 +77,7 @@ macro_rules! find_path_tests { fn find_path_where_no_match() { let (graph, vertices, _, _) = make_test_graph(); assert_eq!( - $crate::algorithms::find_path_where(&graph, vertices[0], |_| false), + $crate::algorithms::dfs_find_path_where(&graph, vertices[0], |_| false), None, "no path should exist when predicate never matches" ); @@ -87,7 +87,7 @@ macro_rules! find_path_tests { fn find_path_where() { let (graph, vertices, _, _) = make_test_graph(); let path = - $crate::algorithms::find_path_where(&graph, vertices[0], |v| v == vertices[9]) + $crate::algorithms::dfs_find_path_where(&graph, vertices[0], |v| v == vertices[9]) .expect(&format!( "path should exist between connected vertices {:?} and {:?}", vertices[0], vertices[9] -- 2.43.0 From 2d400628f74d4b4d6c8d1b9442ef7b133a2bf8f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Fri, 3 Jul 2026 21:49:28 +0200 Subject: [PATCH 2/7] Re-publish AppendGraph and Graph in models --- src/models.rs | 3 +++ tests/bfs.rs | 4 ++-- tests/dfs.rs | 4 ++-- tests/dijkstra.rs | 4 ++-- tests/find_path.rs | 4 ++-- tests/maps.rs | 8 ++++---- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/models.rs b/src/models.rs index f1601bc..a7dae87 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,2 +1,5 @@ pub mod append_graph; pub mod graph; + +pub use append_graph::AppendGraph; +pub use graph::Graph; diff --git a/tests/bfs.rs b/tests/bfs.rs index 52996e5..293ea12 100644 --- a/tests/bfs.rs +++ b/tests/bfs.rs @@ -1,12 +1,12 @@ mod append_graph_tests { - use grapherity::models::append_graph::AppendGraph; + use grapherity::models::AppendGraph; grapherity::graph_topology_test_fixtures!(AppendGraph); grapherity::bfs_tests!(AppendGraph); } mod graph_tests { - use grapherity::models::graph::Graph; + use grapherity::models::Graph; grapherity::graph_topology_test_fixtures!(Graph); grapherity::bfs_tests!(Graph); diff --git a/tests/dfs.rs b/tests/dfs.rs index 4524c57..ec7e039 100644 --- a/tests/dfs.rs +++ b/tests/dfs.rs @@ -1,12 +1,12 @@ mod append_graph_tests { - use grapherity::models::append_graph::AppendGraph; + use grapherity::models::AppendGraph; grapherity::graph_topology_test_fixtures!(AppendGraph); grapherity::dfs_tests!(AppendGraph); } mod graph_tests { - use grapherity::models::graph::Graph; + use grapherity::models::Graph; grapherity::graph_topology_test_fixtures!(Graph); grapherity::dfs_tests!(Graph); diff --git a/tests/dijkstra.rs b/tests/dijkstra.rs index 5a54b49..b495546 100644 --- a/tests/dijkstra.rs +++ b/tests/dijkstra.rs @@ -1,12 +1,12 @@ mod append_graph_tests { - use grapherity::models::append_graph::AppendGraph; + use grapherity::models::AppendGraph; grapherity::graph_topology_test_fixtures!(AppendGraph); grapherity::dijkstra_tests!(AppendGraph); } mod graph_tests { - use grapherity::models::graph::Graph; + use grapherity::models::Graph; grapherity::graph_topology_test_fixtures!(Graph); grapherity::dijkstra_tests!(Graph); diff --git a/tests/find_path.rs b/tests/find_path.rs index c46085e..7f296c8 100644 --- a/tests/find_path.rs +++ b/tests/find_path.rs @@ -1,12 +1,12 @@ mod append_graph_tests { - use grapherity::models::append_graph::AppendGraph; + use grapherity::models::AppendGraph; grapherity::graph_topology_test_fixtures!(AppendGraph); grapherity::find_path_tests!(AppendGraph); } mod graph_tests { - use grapherity::models::graph::Graph; + use grapherity::models::Graph; grapherity::graph_topology_test_fixtures!(Graph); grapherity::find_path_tests!(Graph); diff --git a/tests/maps.rs b/tests/maps.rs index 0b4e2f7..b936db9 100644 --- a/tests/maps.rs +++ b/tests/maps.rs @@ -1,24 +1,24 @@ mod append_graph_vertex_map_tests { - use grapherity::models::append_graph::AppendGraph; + use grapherity::models::AppendGraph; grapherity::vertex_map_tests!(AppendGraph); } mod append_graph_edge_map_tests { - use grapherity::models::append_graph::AppendGraph; + use grapherity::models::AppendGraph; grapherity::edge_map_tests!(AppendGraph); } mod graph_vertex_map_tests { - use grapherity::models::graph::Graph; + use grapherity::models::Graph; grapherity::vertex_map_tests!(Graph); grapherity::vertex_map_deletion_tests!(Graph); } mod graph_edge_map_tests { - use grapherity::models::graph::Graph; + use grapherity::models::Graph; grapherity::edge_map_tests!(Graph); grapherity::edge_map_deletion_tests!(Graph); -- 2.43.0 From 6d2d1de8eae33741f03b29085d8165b97173d30e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Fri, 3 Jul 2026 22:49:14 +0200 Subject: [PATCH 3/7] Hide testing macros from docs --- src/testing/bfs_testing.rs | 1 + src/testing/dfs_testing.rs | 1 + src/testing/dijkstra_testing.rs | 1 + src/testing/find_path_testing.rs | 1 + src/testing/graph_topology_testing.rs | 3 +++ src/testing/maps_testing.rs | 4 ++++ 6 files changed, 11 insertions(+) diff --git a/src/testing/bfs_testing.rs b/src/testing/bfs_testing.rs index 532d289..709ac9f 100644 --- a/src/testing/bfs_testing.rs +++ b/src/testing/bfs_testing.rs @@ -1,3 +1,4 @@ +#[doc(hidden)] #[macro_export] macro_rules! bfs_tests { ($T:ty) => { diff --git a/src/testing/dfs_testing.rs b/src/testing/dfs_testing.rs index 205f020..78238c8 100644 --- a/src/testing/dfs_testing.rs +++ b/src/testing/dfs_testing.rs @@ -1,3 +1,4 @@ +#[doc(hidden)] #[macro_export] macro_rules! dfs_tests { ($T:ty) => { diff --git a/src/testing/dijkstra_testing.rs b/src/testing/dijkstra_testing.rs index bbb2579..3815c4e 100644 --- a/src/testing/dijkstra_testing.rs +++ b/src/testing/dijkstra_testing.rs @@ -1,3 +1,4 @@ +#[doc(hidden)] #[macro_export] macro_rules! dijkstra_tests { ($T:ty) => { diff --git a/src/testing/find_path_testing.rs b/src/testing/find_path_testing.rs index ead7839..c9c4e42 100644 --- a/src/testing/find_path_testing.rs +++ b/src/testing/find_path_testing.rs @@ -1,3 +1,4 @@ +#[doc(hidden)] #[macro_export] macro_rules! find_path_tests { ($T:ty) => { diff --git a/src/testing/graph_topology_testing.rs b/src/testing/graph_topology_testing.rs index de09aaf..400290c 100644 --- a/src/testing/graph_topology_testing.rs +++ b/src/testing/graph_topology_testing.rs @@ -1,3 +1,4 @@ +#[doc(hidden)] #[macro_export] macro_rules! graph_topology_test_fixtures { ($T:ty) => { @@ -101,6 +102,7 @@ macro_rules! graph_topology_test_fixtures { }; } +#[doc(hidden)] #[macro_export] macro_rules! graph_topology_tests { ($T:ty) => { @@ -748,6 +750,7 @@ macro_rules! graph_topology_tests { }; } +#[doc(hidden)] #[macro_export] macro_rules! graph_topology_deletion_tests { ($T:ty) => { diff --git a/src/testing/maps_testing.rs b/src/testing/maps_testing.rs index fdac415..202b2db 100644 --- a/src/testing/maps_testing.rs +++ b/src/testing/maps_testing.rs @@ -1,3 +1,4 @@ +#[doc(hidden)] #[macro_export] macro_rules! vertex_map_tests { ($T:ty) => { @@ -78,6 +79,7 @@ macro_rules! vertex_map_tests { }; } +#[doc(hidden)] #[macro_export] macro_rules! vertex_map_deletion_tests { ($T:ty) => { @@ -130,6 +132,7 @@ macro_rules! vertex_map_deletion_tests { }; } +#[doc(hidden)] #[macro_export] macro_rules! edge_map_tests { ($T:ty) => { @@ -222,6 +225,7 @@ macro_rules! edge_map_tests { }; } +#[doc(hidden)] #[macro_export] macro_rules! edge_map_deletion_tests { ($T:ty) => { -- 2.43.0 From e3a24894f63d0a22ea6ed97e4a2fd902be955888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Mon, 6 Jul 2026 17:51:15 +0200 Subject: [PATCH 4/7] Changed graph::Vertex and graph::Edge to be public to simplify Graph usage --- src/models/graph.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/models/graph.rs b/src/models/graph.rs index 309d268..15e5b51 100644 --- a/src/models/graph.rs +++ b/src/models/graph.rs @@ -3,9 +3,9 @@ use typed_generational_arena::{Arena, Index}; use crate::maps::{EdgeMap, VertexMap}; use crate::traits::{GraphTopology, GraphTopologyDeletion, IncidenceCursor}; -type Vertex = Index; +pub type Vertex = Index; -type Edge = Index; +pub type Edge = Index; #[derive(Copy, Clone, PartialEq, Eq, Debug)] struct VertexSlot(usize); -- 2.43.0 From 266dee783b968dc8026227415b05a8305ceb3e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Mon, 6 Jul 2026 17:52:42 +0200 Subject: [PATCH 5/7] Rename append_graph::Incidence to Edge to unify public naming --- src/models/append_graph.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/models/append_graph.rs b/src/models/append_graph.rs index 65657f8..2f27194 100644 --- a/src/models/append_graph.rs +++ b/src/models/append_graph.rs @@ -5,9 +5,9 @@ use crate::traits::{GraphTopology, IncidenceCursor}; pub struct Vertex(usize); #[derive(Copy, Clone, PartialEq, Eq, Debug)] -pub struct Incidence(usize); +pub struct Edge(usize); -impl Incidence { +impl Edge { fn normalize(&self) -> Self { Self(self.0 & !1) } @@ -15,22 +15,22 @@ impl Incidence { struct VertexIncidenceHeader { incidence_count: usize, - first_incidence: Option, + first_incidence: Option, } #[derive(Copy, Clone)] struct IncidenceEntry { - next: Option, + next: Option, adjacent: Vertex, } #[derive(Copy, Clone)] pub struct AppendGraphIncidenceCursor { - incidence: Option, + incidence: Option, } impl IncidenceCursor for AppendGraphIncidenceCursor { - fn next(&mut self, graph: &AppendGraph) -> Option<(Vertex, Incidence)> { + fn next(&mut self, graph: &AppendGraph) -> Option<(Vertex, Edge)> { graph.step_incidence(&mut self.incidence) } } @@ -56,15 +56,15 @@ impl AppendGraph { adjacent: v2, }); self.vertices[v1.0].incidence_count += 1; - self.vertices[v1.0].first_incidence = Some(Incidence(self.incidences.len() - 1)); + self.vertices[v1.0].first_incidence = Some(Edge(self.incidences.len() - 1)); } - fn raw_incidences(&self, v: Vertex) -> impl Iterator { + fn raw_incidences(&self, v: Vertex) -> impl Iterator { let mut incidence = self.vertices[v.0].first_incidence; std::iter::from_fn(move || self.step_incidence(&mut incidence)) } - fn step_incidence(&self, incidence: &mut Option) -> Option<(Vertex, Incidence)> { + fn step_incidence(&self, incidence: &mut Option) -> Option<(Vertex, Edge)> { let current = (*incidence)?; let entry = self.incidences[current.0]; *incidence = entry.next; @@ -80,7 +80,7 @@ impl Default for AppendGraph { impl GraphTopology for AppendGraph { type Vertex = Vertex; - type Edge = Incidence; + type Edge = Edge; type IncidenceCursor = AppendGraphIncidenceCursor; fn vertex_count(&self) -> usize { @@ -130,7 +130,7 @@ impl GraphTopology for AppendGraph { } fn edges(&self) -> impl Iterator { - (0..self.incidences.len()).step_by(2).map(Incidence) + (0..self.incidences.len()).step_by(2).map(Edge) } fn incident_edges(&self, v: Self::Vertex) -> impl Iterator { @@ -158,7 +158,7 @@ impl GraphTopology for AppendGraph { fn add_edge(&mut self, v1: Self::Vertex, v2: Self::Vertex) -> Self::Edge { self.add_incidence(v1, v2); self.add_incidence(v2, v1); - Incidence(self.incidences.len() - 2) + Edge(self.incidences.len() - 2) } } @@ -175,7 +175,7 @@ mod tests { let v1 = graph.add_vertex(); let v2 = graph.add_vertex(); let e = graph.add_edge(v1, v2); - let f = Incidence(e.0 + 1); + let f = Edge(e.0 + 1); let (u1, u2) = graph.incident_vertices(f); assert!( (u1 == v1 && u2 == v2) || (u1 == v2 && u2 == v1), -- 2.43.0 From 1446103d3466d22ec0c6b2b36a6be1b75c2ab62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Mon, 6 Jul 2026 18:49:02 +0200 Subject: [PATCH 6/7] Add concrete type aliases of VertexMap and EdgeMap for Graph and AppendGraph --- src/models.rs | 4 ++-- src/models/append_graph.rs | 3 +++ src/models/graph.rs | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/models.rs b/src/models.rs index a7dae87..5f556aa 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,5 +1,5 @@ pub mod append_graph; pub mod graph; -pub use append_graph::AppendGraph; -pub use graph::Graph; +pub use append_graph::{AppendGraph, AppendGraphEdgeMap, AppendGraphVertexMap}; +pub use graph::{Graph, GraphEdgeMap, GraphVertexMap}; diff --git a/src/models/append_graph.rs b/src/models/append_graph.rs index 2f27194..9ccfef7 100644 --- a/src/models/append_graph.rs +++ b/src/models/append_graph.rs @@ -7,6 +7,9 @@ pub struct Vertex(usize); #[derive(Copy, Clone, PartialEq, Eq, Debug)] pub struct Edge(usize); +pub type AppendGraphVertexMap = VertexMap; +pub type AppendGraphEdgeMap = EdgeMap; + impl Edge { fn normalize(&self) -> Self { Self(self.0 & !1) diff --git a/src/models/graph.rs b/src/models/graph.rs index 15e5b51..ed86205 100644 --- a/src/models/graph.rs +++ b/src/models/graph.rs @@ -4,9 +4,11 @@ use crate::maps::{EdgeMap, VertexMap}; use crate::traits::{GraphTopology, GraphTopologyDeletion, IncidenceCursor}; pub type Vertex = Index; - pub type Edge = Index; +pub type GraphVertexMap = VertexMap; +pub type GraphEdgeMap = EdgeMap; + #[derive(Copy, Clone, PartialEq, Eq, Debug)] struct VertexSlot(usize); -- 2.43.0 From c8dda39b98424941681db815f8c41a872d434489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Mon, 6 Jul 2026 18:50:22 +0200 Subject: [PATCH 7/7] Update package version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a994a96..e4fc4a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "grapherity" -version = "0.1.0" +version = "0.2.0" authors = ["Stefan Müller"] edition = "2024" rust-version = "1.85.0" -- 2.43.0