reverse-graph

clojure.contrib.graph

  • (reverse-graph g)
Given a directed graph, return another directed graph with the
order of the edges reversed.

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/graph.clj:37 top

(defn reverse-graph
  "Given a directed graph, return another directed graph with the
   order of the edges reversed."
  [g]
  (let [op (fn [rna idx]
             (let [ns (get-neighbors g idx)
                   am (fn [m val]
                        (assoc m val (conj (get m val #{}) idx)))]
               (reduce am rna ns)))
        rn (reduce op {} (:nodes g))]
    (struct directed-graph (:nodes g) rn)))
Vars in clojure.contrib.graph/reverse-graph: defn let struct
Used in 0 other vars

Comments top

No comments for reverse-graph. Log in to add a comment.