aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib
diff options
context:
space:
mode:
authorJeffrey Straszheim <straszheimjeffrey@gmail.com>2009-02-26 23:16:42 +0000
committerJeffrey Straszheim <straszheimjeffrey@gmail.com>2009-02-26 23:16:42 +0000
commit99d4cec057e03f9da7331ef10d88e47ac9edfff2 (patch)
treeaf1bfdf98b596bc9dffc759a6ae5ed83e74597b2 /src/clojure/contrib
parent2a805ed15058cd04bb5042a2ce198c2a44ef0de3 (diff)
Fixed loops in transitive closure
Diffstat (limited to 'src/clojure/contrib')
-rw-r--r--src/clojure/contrib/graph.clj6
-rw-r--r--src/clojure/contrib/test_contrib/test_graph.clj4
2 files changed, 6 insertions, 4 deletions
diff --git a/src/clojure/contrib/graph.clj b/src/clojure/contrib/graph.clj
index 5452340a..8e2eda16 100644
--- a/src/clojure/contrib/graph.clj
+++ b/src/clojure/contrib/graph.clj
@@ -69,7 +69,7 @@
([g n]
(lazy-walk g [n] #{}))
([g ns v]
- (lazy-seq (let [s (seq (remove v ns))
+ (lazy-seq (let [s (seq (drop-while v ns))
n (first s)
ns (rest s)]
(when s
@@ -78,7 +78,9 @@
(defn transitive-closure
"Returns the transitive closure of a graph. The neighbors are lazily computed."
[g]
- (let [nbs (into {} (map (fn [n] [n (delay (lazy-walk g n))]) (:nodes 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))))))
diff --git a/src/clojure/contrib/test_contrib/test_graph.clj b/src/clojure/contrib/test_contrib/test_graph.clj
index 09b3cc93..425966bf 100644
--- a/src/clojure/contrib/test_contrib/test_graph.clj
+++ b/src/clojure/contrib/test_contrib/test_graph.clj
@@ -79,9 +79,9 @@
(is (every? #(= #{:a :b :c :d :e} (set %))
(map (partial get-neighbors tc-1) (:nodes tc-1))))
(is (= (get :a) #{:a :b :c :d :e}))
- (is (= (get :h) #{:h}))
+ (is (= (get :h) #{}))
(is (= (get :j) #{:i :j}))
- (is (= (get :g) #{:a :b :c :d :e :f :g}))))
+ (is (= (get :g) #{:a :b :c :d :e :f}))))
(deftest test-post-ordered-nodes