From dfa8f8f0df8c676b814d37a9961eac8177495c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Mon, 27 Jul 2026 08:56:58 +0200 Subject: [PATCH] Add EntityMap::extend and deprecate VertexMap/EdgeMap::sync --- src/maps.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/maps.rs b/src/maps.rs index 277ceb5..683e4ea 100644 --- a/src/maps.rs +++ b/src/maps.rs @@ -23,8 +23,18 @@ impl VertexMap { self.capacity() } + /// Extends the internal data storage of the map to `capacity`, pre-filling any new slots with + /// the default value. + /// + /// Use this before writing data for new graph vertices to avoid incremental growth on the first + /// write to each new vertex. + pub fn extend(&mut self, capacity: usize) { + self.inner.extend(capacity); + } + + #[deprecated(since = "0.2.4", note = "use 'extend(graph.vertex_capacity())' instead")] pub fn sync>(&mut self, graph: &G) { - self.inner.resize(graph.vertex_capacity()); + self.inner.extend(graph.vertex_capacity()); } } @@ -63,8 +73,18 @@ impl EdgeMap { self.capacity() } + /// Extends the internal data storage of the map to `capacity`, pre-filling any new slots with + /// the default value. + /// + /// Use this before writing data for new graph edges to avoid incremental growth on the first + /// write to each new edge. + pub fn extend(&mut self, capacity: usize) { + self.inner.extend(capacity); + } + + #[deprecated(since = "0.2.4", note = "use 'extend(graph.edge_capacity())' instead")] pub fn sync>(&mut self, graph: &G) { - self.inner.resize(graph.edge_capacity()); + self.inner.extend(graph.edge_capacity()); } } @@ -101,8 +121,8 @@ impl EntityMap { self.data.len() } - pub fn resize(&mut self, capacity: usize) { - if capacity > self.data.len() { + pub fn extend(&mut self, capacity: usize) { + if capacity > self.data.capacity() { self.data.resize(capacity, self.default.clone()); } }