Skip to content

Commit

Permalink
Inlined add-node.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrupp committed Mar 18, 2013
1 parent a9f3376 commit 89554c8
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/graffy/core.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns graffy.core)

(defprotocol Graph
(add-node [this n])
(add-edge [this s d])
(nodes [this])
(edges [this n])
Expand All @@ -11,12 +10,9 @@
(defn make-graph []
(let [state (atom {})]
(reify Graph
(add-node [_ n]
(when-not (@state n)
(swap! state assoc n #{})))
(add-edge [this s d]
(add-node this s)
(add-node this d)
(when-not (@state s) (swap! state assoc s #{}))
(when-not (@state d) (swap! state assoc d #{}))
(swap! state update-in [s] conj d)
(swap! state update-in [d] conj s)
this)
Expand Down

0 comments on commit 89554c8

Please sign in to comment.