Skip to content

Commit

Permalink
Made neighbors return a seq and removed redundant neighbors-list func…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
davidrupp committed Mar 23, 2013
1 parent 0dc3a9b commit 51f682a
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/graffy/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
(keys g))

(defn neighbors [g n]
(or (g n)
(sorted-set)))
(seq (or (g n)
(sorted-set))))

(defn edges [g n]
(for [dest (neighbors g n)]
Expand All @@ -22,9 +22,6 @@
(apply concat (for [source (vertices g)]
(edges g source))))

(defn neighbor-list [g n]
(apply list (neighbors g n)))

(defn dft [g n]
(loop [acc [] stack (list n)]
(if (zero? (count stack))
Expand All @@ -33,7 +30,7 @@
rst (pop stack)]
(if (contains? (into #{} acc) nxt)
(recur acc rst)
(recur (conj acc nxt) (apply list (concat (neighbor-list g nxt) rst))))))))
(recur (conj acc nxt) (apply list (concat (neighbors g nxt) rst))))))))

;; TODO: Refactor me!; bft differs from dft only in the concat call in tail position**
(defn bft [g n]
Expand All @@ -44,4 +41,4 @@
rst (pop stack)]
(if (contains? (into #{} acc) nxt)
(recur acc rst)
(recur (conj acc nxt) (apply list (concat rst (neighbor-list g nxt))))))))) ;; ** here
(recur (conj acc nxt) (apply list (concat rst (neighbors g nxt))))))))) ;; ** here

0 comments on commit 51f682a

Please sign in to comment.