Nick Day <[email protected]> writes:
> I've been trying to implement a topological sort and have been
> struggling a bit. I have a map of symbol vs collection of symbols
> like:
>
> {a [b c], b [c], c [nil]}
>
> which can be read as 'a' depends on 'b' and 'c', 'b' depends on 'c'
> and 'c' doesn't depend on anything. I've been trying to write
> something that returns a collection of the dependencies in order (c,
> b, a) but so far I've only been able to do it using a ref to store
> intermediate output of the sorting. I was wondering if anyone has
> already done something similar?
clojure.contrib.graph/dependency-list might be close enough for you
(use 'clojure.contrib.graph)
(dependency-list {:nodes [:a :b :c]
:neighbors {:a [:b :c]
:b [:c]}})
=>[#{:c} #{:b} #{:a}]
--
jan
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en