Comments (4)
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.
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.
ping
from graph.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graph.