Ticket #13882: trac13882_trivial_dlx_solver.patch

File trac13882_trivial_dlx_solver.patch, 1.4 KB (added by SimonKing, 8 years ago)
  • sage/combinat/matrices/dancing_links.pyx

    # HG changeset patch
    # User Simon King <simon.king@uni-jena.de>
    # Date 1356818466 -3600
    # Node ID 6820ead5b5a874df0572ecaee6688349a8ed867e
    # Parent  c41952054baa9176123737466ae0c06518f66254
    #13822: Fix trivial case in dancing_linksWrapper.add_rows
    
    diff --git a/sage/combinat/matrices/dancing_links.pyx b/sage/combinat/matrices/dancing_links.pyx
    a b  
    6363            sage: x = make_dlxwrapper(dumps(rows))
    6464            sage: loads(x.__reduce__()[1][0])
    6565            [[0, 1, 2], [1, 2]]
     66
    6667        """
    6768        pass       
    6869
     
    7172    def __cinit__(self, rows):
    7273        self.rows = PyList_New(len(rows))
    7374        dancing_links_construct(&self.x)
    74         self.add_rows(rows)
     75        if rows:
     76            self.add_rows(rows)
    7577
    7678    def __dealloc__(self):
    7779        self.x.freemem()
     
    174176            sage: x = dlx_solver(rows)
    175177            sage: print x.search()
    176178            1
     179
     180        The following example would crash in Sage's debug version
     181        from :trac:`13864` prior to the fix from :trac:`13822`::
     182
     183            sage: from sage.combinat.matrices.dancing_links import dlx_solver
     184            sage: x = dlx_solver([])          # indirect doctest
     185            sage: x.get_solution()
     186            []
     187
    177188        """
     189        if not rows:
     190            return
    178191
    179192        cdef vector_int v
    180193        cdef vector_vector_int vv