@@ -150,6 +150,21 @@ class DiGraphGenerators:
150150 dense data structure. See the documentation of
151151 :class:`~sage.graphs.graph.Graph`.
152152
153+ - ``copy`` -- boolean (default: ``True``); whether to make copies of the
154+ digraphs before returning them. If set to ``False`` the method returns the
155+ digraph it is working on. The second alternative is faster, but modifying
156+ any of the digraph instances returned by the method may break the
157+ function's behaviour, as it is using these digraphs to compute the next
158+ ones: only use ``copy = False`` when you stick to *reading* the digraphs
159+ returned.
160+
161+ This parameter is ignored when ``immutable`` is set to ``True``, in which
162+ case returned graphs are always copies.
163+
164+ - ``immutable`` -- boolean (default: ``False``); whether to return immutable
165+ or mutable digraphs. When set to ``True``, this parameter implies
166+ ``copy=True``.
167+
153168 EXAMPLES:
154169
155170 Print digraphs on 2 or less vertices::
@@ -1780,7 +1795,7 @@ def edges():
17801795# ##############################################################################
17811796
17821797 def __call__ (self , vertices = None , property = lambda x : True , augment = 'edges' ,
1783- size = None , sparse = True , copy = True ):
1798+ size = None , sparse = True , copy = True , immutable = False ):
17841799 """
17851800 Access the generator of isomorphism class representatives [McK1998]_.
17861801 Iterates over distinct, exhaustive representatives.
@@ -1824,6 +1839,13 @@ def __call__(self, vertices=None, property=lambda x: True, augment='edges',
18241839 compute the next ones: only use ``copy = False`` when you stick to
18251840 *reading* the digraphs returned.
18261841
1842+ This parameter is ignored when ``immutable`` is set to ``True``, in
1843+ which case returned graphs are always copies.
1844+
1845+ - ``immutable`` -- boolean (default: ``False``); whether to return
1846+ immutable or mutable digraphs. When set to ``True``, this parameter
1847+ implies ``copy=True``.
1848+
18271849 EXAMPLES:
18281850
18291851 Print digraphs on 2 or less vertices::
@@ -1850,7 +1872,6 @@ def __call__(self, vertices=None, property=lambda x: True, augment='edges',
18501872
18511873 sage: digraphs? # not tested
18521874 """
1853- from copy import copy as copyfun
18541875 if size is not None :
18551876 def extra_property (x ):
18561877 return x .size () == size
@@ -1865,14 +1886,15 @@ def extra_property(x):
18651886 g = DiGraph (sparse = sparse )
18661887 for gg in canaug_traverse_vert (g , [], vertices , property , dig = True , sparse = sparse ):
18671888 if extra_property (gg ):
1868- yield copyfun ( gg ) if copy else gg
1889+ yield gg . copy ( immutable = immutable ) if copy or immutable else gg
18691890
18701891 elif augment == 'edges' :
18711892
18721893 if vertices is None :
18731894 vertices = 0
18741895 while True :
1875- yield from self (vertices , sparse = sparse , copy = copy )
1896+ yield from self (vertices , sparse = sparse , copy = copy ,
1897+ immutable = immutable )
18761898 vertices += 1
18771899
18781900 from sage .graphs .graph_generators import canaug_traverse_edge
@@ -1886,7 +1908,7 @@ def extra_property(x):
18861908 gens .append (gen )
18871909 for gg in canaug_traverse_edge (g , gens , property , dig = True , sparse = sparse ):
18881910 if extra_property (gg ):
1889- yield copyfun ( gg ) if copy else gg
1911+ yield gg . copy ( immutable = immutable ) if copy or immutable else gg
18901912 else :
18911913 raise NotImplementedError ()
18921914
0 commit comments