From fd817f25823857ba88188798969105c24ba8c37f Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 20 Oct 2014 17:01:40 +0100 Subject: [PATCH] Minor optimisation --- project.clj | 2 +- src/mw_engine/drainage.clj | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/project.clj b/project.clj index 64282fc..f43e2d3 100644 --- a/project.clj +++ b/project.clj @@ -12,7 +12,7 @@ :license {:name "GNU General Public License v2" :url "http://www.gnu.org/licenses/gpl-2.0.html"} :plugins [[lein-marginalia "0.7.1"]] - :dependencies [[org.clojure/clojure "1.5.1"] + :dependencies [[org.clojure/clojure "1.6.0"] [org.clojure/math.combinatorics "0.0.7"] [org.clojure/tools.trace "0.7.8"] [org.clojure/tools.namespace "0.2.4"] diff --git a/src/mw_engine/drainage.clj b/src/mw_engine/drainage.clj index be777c0..1d04a7a 100644 --- a/src/mw_engine/drainage.clj +++ b/src/mw_engine/drainage.clj @@ -2,8 +2,6 @@ ;; assumed to have altitudes already set from a heighmap. (ns mw-engine.drainage - (:require - [clojure.core.reducers :as r]) (:use mw-engine.utils mw-engine.world)) @@ -21,7 +19,7 @@ [world cell] (remove nil? (into [] - (r/map + (map (fn [n] (cond (= cell (get-least-cell (get-neighbours world n) :altitude)) n)) (get-neighbours-with-property-value world (:x cell) (:y cell) 1 @@ -30,10 +28,12 @@ (def flow "Compute the total flow upstream of this `cell` in this `world`, and return a cell identical - to this one but having a value of its flow property set from that computation. + to this one but having a value of its flow property set from that computation. The function is + memoised because the consequence of mapping a recursive function across an array is that many + cells will be revisited - potentially many times. Flow comes from a higher cell to a lower only if the lower is the lowest neighbour of the higher." - (memoize + (memoize (fn [world cell] (cond (not (nil? (:flow cell))) cell