Plaster
New
List
Login
common-lisp
default
anonymous
2022.11.18 16:45:51
(defmethod interface:components ((graph undirected-graph)) (do* ((remaining (interface:vertices graph) (set-difference remaining last-seen)) (interface:components '() (cons last-seen interface:components)) (last-seen '() '())) ((null remaining) interface:components) ;; A component is created by recording all the targets in a ;; depth-first search. (interface:depth-first-search graph (lambda (_ x) (declare (ignore _)) (push x last-seen)) ;; Start the component discovery at any vertex from the remaining. (first remaining))))
Raw
Annotate
Repaste
Edit
Annotations
text
default
anonymous
2022.11.18 17:04:13
(defmethod interface:components ((graph undirected-graph)) (iterate (for remaining = (interface:vertices graph) then (set-difference remaining last-seen)) (as last-seen = nil) ; last-seen is reset to nil every time? (while remaining) (with components) (interface:depth-first-search graph (lambda (_ x) (declare (ignore _)) (push x last-seen)) ;; Start the component discovery at any vertex from the remaining. (first remaining)) ;; this returns a list of last-seen sets, which I think is what the original does, but if you ;; want a single set, then this should be "appending" (collecting last-seen)))
Raw
Repaste
Edit