Change "neighbor" terminology to "adjacent vertex" throughout the code

This commit is contained in:
2026-05-07 17:34:20 +02:00
parent 726e7691ea
commit a7be995e34
5 changed files with 61 additions and 61 deletions
+8 -8
View File
@@ -20,22 +20,22 @@ struct VertexIncidenceHeader {
struct IncidenceEntry {
next: Option<Incidence>,
neighbor: Vertex,
adjacent: Vertex,
}
struct VertexNeighborIterator<'a> {
struct VertexAdjacenceIterator<'a> {
graph: &'a AppendGraph,
incidence: Option<Incidence>,
}
impl<'a> Iterator for VertexNeighborIterator<'a> {
impl<'a> Iterator for VertexAdjacenceIterator<'a> {
type Item = Vertex;
fn next(&mut self) -> Option<Self::Item> {
let incidence = self.incidence?;
let entry = &self.graph.incidences[incidence.0];
self.incidence = entry.next;
Some(entry.neighbor)
Some(entry.adjacent)
}
}
@@ -58,7 +58,7 @@ impl AppendGraph {
fn add_incidence(&mut self, v1: Vertex, v2: Vertex) {
self.incidences.push(IncidenceEntry {
next: self.vertices[v1.0].first_incidence.take(),
neighbor: v2,
adjacent: v2,
});
self.vertices[v1.0].incidence_count += 1;
self.vertices[v1.0].first_incidence = Some(Incidence(self.incidences.len() - 1));
@@ -105,15 +105,15 @@ impl GraphTopology for AppendGraph {
}
fn are_adjacent(&self, v1: Self::Vertex, v2: Self::Vertex) -> bool {
self.neighbors(v1).any(|x| x == v2)
self.adjacent_vertices(v1).any(|x| x == v2)
}
fn vertices(&self) -> impl Iterator<Item = Self::Vertex> {
(0..self.vertices.len()).map(Vertex)
}
fn neighbors(&self, v: Self::Vertex) -> impl Iterator<Item = Self::Vertex> {
VertexNeighborIterator {
fn adjacent_vertices(&self, v: Self::Vertex) -> impl Iterator<Item = Self::Vertex> {
VertexAdjacenceIterator {
graph: self,
incidence: self.vertices[v.0].first_incidence,
}