1.2.0 permalink Arrow_down_16x16

transitive-closure

clojure.contrib.graph

  • (transitive-closure g)
Returns the transitive closure of a graph. The neighbors are lazily computed.

Note: some version of this algorithm return all edges a->a
regardless of whether such loops exist in the original graph. This
version does not. Loops will be included only if produced by
cycles in the graph. If you have code that depends on such
behavior, call (-> g transitive-closure add-loops)

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:81 top

(defn transitive-closure
  "Returns the transitive closure of a graph.  The neighbors are lazily computed.

   Note: some version of this algorithm return all edges a->a
   regardless of whether such loops exist in the original graph.  This
   version does not.  Loops will be included only if produced by
   cycles in the graph.  If you have code that depends on such
   behavior, call (-> g transitive-closure add-loops)"
  [g]
  (let [nns (fn [n]
              [n (delay (lazy-walk g (get-neighbors g n) #{}))])
        nbs (into {} (map nns (:nodes g)))]
    (struct directed-graph
            (:nodes g)
            (fn [n] (force (nbs n))))))
Vars in clojure.contrib.graph/transitive-closure: defn fn force let struct
Used in 0 other vars

Comments top

No comments for transitive-closure. Log in to add a comment.