 (defn dbscan
   "Run dbscan"
   [pts metric eps min-pts]
-  
-  (loop [points pts
-         visited #{}
-         clusters #{}]
-    (let [pt (first points)]
-      (cond
-        (empty? points)
-          clusters
-        (visited pt) 
-          (recur (rest points)
-                 (conj visited pt)
-                 clusters)
-        :else
-          (let [{new-cluster :core, new-visited :visited}
-                (expand-cluster pt pts metric eps min-pts visited)]
+  (let [mem-metric (if memoized-dbscan
+                     (memoize-metric metric)
+                      metric)]
+
+    (loop [points pts
+           visited #{}
+           clusters #{}]
+      (let [pt (first points)]
+        (cond
+          (empty? points)
+            clusters
+          (visited pt) 
             (recur (rest points)
-                   new-visited
-                   (conj clusters new-cluster))))))) 
+                   (conj visited pt)
+                   clusters)
+          :else
+            (let [{new-cluster :core, new-visited :visited}
+                  (expand-cluster pt pts mem-metric eps min-pts visited)]
+              (recur (rest points)
+                     new-visited
+                     (conj clusters new-cluster))))))))
 
 (defn parse-float
   "Parse string s as float"

          (swap! mem assoc (hash-set a b) ret)
          ret)))))

;;;

(def files


(declare region-query-s)
(declare region-query-p)
(declare memoized-metric)

;; TODO: find optimal subdivision for r/fold

(def memoized-dbscan
  "If true, calls to the metric passed to dbscan will be memoized"
  true)

(def memoized-mediods
  "If true, calls to the metric passed to mediod-protein will be memoized"
  true)

(def region-query
  "Select region-query-s (serial) or region-query-p (parallel)"
  region-query-p)

(def partition-size
  "Approximate subdivision size for clojure.core.reducers/fold"
  16)

;;;

