Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.