Update Graph::are_adjacent() to use neighbors() iterator
This commit is contained in:
+1
-13
@@ -61,20 +61,8 @@ impl Graph {
|
|||||||
self.incidence_headers[v.0].incidence_count
|
self.incidence_headers[v.0].incidence_count
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: 'fn are_adjacent()' could probably be done with a neighbor vertex iterator.
|
|
||||||
pub fn are_adjacent(&self, v1: Vertex, v2: Vertex) -> bool {
|
pub fn are_adjacent(&self, v1: Vertex, v2: Vertex) -> bool {
|
||||||
let Some(mut incidence) = self.incidence_headers[v1.0].first_incidence else {
|
self.neighbors(v1).find(|&x| x == v2).is_some()
|
||||||
return false;
|
|
||||||
};
|
|
||||||
loop {
|
|
||||||
if self.incidence_vertices[incidence.0] == v2 {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
let Some(next) = self.next_incidences[incidence.0] else {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
incidence = next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: 'fn add_vertex()' needs variants for custom vertex data.
|
// TODO: 'fn add_vertex()' needs variants for custom vertex data.
|
||||||
|
|||||||
Reference in New Issue
Block a user