Skip to content

Instantly share code, notes, and snippets.

@didibus
Created November 16, 2016 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save didibus/1fd4c00b69d927745fbce3dcd7ca461a to your computer and use it in GitHub Desktop.
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
(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