Created
November 16, 2016 03:32
-
-
Save didibus/1fd4c00b69d927745fbce3dcd7ca461a to your computer and use it in GitHub Desktop.
A Benchmark I modified to Clojure from: https://github.com/c-cube/hashset_benchs
This file contains hidden or 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
(ns hash-set-bench | |
"A Benchmark I modified to Clojure from: | |
https://github.com/c-cube/hashset_benchs") | |
(defn iterNeighbors [f [i j]] | |
(f [(dec i) j]) | |
(f [(inc i) j]) | |
(f [i (dec j)]) | |
(f [i (inc j)])) | |
(defn nth* [n p] | |
(loop [n n s1 #{p} s2 #{}] | |
(if (= n 0) | |
s1 | |
(let [s0 (atom #{})] | |
(letfn [(add [p] | |
(when (not (or (contains? s1 p) (contains? s2 p))) | |
(reset! s0 (conj @s0 p))))] | |
(doseq [p s1] (iterNeighbors add p)) | |
(recur (dec n) @s0 s1)))))) | |
#_(printf "result is %d" (count (time (nth* 2000 [0 0])))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment