diff --git a/src/loom/alg.cljc b/src/loom/alg.cljc index b3008b1..5ea8448 100644 --- a/src/loom/alg.cljc +++ b/src/loom/alg.cljc @@ -435,7 +435,7 @@ can use these functions." coloring (let [v (peek queue) color (- 1 (coloring v)) - nbrs (graph/successors g v)] + nbrs (graph/neighbors g v)] ;; TODO: could be better (if (some #(and (coloring %) (= (coloring v) (coloring %))) nbrs) diff --git a/src/loom/graph.cljc b/src/loom/graph.cljc index caaa5f6..8341d41 100644 --- a/src/loom/graph.cljc +++ b/src/loom/graph.cljc @@ -5,6 +5,7 @@ on adjacency lists." :author "Justin Kramer"} loom.graph (:require [loom.alg-generic :refer [bf-traverse]] + [clojure.set :as clj.set] #?@(:clj [[loom.cljs :refer (def-protocol-impls)]])) #?@(:cljs [(:require-macros [loom.cljs :refer [def-protocol-impls extend]])])) @@ -79,6 +80,14 @@ on adjacency lists." ([g] #(predecessors g %)) ([g node] (predecessors* g node))) +(defn neighbors + "Returns all neighbors of node" + ([g] #(neighbors g %)) + ([g node] + (clj.set/union + (set (predecessors g node)) + (set (successors g node))))) + (defn weight "Returns the weight of edge e or edge [n1 n2]" ([g] (partial weight g))