Add EntityMap::extend and deprecate VertexMap/EdgeMap::sync

This commit is contained in:
2026-07-27 08:56:58 +02:00
parent 9f76ce4ce3
commit dfa8f8f0df
+24 -4
View File
@@ -23,8 +23,18 @@ impl<V: Copy, T: Clone> VertexMap<V, T> {
self.capacity() 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<G: GraphTopology<Vertex = V>>(&mut self, graph: &G) { pub fn sync<G: GraphTopology<Vertex = V>>(&mut self, graph: &G) {
self.inner.resize(graph.vertex_capacity()); self.inner.extend(graph.vertex_capacity());
} }
} }
@@ -63,8 +73,18 @@ impl<E: Copy, T: Clone> EdgeMap<E, T> {
self.capacity() 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<G: GraphTopology<Edge = E>>(&mut self, graph: &G) { pub fn sync<G: GraphTopology<Edge = E>>(&mut self, graph: &G) {
self.inner.resize(graph.edge_capacity()); self.inner.extend(graph.edge_capacity());
} }
} }
@@ -101,8 +121,8 @@ impl<E: Copy, T: Clone> EntityMap<E, T> {
self.data.len() self.data.len()
} }
pub fn resize(&mut self, capacity: usize) { pub fn extend(&mut self, capacity: usize) {
if capacity > self.data.len() { if capacity > self.data.capacity() {
self.data.resize(capacity, self.default.clone()); self.data.resize(capacity, self.default.clone());
} }
} }