Refactor ElementMap, removing its copy-on-write feature
This commit is contained in:
@@ -170,7 +170,6 @@ impl GraphTopology for AppendGraph {
|
||||
self.vertices.len()
|
||||
}
|
||||
|
||||
// TODO: Create with capacity 0, maybe offer pre-allocated alternative?
|
||||
fn vertex_map<T: Clone>(&self, default: T) -> ElementMap<Self::Vertex, T> {
|
||||
ElementMap::new(default, |v| v.0, self.vertex_capacity())
|
||||
}
|
||||
@@ -179,7 +178,6 @@ impl GraphTopology for AppendGraph {
|
||||
self.incidences.len() / 2
|
||||
}
|
||||
|
||||
// TODO: Create with capacity 0, maybe offer pre-allocated alternative?
|
||||
fn edge_map<T: Clone>(&self, default: T) -> ElementMap<Self::Edge, T> {
|
||||
ElementMap::new(default, |e| e.index() / 2, self.edge_capacity())
|
||||
}
|
||||
|
||||
@@ -144,7 +144,8 @@ impl GraphTopology for FrozenGraph {
|
||||
|
||||
// TODO: Find a way to reduce the needed capacity for the edge ElementMap. This could be improved by finding a small vertex cover and store those vertices first. See https://en.wikipedia.org/wiki/Vertex_cover#Approximate_evaluation
|
||||
fn edge_map<T: Clone>(&self, default: T) -> ElementMap<Self::Edge, T> {
|
||||
ElementMap::new(default, |e| e.0, self.incidences.len() - 1)
|
||||
// "incidences.len() - 1" would underflow for an edge-free graph.
|
||||
ElementMap::new(default, |e| e.0, self.incidences.len().saturating_sub(1))
|
||||
}
|
||||
|
||||
fn degree(&self, v: Self::Vertex) -> usize {
|
||||
|
||||
@@ -262,7 +262,6 @@ impl GraphTopology for Graph {
|
||||
self.vertices.len()
|
||||
}
|
||||
|
||||
// TODO: Create with capacity 0, maybe offer pre-allocated alternative?
|
||||
fn vertex_map<T: Clone>(&self, default: T) -> ElementMap<Self::Vertex, T> {
|
||||
ElementMap::new(default, |v| v.arr_idx(), self.vertex_capacity())
|
||||
}
|
||||
@@ -271,7 +270,6 @@ impl GraphTopology for Graph {
|
||||
self.incidences.len() / 2
|
||||
}
|
||||
|
||||
// TODO: Create with capacity 0, maybe offer pre-allocated alternative?
|
||||
fn edge_map<T: Clone>(&self, default: T) -> ElementMap<Self::Edge, T> {
|
||||
ElementMap::new(default, |e| e.arr_idx() / 2, self.edge_capacity())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user