This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-25
Channels
- # adventofcode (1)
- # announcements (1)
- # beginners (244)
- # calva (20)
- # cider (11)
- # cljs-dev (34)
- # clojure (50)
- # clojure-spec (1)
- # clojure-uk (3)
- # clojurebridge (1)
- # clojurescript (21)
- # code-reviews (1)
- # cursive (19)
- # events (1)
- # expound (1)
- # fulcro (65)
- # hyperfiddle (6)
- # luminus (3)
- # nrepl (3)
- # off-topic (23)
- # protorepl (4)
- # re-frame (18)
- # rum (11)
- # shadow-cljs (77)
- # spacemacs (8)
- # tools-deps (2)
- # unrepl (1)
- # vim (2)
Is it still a depth first search if the parent is queued for processing after its children?
parent should not be queued after processing. You have visited set, for visited nodes. It doesn’t make sense to re-visit the parent node again. Or is it your specific use case?
I have a single thread that can process nodes. Parents need all of their children resolved before they can be processed.
Smth like this?
def dfs(source, visited):
if source in visited: return
visited.add(source)
for child in children[source]:
dfs(child, visited)
# do your logic here with source
My code does exactly what you said. > Parents need all of their children resolved before they can be processed
> Oh, I would go over visited in reverse? sure. But this is what you want → child before parent. It should be this way
(defn post-order-tree-seq
[branch? children root]
(let [walk (fn walk [n]
(if (branch? n)
(concat (mapcat walk (children n)) [n])
[n]))]
(walk root)))
Came up with this, which I'm fairly certain is bad given that I'm using concat
in this way 🙂 Generally seems to work though!