Change "neighbor" terminology to "adjacent vertex" throughout the code
This commit is contained in:
+17
-17
@@ -20,15 +20,15 @@ pub struct VertexIncidenceHeader {
|
||||
|
||||
pub struct IncidenceEntry {
|
||||
next: Option<IncidenceSlot>,
|
||||
neighbor: VertexSlot,
|
||||
adjacent: VertexSlot,
|
||||
}
|
||||
|
||||
struct VertexNeighborIterator<'a> {
|
||||
struct VertexAdjacenceIterator<'a> {
|
||||
graph: &'a Graph,
|
||||
incidence: Option<IncidenceSlot>,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for VertexNeighborIterator<'a> {
|
||||
impl<'a> Iterator for VertexAdjacenceIterator<'a> {
|
||||
type Item = Vertex;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
@@ -37,7 +37,7 @@ impl<'a> Iterator for VertexNeighborIterator<'a> {
|
||||
let index = self.graph.incidences.get_idx(incidence.0)?;
|
||||
let entry = &self.graph.incidences[index];
|
||||
self.incidence = entry.next;
|
||||
self.graph.vertices.get_idx(entry.neighbor.0)
|
||||
self.graph.vertices.get_idx(entry.adjacent.0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ impl Graph {
|
||||
fn add_incidence(&mut self, v1: Vertex, v2: Vertex) -> Edge {
|
||||
let edge = self.incidences.insert(IncidenceEntry {
|
||||
next: self.vertices[v1].first_incidence.take(),
|
||||
neighbor: VertexSlot(v2.arr_idx()),
|
||||
adjacent: VertexSlot(v2.arr_idx()),
|
||||
});
|
||||
self.vertices[v1].incidence_count += 1;
|
||||
self.vertices[v1].first_incidence = Some(IncidenceSlot(edge.arr_idx()));
|
||||
@@ -124,12 +124,12 @@ impl Graph {
|
||||
let source_vertex = self
|
||||
.vertices
|
||||
.get_idx(source.0)
|
||||
.expect("missing incident neighbor, corrupt internal data state");
|
||||
.expect("missing incident vertex, corrupt internal data state");
|
||||
let vertex_header = &mut self.vertices[source_vertex];
|
||||
vertex_header.incidence_count -= if is_loop { 2 } else { 1 };
|
||||
let first = vertex_header
|
||||
.first_incidence
|
||||
.expect("incident neighbor without incidences, corrupt internal data state");
|
||||
.expect("incident vertex without incidences, corrupt internal data state");
|
||||
if first.0 == e.arr_idx() {
|
||||
vertex_header.first_incidence = next;
|
||||
} else {
|
||||
@@ -184,15 +184,15 @@ impl GraphTopology for Graph {
|
||||
}
|
||||
|
||||
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> {
|
||||
self.vertices.iter().map(|(i, _)| i)
|
||||
}
|
||||
|
||||
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].first_incidence,
|
||||
}
|
||||
@@ -233,8 +233,8 @@ impl GraphTopologyDeletion for Graph {
|
||||
// Since v is being deleted, there are no update_incidence_list() calls for e, no need
|
||||
// to fix v's incidence list.
|
||||
let (f, e_entry, f_entry) = self.remove_incidence_pair(e);
|
||||
if e_entry.neighbor != f_entry.neighbor {
|
||||
self.update_incidence_list(f, e_entry.neighbor, f_entry.next, false);
|
||||
if e_entry.adjacent != f_entry.adjacent {
|
||||
self.update_incidence_list(f, e_entry.adjacent, f_entry.next, false);
|
||||
} else {
|
||||
cursor.incidence = f_entry.next;
|
||||
}
|
||||
@@ -246,13 +246,13 @@ impl GraphTopologyDeletion for Graph {
|
||||
// the predecessor, never the removed entries themselves.
|
||||
fn delete_edge(&mut self, e: Self::Edge) {
|
||||
let (f, e_entry, f_entry) = self.remove_incidence_pair(e);
|
||||
if e_entry.neighbor != f_entry.neighbor {
|
||||
self.update_incidence_list(e, f_entry.neighbor, e_entry.next, false);
|
||||
self.update_incidence_list(f, e_entry.neighbor, f_entry.next, false);
|
||||
if e_entry.adjacent != f_entry.adjacent {
|
||||
self.update_incidence_list(e, f_entry.adjacent, e_entry.next, false);
|
||||
self.update_incidence_list(f, e_entry.adjacent, f_entry.next, false);
|
||||
} else if f_entry.next.is_some_and(|i| e.arr_idx() == i.0) {
|
||||
self.update_incidence_list(f, e_entry.neighbor, e_entry.next, true);
|
||||
self.update_incidence_list(f, e_entry.adjacent, e_entry.next, true);
|
||||
} else {
|
||||
self.update_incidence_list(e, e_entry.neighbor, f_entry.next, true);
|
||||
self.update_incidence_list(e, e_entry.adjacent, f_entry.next, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user