GithubHelp home page GithubHelp logo

topological-sort stack overflows about graph HOT 4 CLOSED

mfiano avatar mfiano commented on August 22, 2024
topological-sort stack overflows

from graph.

Comments (4)

tsdye avatar tsdye commented on August 22, 2024

Can you be more specific? The function passes its test locally with a recent SBCL.

Perhaps note that topological-sort applies to directed graphs, so it is not expected to work with any graph.

; SLIME 2.22
CL-USER> (ql:quickload :graph/test)
To load "graph/test":
Load 1 ASDF system:
graph/test
; Loading "graph/test"
.
(:GRAPH/TEST)
CL-USER> (in-package :graph/test)
#<PACKAGE "GRAPH/TEST">
GRAPH/TEST> (with-fixture digraph (topological-sort *digraph*))
(G A B D C E F)
GRAPH/TEST> (nodes *digraph*)
(A B C D E F G)
GRAPH/TEST> (edges *digraph*)
((A B) (B D) (B C) (C E) (D E) (E F))

from graph.

eschulte avatar eschulte commented on August 22, 2024

If you replace the definition of topological-sort with the following iterative alternative do you still get stack overflows?

(defmethod topological-sort (digraph)
  (assert (null (basic-cycles digraph)) (digraph)
          "~S has a cycle so no topological sort is possible" digraph)
  (let ((pending (nodes digraph)) (seen (make-hash-table)) internal result)
    (loop :while pending :do
         (let ((node (pop pending)))
           (setf pending (append (neighbors digraph node) pending))
           (push node internal)))
    (loop :for node :in internal :unless (gethash node seen) :do
         (setf (gethash node seen) t)
         (push node result))
    result))

The graph library makes pretty heavy use of recursive functions, so I wouldn't be surprised if you hit stack overflows elsewhere. You could also try upping the --control-stack-size in SBCL.

from graph.

eschulte avatar eschulte commented on August 22, 2024

ping

from graph.

eschulte avatar eschulte commented on August 22, 2024

I'm going to go ahead and switch to the iterative solution as it is likely faster and it doesn't appear to be broken.

from graph.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.