From fb9dfe8280b23717409553ea9014d2a0766a9972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Fri, 10 Jul 2026 11:58:45 +0200 Subject: [PATCH] Renamed len() to capacity() in EntityMap, VertexMap, and EdgeMap len() is generally expected to describe the number of elements in a collection, but in this case elements beyond len() are accessible without restriction. capacity() is a better name because it describes data storage size. --- src/maps.rs | 14 +++++++------- src/testing/maps_testing.rs | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/maps.rs b/src/maps.rs index b7c24ef..72b8a29 100644 --- a/src/maps.rs +++ b/src/maps.rs @@ -13,9 +13,9 @@ impl VertexMap { } } - // Reads beyond len() are valid and return the default value. - pub fn len(&self) -> usize { - self.inner.len() + // Reads beyond capacity() are valid and return the default value. + pub fn capacity(&self) -> usize { + self.inner.capacity() } pub fn sync>(&mut self, graph: &G) { @@ -48,9 +48,9 @@ impl EdgeMap { } } - // Reads beyond len() are valid and return the default value. - pub fn len(&self) -> usize { - self.inner.len() + // Reads beyond capacity() are valid and return the default value. + pub fn capacity(&self) -> usize { + self.inner.capacity() } pub fn sync>(&mut self, graph: &G) { @@ -87,7 +87,7 @@ impl EntityMap { } } - pub fn len(&self) -> usize { + pub fn capacity(&self) -> usize { self.data.len() } diff --git a/src/testing/maps_testing.rs b/src/testing/maps_testing.rs index 202b2db..4bf9be4 100644 --- a/src/testing/maps_testing.rs +++ b/src/testing/maps_testing.rs @@ -53,16 +53,16 @@ macro_rules! vertex_map_tests { let mut graph = <$T>::new(); graph.add_vertex(); let mut map = graph.vertex_map(42); - let initial_len = map.len(); + let initial_len = map.capacity(); while graph.vertex_capacity() <= initial_len { graph.add_vertex(); } assert!( - map.len() < graph.vertex_capacity(), + map.capacity() < graph.vertex_capacity(), "precondition: map is stale before sync" ); map.sync(&graph); - assert_eq!(map.len(), graph.vertex_capacity()); + assert_eq!(map.capacity(), graph.vertex_capacity()); } #[test] @@ -109,7 +109,7 @@ macro_rules! vertex_map_deletion_tests { let capacity_before = graph.vertex_capacity(); graph.delete_vertex(v2); map.sync(&graph); - assert_eq!(map.len(), capacity_before); + assert_eq!(map.capacity(), capacity_before); assert_eq!(map[v1], 5); } @@ -197,16 +197,16 @@ macro_rules! edge_map_tests { let v2 = graph.add_vertex(); graph.add_edge(v1, v2); let mut map = graph.edge_map(42); - let initial_len = map.len(); + let initial_len = map.capacity(); while graph.edge_capacity() <= initial_len { graph.add_edge(v1, v2); } assert!( - map.len() < graph.edge_capacity(), + map.capacity() < graph.edge_capacity(), "precondition: map is stale before sync" ); map.sync(&graph); - assert_eq!(map.len(), graph.edge_capacity()); + assert_eq!(map.capacity(), graph.edge_capacity()); } #[test] @@ -259,7 +259,7 @@ macro_rules! edge_map_deletion_tests { let capacity_before = graph.edge_capacity(); graph.delete_edge(e2); map.sync(&graph); - assert_eq!(map.len(), capacity_before); + assert_eq!(map.capacity(), capacity_before); assert_eq!(map[e1], 5); }