# HG changeset patch
# User Robert L. Miller <rlm@rlmiller.org>
# Date 1216685783 25200
# Node ID ac572826f4212184211abdbe0219f5b1b4f179fa
# Parent  91af4c3f6b92316e4117af342d82be33cf5d949b
fixed bug in sparse graph backends:set_edge_label

diff -r 91af4c3f6b92 -r ac572826f421 sage/graphs/base/sparse_graph.pyx
--- a/sage/graphs/base/sparse_graph.pyx	Thu Jul 10 01:11:19 2008 -0700
+++ b/sage/graphs/base/sparse_graph.pyx	Mon Jul 21 17:16:23 2008 -0700
@@ -1465,15 +1465,23 @@ class SparseGraphBackend(CGraphBackend):
         DOCTEST:
             sage: G = sage.graphs.base.sparse_graph.SparseGraphBackend(9)
             sage: G.set_edge_label(1,2,'a',True)
-        """        
+        """
         if not self.has_edge(u, v, None):
             return
         if self.multiple_edges(None):
             if len(self.get_edge_label(u, v)) > 1:
                 raise RuntimeError("Cannot set edge label, since there are multiple edges from %s to %s."%(u,v))
+        # now we know there is exactly one edge from u to v
         if directed:
+            ll = self.get_edge_label(u,v)
+            if ll is not None:
+                self._cg.del_arc_label(u, v, ll)
             self._cg.add_arc_label(u, v, l)
         else:
+            ll = self.get_edge_label(u,v)
+            if ll is not None:
+                self._cg.del_arc_label(u, v, ll)
+                self._cg.del_arc_label(v, u, ll)
             self._cg.add_arc_label(u, v, l)
             self._cg.add_arc_label(v, u, l)
 
diff -r 91af4c3f6b92 -r ac572826f421 sage/graphs/graph.py
--- a/sage/graphs/graph.py	Thu Jul 10 01:11:19 2008 -0700
+++ b/sage/graphs/graph.py	Mon Jul 21 17:16:23 2008 -0700
@@ -2755,6 +2755,13 @@ class GenericGraph(SageObject):
             [(0, 1, 5)]
             sage: dg.incoming_edges(0)
             [(1, 0, 9)]
+
+            sage: G = Graph({0:{1:1}}, implementation='c_graph')
+            sage: G.num_edges()
+            1
+            sage: G.set_edge_label(0,1,1)
+            sage: G.num_edges()
+            1
 
         """
         if self.multiple_edges():
