Fix IncidenceCursor for AppendGraph and Graph, and add tests
This commit is contained in:
@@ -34,7 +34,9 @@ pub struct AppendGraphIncidenceCursor {
|
||||
|
||||
impl IncidenceCursor<AppendGraph> for AppendGraphIncidenceCursor {
|
||||
fn next(&mut self, graph: &AppendGraph) -> Option<(Vertex, Edge)> {
|
||||
graph.step_incidence(&mut self.incidence)
|
||||
graph
|
||||
.step_incidence(&mut self.incidence)
|
||||
.map(|(v, e)| (v, e.normalize()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-4
@@ -43,9 +43,12 @@ pub struct GraphIncidenceCursor {
|
||||
|
||||
impl IncidenceCursor<Graph> for GraphIncidenceCursor {
|
||||
fn next(&mut self, graph: &Graph) -> Option<(Vertex, Edge)> {
|
||||
graph
|
||||
.step_incidence(&mut self.incidence)
|
||||
.map(|(vs, e)| (graph.vertices.get_idx(vs.0).unwrap(), e))
|
||||
graph.step_incidence(&mut self.incidence).map(|(vs, e)| {
|
||||
(
|
||||
graph.vertices.get_idx(vs.0).unwrap(),
|
||||
graph.normalize_edge(e),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +143,12 @@ impl Graph {
|
||||
}
|
||||
|
||||
fn normalize_edge(&self, e: Edge) -> Edge {
|
||||
self.incidences.get_idx(e.arr_idx() & !1).unwrap()
|
||||
let i = e.arr_idx();
|
||||
if i & 1 == 0 {
|
||||
e
|
||||
} else {
|
||||
self.incidences.get_idx(i ^ 1).unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user