Last active
May 22, 2020 21:03
-
-
Save mfikes/cc1d1fac47e7dc112b0b9f4e3de11eae to your computer and use it in GitHub Desktop.
Directly-reducible PoC in Clojure
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 nth' [coll n] | |
(transduce (drop n) (completing #(reduced %2)) nil coll)) | |
(defn tree-seq' | |
[branch? children root] | |
(eduction (take-while some?) (map first) | |
(iterate (fn [[node pair]] | |
(when-some [[[node' & r] cont] (if (branch? node) | |
(if-some [cs (not-empty (children node))] | |
[cs pair] | |
pair) | |
pair)] | |
(if (some? r) | |
[node' [r cont]] | |
[node' cont]))) | |
[root nil]))) | |
(time (dotimes [x 10000] (nth' (tree-seq seq? identity (repeat 10 (repeat 100 [1 2 (repeat 100 3)]))) 1000))) | |
;; "Elapsed time: 6161.53902 msecs" | |
(time (dotimes [x 10000] (nth' (tree-seq' seq? identity (repeat 10 (repeat 100 [1 2 (repeat 100 3)]))) 1000))) | |
;; "Elapsed time: 2830.583306 msecs" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I made a faster transducer version there: https://gist.github.com/green-coder/3adf11660b7b0ca83648c5be69de2a3b