FEAT: Add StableGraph::retain_edges
diff --git a/src/graph_impl/stable_graph/mod.rs b/src/graph_impl/stable_graph/mod.rs
index 9a1d1f6..e0db3d5 100644
--- a/src/graph_impl/stable_graph/mod.rs
+++ b/src/graph_impl/stable_graph/mod.rs
@@ -709,7 +709,7 @@
     ///  **e'** is the number of affected edges, including *n* calls to `.remove_edge()`
     /// where *n* is the number of edges with an endpoint in a removed node.
     pub fn retain_nodes<F>(&mut self, mut visit: F) where F: FnMut(Frozen<Self>, NodeIndex<Ix>) -> bool {
-        for i in 0..self.g.node_count() {
+        for i in 0..self.node_bound() {
             let ix = node_index(i);
             if self.contains_node(ix) && !visit(Frozen(self), ix) {
                 self.remove_node(ix);
@@ -718,6 +718,31 @@
         self.check_free_lists();
     }
 
+    /// Keep all edges that return `true` from the `visit` closure,
+    /// remove the others.
+    ///
+    /// `visit` is provided a proxy reference to the graph, so that
+    /// the graph can be walked and associated data modified.
+    ///
+    /// The order edges are visited is not specified.
+    ///
+    /// The edge indices of the removed edes are invalidated, but none other.
+    /// Edge indices are invalidated as they would be following the removal of
+    /// each edge with an endpoint in a removed edge.
+    ///
+    /// Computes in **O(e'')** time, **e'** is the number of affected edges,
+    /// including the calls to `.remove_edge()` for each removed edge.
+    pub fn retain_edges<F>(&mut self, mut visit: F)
+        where F: FnMut(Frozen<Self>, EdgeIndex<Ix>) -> bool
+    {
+        for i in 0..self.edge_bound() {
+            let ix = edge_index(i);
+            if self.edge_weight(ix).is_some() && !visit(Frozen(self), ix) {
+                self.remove_edge(ix);
+            }
+        }
+        self.check_free_lists();
+    }
 
     /// Create a new `StableGraph` from an iterable of edges.
     ///