diff options
-rw-r--r-- | src/clojure/contrib/graph.clj | 6 | ||||
-rw-r--r-- | src/clojure/contrib/test_contrib/test_graph.clj | 4 |
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 |