# HG changeset patch
# User JeanPierre Flori <jeanpierre.flor@ssi.gouv.fr>
# Date 1353343752 3600
# Node ID 6cd9b52cfb4ea028f78247322b490e16107a8c00
# Parent 1557e9aeccb47fc8065714825c9823ea99761c34
#13719: Handle tree with no vertices correctly
diff git a/sage/graphs/trees.pyx b/sage/graphs/trees.pyx
a

b


85  85  """ 
86  86  if self.l != NULL: 
87  87  sage_free(self.l) 
 88  self.l = NULL 
88  89  if self.current_level_sequence != NULL: 
89  90  sage_free(self.current_level_sequence) 
 91  self.current_level_sequence = NULL 
90  92  
91  93  def __str__(self): 
92  94  r""" 
… 
… 

122  124  sage: T = TreeIterator(5) 
123  125  sage: [t for t in T] # indirect doctest 
124  126  [Graph on 5 vertices, Graph on 5 vertices, Graph on 5 vertices] 
 127  
 128  
 129  TESTS: 
 130  
 131  This used to be broken for trees with no vertices 
 132  and was fixed in :trac:`13719` :: 
 133  
 134  sage: from sage.graphs.trees import TreeIterator 
 135  sage: T = TreeIterator(0) 
 136  sage: [t for t in T] # indirect doctest 
 137  [Graph on 0 vertices] 
125  138  """ 
126  139  
127  140  if not self.first_time and self.q == 0: 
128  141  raise StopIteration 
129  142  
130  143  if self.first_time == 1: 
131   self.l = <int *>sage_malloc(self.vertices * sizeof(int)) 
132   self.current_level_sequence = <int *>sage_malloc(self.vertices * sizeof(int)) 
133   
134   if self.l == NULL or self.current_level_sequence == NULL: 
135   raise MemoryError 
 144  if self.vertices == 0: 
 145  self.first_time = 0 
 146  self.q = 0 
 147  else: 
 148  self.l = <int *>sage_malloc(self.vertices * sizeof(int)) 
 149  self.current_level_sequence = <int *>sage_malloc(self.vertices * sizeof(int)) 
136  150  
137   self.generate_first_level_sequence() 
138   self.first_time = 0 
 151  if self.l == NULL or self.current_level_sequence == NULL: 
 152  raise MemoryError 
 153  
 154  self.generate_first_level_sequence() 
 155  self.first_time = 0 
139  156  else: 
140  157  self.generate_next_level_sequence() 
141  158  