Created
October 20, 2010 22:38
-
-
Save duncanmak/637492 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn conj-entry [trails entry transform] | |
(let [all-trails (sort-by #(trail-proximity % entry) trails)] | |
(if (empty? all-trails) | |
[(make-trail entry)] | |
(loop [[trail & trails] all-trails | |
results (transient [])] | |
(cond | |
;; no matches found after scanning all trails | |
(nil? trail) | |
(do | |
(when *debug* (print "!")) | |
(conj (persistent! results) (make-trail entry))) | |
;; trail matches | |
(trail-matches? trail (transform-entry transform entry)) | |
(let [new-trail (add-entry trail entry)] | |
(when *debug* (print "+")) | |
(apply conj (persistent! results) new-trail trails)) | |
:else ;; try the next trail | |
(recur trails | |
(conj! results trail))))))) | |
(defn propagate-iterative [entries transform relevant-trails other-trails] | |
(loop [entries entries | |
trails relevant-trails] | |
(if (empty? entries) | |
(do (when *debug* (println)) | |
(if (empty? other-trails) | |
trails | |
(apply conj trails other-trails))) | |
(let [entry (first entries)] | |
(recur (rest entries) | |
(conj-entry trails entry transform)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment