Add GraphTopologyAddition trait from GraphTopology

Move capacity and add methods from GraphTopology trait to new GraphTopologyAddition trait
This commit is contained in:
2026-08-06 14:17:21 +02:00
parent 2851cf60fd
commit 10d0c382cc
10 changed files with 75 additions and 63 deletions
+13 -9
View File
@@ -3,7 +3,9 @@
use typed_generational_arena::{Arena, Index};
use crate::maps::EntityMap;
use crate::traits::{GraphTopology, GraphTopologyDeletion, Incidence, IncidenceCursor};
use crate::traits::{
GraphTopology, GraphTopologyAddition, GraphTopologyDeletion, Incidence, IncidenceCursor,
};
/// An opaque handle identifying a vertex in a [`Graph`].
///
@@ -239,10 +241,6 @@ impl GraphTopology for Graph {
self.vertices.len()
}
fn vertex_capacity(&self) -> usize {
self.vertices.capacity()
}
fn vertex_map<T: Clone>(&self, default: T) -> EntityMap<Self::Vertex, T> {
EntityMap::new(default, |v| v.arr_idx(), self.vertex_capacity())
}
@@ -251,10 +249,6 @@ impl GraphTopology for Graph {
self.incidences.len() / 2
}
fn edge_capacity(&self) -> usize {
self.incidences.capacity() / 2
}
fn edge_map<T: Clone>(&self, default: T) -> EntityMap<Self::Edge, T> {
EntityMap::new(default, |e| e.arr_idx() / 2, self.edge_capacity())
}
@@ -312,6 +306,16 @@ impl GraphTopology for Graph {
incidence: self.vertices[v].first_incidence,
}
}
}
impl GraphTopologyAddition for Graph {
fn vertex_capacity(&self) -> usize {
self.vertices.capacity()
}
fn edge_capacity(&self) -> usize {
self.incidences.capacity() / 2
}
fn add_vertex(&mut self) -> Self::Vertex {
self.vertices.insert(VertexIncidenceHeader {