Add len() for VertexMap and EdgeMap

This commit is contained in:
2026-05-12 18:25:22 +02:00
parent be63527478
commit f1d5ccafd2
2 changed files with 22 additions and 8 deletions
+14
View File
@@ -13,6 +13,11 @@ impl<V: Copy, T: Clone> VertexMap<V, T> {
}
}
// Reads beyond len() are valid and return the default value.
pub fn len(&self) -> usize {
self.inner.len()
}
pub fn sync<G: GraphTopology<Vertex = V>>(&mut self, graph: &G) {
self.inner.resize(graph.vertex_capacity());
}
@@ -43,6 +48,11 @@ impl<E: Copy, T: Clone> EdgeMap<E, T> {
}
}
// Reads beyond len() are valid and return the default value.
pub fn len(&self) -> usize {
self.inner.len()
}
pub fn sync<G: GraphTopology<Edge = E>>(&mut self, graph: &G) {
self.inner.resize(graph.edge_capacity());
}
@@ -77,6 +87,10 @@ impl<E: Copy, T: Clone> EntityMap<E, T> {
}
}
pub fn len(&self) -> usize {
self.data.len()
}
pub fn resize(&mut self, capacity: usize) {
if capacity > self.data.len() {
self.data.resize(capacity, self.default.clone());