From a7346bd7828c1b81d66013e08b4d8adf90a4542e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Thu, 6 Aug 2026 23:01:10 +0200 Subject: [PATCH] Rename EntityMap to ElementMap (tests not yet updated) --- src/algorithms.rs | 28 ++++++++++++++-------------- src/lib.rs | 4 ++-- src/maps.rs | 18 +++++++++--------- src/models/append_graph.rs | 18 +++++++++--------- src/models/graph.rs | 18 +++++++++--------- src/testing/bfs_testing.rs | 4 ++-- src/testing/dfs_testing.rs | 6 +++--- src/testing/dijkstra_testing.rs | 10 +++++----- src/traits.rs | 10 +++++----- 9 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/algorithms.rs b/src/algorithms.rs index 2da4d09..7719e0f 100644 --- a/src/algorithms.rs +++ b/src/algorithms.rs @@ -33,15 +33,15 @@ use std::cmp::Reverse; use std::collections::VecDeque; use std::hash::Hash; -use crate::maps::EntityMap; +use crate::maps::ElementMap; use crate::traits::{GraphTopology, Incidence, IncidenceCursor}; /// Return data type for [`dijkstra`] and [`dijkstra_unweighted`]. pub struct DijkstraResult { /// Vertex map of minimum distances from a given `source` vertex. - pub distances: EntityMap>, + pub distances: ElementMap>, /// Vertex map of predecessors on some shortest path from a given `source` vertex. - pub predecessors: EntityMap>, + pub predecessors: ElementMap>, } // TODO: Generalize the return type of the weight function. @@ -128,7 +128,7 @@ pub fn dijkstra_distances( graph: &G, source: G::Vertex, weights: W, -) -> EntityMap> +) -> ElementMap> where G: GraphTopology, G::Vertex: Hash, @@ -209,7 +209,7 @@ where pub fn dijkstra_distances_unweighted( graph: &G, source: G::Vertex, -) -> EntityMap> +) -> ElementMap> where G: GraphTopology, G::Vertex: Hash, @@ -222,7 +222,7 @@ fn dijkstra_impl( source: G::Vertex, weights: W, mut on_relax: F, -) -> EntityMap> +) -> ElementMap> where G: GraphTopology, G::Vertex: Hash, @@ -255,9 +255,9 @@ where /// Return data type for [`bfs`]. pub struct BfsResult { /// Vertex map of minimum distances from a given `source` vertex. - pub distances: EntityMap>, + pub distances: ElementMap>, /// Vertex map of predecessors on some shortest path from a given `source` vertex. - pub predecessors: EntityMap>, + pub predecessors: ElementMap>, } /// [Breadth-first search] traversal from `source`, returns distances and predecessors. @@ -333,7 +333,7 @@ where /// ``` /// /// [Breadth-first search]: https://en.wikipedia.org/wiki/Breadth-first_search -pub fn bfs_distances(graph: &G, source: G::Vertex) -> EntityMap> +pub fn bfs_distances(graph: &G, source: G::Vertex) -> ElementMap> where G: GraphTopology, { @@ -415,7 +415,7 @@ where } struct BfsImplResult { - distances: EntityMap>, + distances: ElementMap>, found: Option<(V, u32)>, } @@ -455,9 +455,9 @@ where /// Return data type for [`dfs`]. pub struct DfsResult { /// Vertex map indicating which vertices were visited during the search. - pub visited: EntityMap, + pub visited: ElementMap, /// Vertex map of predecessors on the DFS tree path from a given `source` vertex. - pub predecessors: EntityMap>, + pub predecessors: ElementMap>, } /// [Depth-first search] traversal from `source`, returns visited vertices and predecessors. @@ -533,7 +533,7 @@ where /// ``` /// /// [Depth-first search]: https://en.wikipedia.org/wiki/Depth-first_search -pub fn dfs_visited(graph: &G, source: G::Vertex) -> EntityMap +pub fn dfs_visited(graph: &G, source: G::Vertex) -> ElementMap where G: GraphTopology, { @@ -613,7 +613,7 @@ where } struct DfsImplResult { - visited: EntityMap, + visited: ElementMap, found: Option, } diff --git a/src/lib.rs b/src/lib.rs index 496bb4a..946e3f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ //! //! * Undirected graph types [`Graph`] and [`AppendGraph`] built on a flat, index-based adjacency //! list, -//! * [`EntityMap`] to freely associate custom data with vertices and edges, +//! * [`ElementMap`] to freely associate custom data with vertices and edges, //! * Connectivity and pathing algorithms: [Dijkstra's algorithm], [DFS], and [BFS] in different //! variants, //! * Exposed [`traits`] to implement custom graph data structures or algorithms. @@ -118,7 +118,7 @@ //! [BFS]: crate::algorithms::bfs //! [Dijkstra's algorithm]: crate::algorithms::dijkstra //! [DFS]: crate::algorithms::dfs -//! [`EntityMap`]: crate::maps::EntityMap +//! [`ElementMap`]: crate::maps::ElementMap //! [`AppendGraph`]: crate::models::AppendGraph //! [`Graph`]: crate::models::Graph //! [`GraphTopology`]: crate::traits::GraphTopology diff --git a/src/maps.rs b/src/maps.rs index 1aaa5a5..f6ddf0f 100644 --- a/src/maps.rs +++ b/src/maps.rs @@ -1,30 +1,30 @@ //! Provides maps to associate custom data to graph vertices and edges. //! -//! [`EntityMap`] provides a copy-on-write, [`Vec`]-backed map to associate data to either all +//! [`ElementMap`] provides a copy-on-write, [`Vec`]-backed map to associate data to either all //! vertices or all edges in a graph. use std::ops::{Index, IndexMut}; /// A map to associate custom data to graph vertices or edges. /// -/// This map uses raw entity indices to associate homogenous custom data of type `T` to graph +/// This map uses raw element indices to associate homogenous custom data of type `T` to graph /// vertices or edges. The implementation uses a [`Vec`], allocating contiguous slots for the data, -/// which means that the provided index conversion function should map entities to contiguous +/// which means that the provided index conversion function should map elements to contiguous /// indices, or indices with relatively few gaps. /// /// Data allocation happens as copy-on-write, i.e. the backing [`Vec`] is only resized if a value is /// written beyond current capacity, but the `default` value can transparently be read. No bound or -/// validity checks are performed by the map on the provided entity handles. +/// validity checks are performed by the map on the provided element handles. /// -/// Use [`GraphTopology::vertex_map`] or [`GraphTopology::edge_map`] to obtain an `EntityMap` for +/// Use [`GraphTopology::vertex_map`] or [`GraphTopology::edge_map`] to obtain an `ElementMap` for /// vertices or edges, respectively. -pub struct EntityMap { +pub struct ElementMap { data: Vec, default: T, to_index: fn(E) -> usize, } -impl EntityMap { +impl ElementMap { /// Creates a new map with the given `default` value, an index conversion function `to_index`, /// and an initial `capacity`. pub fn new(default: T, to_index: fn(E) -> usize, capacity: usize) -> Self { @@ -53,7 +53,7 @@ impl EntityMap { } } -impl Index for EntityMap { +impl Index for ElementMap { type Output = T; fn index(&self, e: E) -> &T { @@ -66,7 +66,7 @@ impl Index for EntityMap { } } -impl IndexMut for EntityMap { +impl IndexMut for ElementMap { fn index_mut(&mut self, e: E) -> &mut T { let i = (self.to_index)(e); if i >= self.data.len() { diff --git a/src/models/append_graph.rs b/src/models/append_graph.rs index d3f37fe..ac637ea 100644 --- a/src/models/append_graph.rs +++ b/src/models/append_graph.rs @@ -1,6 +1,6 @@ //! [`AppendGraph`], an undirected graph topology supporting addition only. -use crate::maps::EntityMap; +use crate::maps::ElementMap; use crate::traits::{GraphTopology, GraphTopologyAddition, Incidence, IncidenceCursor}; /// An opaque handle identifying a vertex in an [`AppendGraph`]. @@ -17,11 +17,11 @@ pub struct Vertex(usize); #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] pub struct Edge(usize); -/// An [`EntityMap`] for [`AppendGraph`] vertices. -pub type AppendGraphVertexMap = EntityMap; +/// An [`ElementMap`] for [`AppendGraph`] vertices. +pub type AppendGraphVertexMap = ElementMap; -/// An [`EntityMap`] for [`AppendGraph`] edges. -pub type AppendGraphEdgeMap = EntityMap; +/// An [`ElementMap`] for [`AppendGraph`] edges. +pub type AppendGraphEdgeMap = ElementMap; /// An [`Incidence`] for [`AppendGraph`]. pub type AppendGraphIncidence = Incidence; @@ -147,16 +147,16 @@ impl GraphTopology for AppendGraph { self.vertices.len() } - fn vertex_map(&self, default: T) -> EntityMap { - EntityMap::new(default, |v| v.0, self.vertex_capacity()) + fn vertex_map(&self, default: T) -> ElementMap { + ElementMap::new(default, |v| v.0, self.vertex_capacity()) } fn edge_count(&self) -> usize { self.incidences.len() / 2 } - fn edge_map(&self, default: T) -> EntityMap { - EntityMap::new(default, |e| e.0 / 2, self.edge_capacity()) + fn edge_map(&self, default: T) -> ElementMap { + ElementMap::new(default, |e| e.0 / 2, self.edge_capacity()) } fn degree(&self, v: Self::Vertex) -> usize { diff --git a/src/models/graph.rs b/src/models/graph.rs index d0b37c4..c47ec36 100644 --- a/src/models/graph.rs +++ b/src/models/graph.rs @@ -2,7 +2,7 @@ use typed_generational_arena::{Arena, Index}; -use crate::maps::EntityMap; +use crate::maps::ElementMap; use crate::traits::{ GraphTopology, GraphTopologyAddition, GraphTopologyDeletion, Incidence, IncidenceCursor, }; @@ -19,11 +19,11 @@ pub type Vertex = Index; /// deleted. Obtain via graph methods like [`Graph::add_edge`] and [`Graph::edges`]. pub type Edge = Index; -/// An [`EntityMap`] for [`Graph`] vertices. -pub type GraphVertexMap = EntityMap; +/// An [`ElementMap`] for [`Graph`] vertices. +pub type GraphVertexMap = ElementMap; -/// An [`EntityMap`] for [`Graph`] edges. -pub type GraphEdgeMap = EntityMap; +/// An [`ElementMap`] for [`Graph`] edges. +pub type GraphEdgeMap = ElementMap; /// An [`Incidence`] for [`Graph`]. pub type GraphIncidence = Incidence; @@ -241,16 +241,16 @@ impl GraphTopology for Graph { self.vertices.len() } - fn vertex_map(&self, default: T) -> EntityMap { - EntityMap::new(default, |v| v.arr_idx(), self.vertex_capacity()) + fn vertex_map(&self, default: T) -> ElementMap { + ElementMap::new(default, |v| v.arr_idx(), self.vertex_capacity()) } fn edge_count(&self) -> usize { self.incidences.len() / 2 } - fn edge_map(&self, default: T) -> EntityMap { - EntityMap::new(default, |e| e.arr_idx() / 2, self.edge_capacity()) + fn edge_map(&self, default: T) -> ElementMap { + ElementMap::new(default, |e| e.arr_idx() / 2, self.edge_capacity()) } fn degree(&self, v: Self::Vertex) -> usize { diff --git a/src/testing/bfs_testing.rs b/src/testing/bfs_testing.rs index b5e4365..63f8fae 100644 --- a/src/testing/bfs_testing.rs +++ b/src/testing/bfs_testing.rs @@ -194,7 +194,7 @@ macro_rules! bfs_tests { } fn assert_bfs_distances( - distances: &$crate::maps::EntityMap< + distances: &$crate::maps::ElementMap< <$T as $crate::traits::GraphTopology>::Vertex, Option, >, @@ -222,7 +222,7 @@ macro_rules! bfs_tests { } fn assert_bfs_predecessors( - predecessors: &$crate::maps::EntityMap< + predecessors: &$crate::maps::ElementMap< <$T as $crate::traits::GraphTopology>::Vertex, Option<<$T as $crate::traits::GraphTopology>::Vertex>, >, diff --git a/src/testing/dfs_testing.rs b/src/testing/dfs_testing.rs index b89ff30..61f4944 100644 --- a/src/testing/dfs_testing.rs +++ b/src/testing/dfs_testing.rs @@ -163,7 +163,7 @@ macro_rules! dfs_tests { } fn assert_dfs_visited( - visited: &$crate::maps::EntityMap<<$T as $crate::traits::GraphTopology>::Vertex, bool>, + visited: &$crate::maps::ElementMap<<$T as $crate::traits::GraphTopology>::Vertex, bool>, vertices: &[<$T as $crate::traits::GraphTopology>::Vertex], ) { for i in 0..10 { @@ -177,8 +177,8 @@ macro_rules! dfs_tests { fn assert_dfs_predecessors( graph: &$T, - visited: &$crate::maps::EntityMap<<$T as $crate::traits::GraphTopology>::Vertex, bool>, - predecessors: &$crate::maps::EntityMap< + visited: &$crate::maps::ElementMap<<$T as $crate::traits::GraphTopology>::Vertex, bool>, + predecessors: &$crate::maps::ElementMap< <$T as $crate::traits::GraphTopology>::Vertex, Option<<$T as $crate::traits::GraphTopology>::Vertex>, >, diff --git a/src/testing/dijkstra_testing.rs b/src/testing/dijkstra_testing.rs index 34cbe79..d015ca6 100644 --- a/src/testing/dijkstra_testing.rs +++ b/src/testing/dijkstra_testing.rs @@ -131,7 +131,7 @@ macro_rules! dijkstra_tests { } fn assert_distances_single_vertex( - distances: &$crate::maps::EntityMap< + distances: &$crate::maps::ElementMap< <$T as $crate::traits::GraphTopology>::Vertex, Option, >, @@ -160,7 +160,7 @@ macro_rules! dijkstra_tests { } fn assert_distances_disconnected( - distances: &$crate::maps::EntityMap< + distances: &$crate::maps::ElementMap< <$T as $crate::traits::GraphTopology>::Vertex, Option, >, @@ -204,7 +204,7 @@ macro_rules! dijkstra_tests { } fn assert_distances_test_graph( - distances: &$crate::maps::EntityMap< + distances: &$crate::maps::ElementMap< <$T as $crate::traits::GraphTopology>::Vertex, Option, >, @@ -261,7 +261,7 @@ macro_rules! dijkstra_tests { } fn assert_distances_unweighted_test_graph( - distances: &$crate::maps::EntityMap< + distances: &$crate::maps::ElementMap< <$T as $crate::traits::GraphTopology>::Vertex, Option, >, @@ -302,7 +302,7 @@ macro_rules! dijkstra_tests { <$T as $crate::traits::GraphTopology>::Edge, >, >; 10], - $crate::maps::EntityMap<<$T as $crate::traits::GraphTopology>::Edge, u32>, + $crate::maps::ElementMap<<$T as $crate::traits::GraphTopology>::Edge, u32>, ) { use $crate::traits::GraphTopology; let (graph, vertices, edges, incidences) = make_test_graph(); diff --git a/src/traits.rs b/src/traits.rs index a625d06..f459cfa 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -1,6 +1,6 @@ //! Core traits for undirected graph topologies. -use crate::maps::EntityMap; +use crate::maps::ElementMap; /// A trait representing an undirected graph topology. /// @@ -44,7 +44,7 @@ pub trait GraphTopology { /// Returns the number of vertices in the graph. fn vertex_count(&self) -> usize; - /// Creates and returns an [`EntityMap`] for the vertices with every slot initialised to + /// Creates and returns an [`ElementMap`] for the vertices with every slot initialised to /// `default`. /// /// # Examples @@ -65,12 +65,12 @@ pub trait GraphTopology { /// labels[v2] = "b"; /// assert_eq!(labels[v2], "b"); /// ``` - fn vertex_map(&self, default: T) -> EntityMap; + fn vertex_map(&self, default: T) -> ElementMap; /// Returns the number of edges in the graph. fn edge_count(&self) -> usize; - /// Creates and returns an [`EntityMap`] for the edges with every slot initialised to `default`. + /// Creates and returns an [`ElementMap`] for the edges with every slot initialised to `default`. /// /// # Examples /// @@ -92,7 +92,7 @@ pub trait GraphTopology { /// weights[e2] = 2; /// assert_eq!(weights[e2], 2); /// ``` - fn edge_map(&self, default: T) -> EntityMap; + fn edge_map(&self, default: T) -> ElementMap; /// Returns the degree of `v`, i.e. the number of incident edges, where each loop contributes 2. ///