Skip to content

Instantly share code, notes, and snippets.

@artdent
artdent / graph.clj
Created January 16, 2012 22:09 — forked from zaphar/graph.clj
Ways by node
(defn ways-by-node [ways]
(reduce
(partial merge-with (comp vec concat))
(for [way ways, id (:nodes way)]
(hash-map id [(:id way)]))))
@artdent
artdent / graph.clj
Created January 16, 2012 21:17
Ways by node
(defn collect-ways-by-node [ways]
(loop [ways ways
accum {}]
(if (seq ways)
(let [{:keys [nodes id]} (first ways)
new-accum (zipmap nodes (map vector (repeat id)))]
(recur (rest ways) (merge-with (comp vec concat) accum new-accum)))
accum)))