Return a lazy sequence of the nodes of a graph starting a node n. Optionally,
provide a set of visited notes (v) and a collection of nodes to
visit (ns).
(defn lazy-walk
"Return a lazy sequence of the nodes of a graph starting a node n. Optionally,
provide a set of visited notes (v) and a collection of nodes to
visit (ns)."
([g n]
(lazy-walk g [n] #{}))
([g ns v]
(lazy-seq (let [s (seq (drop-while v ns))
n (first s)
ns (rest s)]
(when s
(cons n (lazy-walk g (concat (get-neighbors g n) ns) (conj v n))))))))
Comments top
No comments for lazy-walk. Log in to add a comment.