Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
trac #15619: Pickling of immutable graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanncohen committed Jan 2, 2014
1 parent 7860f39 commit 0229348
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/sage/graphs/base/static_sparse_backend.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,24 @@ class StaticSparseBackend(CGraphBackend):
self._vertex_to_labels = vertices
self._vertex_to_int = {v:i for i,v in enumerate(vertices)}

def __reduce__(self):
"""
Return a tuple used for pickling this graph.
TESTS::
sage: G = Graph(graphs.PetersenGraph(), immutable=True)
sage: _ = loads(dumps(G))
"""
if self._directed:
from sage.graphs.digraph import DiGraph as constructor
else:
from sage.graphs.graph import Graph as constructor
G = constructor()
G.add_vertices(self.iterator_verts(None))
G.add_edges(list(self.iterator_edges(self.iterator_verts(None),1)))
return (StaticSparseBackend, (G, self._loops, self._multiedges))

def has_vertex(self, v):
r"""
Tests if the vertex belongs to the graph
Expand Down

0 comments on commit 0229348

Please sign in to comment.