Repository: petgraph/petgraph (language: rust)

Issue:
immediately_dominated_by function called on root of graph returns root itself
Hello petgraph maintainers!

While using this amazing crate we stumbled upon 1 small bug. The documentation of the [immediately_dominated_by](https://docs.rs/petgraph/latest/petgraph/algo/dominators/struct.Dominators.html#method.immediately_dominated_by) states:

> Iterate over all nodes immediately dominated by the given node (not including the given node itself).

But when we call this function on a root of a graph the function returns the root itself. See the example.

If you have any questions please let me know.

Thank you 👋 

### Test Case

use petgraph::{algo::dominators, stable_graph::StableDiGraph};
fn main() {
    let mut graph: StableDiGraph<&str, ()> = StableDiGraph::new();
    let root = graph.add_node("ROOT");
    let a = graph.add_node("A");
    let b = graph.add_node("B");
    graph.extend_with_edges([(root, a), (root, b)]);
    let dominators = dominators::simple_fast(&graph, root);
    let dominated_by_root: Vec<_> = dominators
        .immediately_dominated_by(root)
        .map(|n| graph.node_weight(n).unwrap())
        .collect();
    println!("{:?}", dominated_by_root);
}

### Steps To Reproduce

 * Create a new binary project with petgraph as dependency
 * Paste the code in main.rs
 * let it run with cargo run

### Actual Results

["ROOT", "A", "B"]

### Expected Results

["A", "B"]


Discussion / hints:

Fix patch:
diff --git a/src/algo/dominators.rs b/src/algo/dominators.rs
index a7e1a5f9a..9e709352f 100644
--- a/src/algo/dominators.rs
+++ b/src/algo/dominators.rs
@@ -132,9 +132,11 @@ where
     type Item = N;
 
     fn next(&mut self) -> Option<Self::Item> {
-        for next in self.iter.by_ref() {
-            if next.1 == &self.node {
-                return Some(*next.0);
+        for (dominator, dominated) in self.iter.by_ref() {
+            // The root node dominates itself, but it should not be included in
+            // the results.
+            if dominated == &self.node && dominated != dominator {
+                return Some(*dominator);
             }
         }
         None
@@ -326,5 +328,6 @@ mod tests {
         let dom_by: Vec<_> = doms.immediately_dominated_by(1).collect();
         assert_eq!(vec![2], dom_by);
         assert_eq!(None, doms.immediately_dominated_by(99).next());
+        assert_eq!(1, doms.immediately_dominated_by(0).count());
     }
 }


Test patch: