From 85a81bd8fbe0d67d76b9649d5156c7924bcf9aae Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Tue, 23 Nov 2010 21:40:56 -0700 Subject: [PATCH] memoizing the neighbors function over graphs --- src/neural_net/core.clj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/neural_net/core.clj b/src/neural_net/core.clj index e535d97..ffac57f 100644 --- a/src/neural_net/core.clj +++ b/src/neural_net/core.clj @@ -4,9 +4,11 @@ (defrecord Graph [#^clojure.lang.IPersistentMap vertices #^clojure.lang.IPersistentVector edges]) -(defn neighbors [#^neural-net.core.Graph g v] +(defn -neighbors [#^neural-net.core.Graph g v] (keep identity (map (fn [[a b]] (cond (= a v) b (= b v) a)) (get g :edges)))) +(def neighbors (memoize -neighbors)) + (defn nearest-neighbors ([#^neural-net.core.Graph g] (nearest-neighbors g (count (get g :vertices)))) ([#^neural-net.core.Graph g max] -- 2.11.4.GIT