Mercurial > coderloop
annotate src/test_mega_tree.clj @ 0:307a81e46071 tip
initial committ
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 18 Oct 2011 01:17:49 -0700 |
parents | |
children |
rev | line source |
---|---|
rlm@0 | 1 (ns coderloop.test-mega-tree) |
rlm@0 | 2 |
rlm@0 | 3 (rlm.ns-rlm/ns-clone rlm.light-base) |
rlm@0 | 4 (import '[com.coderloop.puzzles Megafasttree Megafasttree$Node]) |
rlm@0 | 5 |
rlm@0 | 6 |
rlm@0 | 7 (defn node [n] |
rlm@0 | 8 (Megafasttree$Node. n)) |
rlm@0 | 9 |
rlm@0 | 10 |
rlm@0 | 11 (defn tree [root] |
rlm@0 | 12 (doto (Megafasttree.) |
rlm@0 | 13 (.addRoot root))) |
rlm@0 | 14 |
rlm@0 | 15 |
rlm@0 | 16 (defn make-counter [] |
rlm@0 | 17 (let [a (atom -1)] |
rlm@0 | 18 (fn count [] (swap! a inc)))) |
rlm@0 | 19 |
rlm@0 | 20 |
rlm@0 | 21 (defn make-big-ass-tree [depth] |
rlm@0 | 22 (let [counter (make-counter) |
rlm@0 | 23 root (node (counter))] |
rlm@0 | 24 (loop [base [root] |
rlm@0 | 25 level 0] |
rlm@0 | 26 (if (= level depth) |
rlm@0 | 27 (tree root) |
rlm@0 | 28 (do |
rlm@0 | 29 (dorun (map |
rlm@0 | 30 #(doto % |
rlm@0 | 31 (.setLeftChild (node (counter))) |
rlm@0 | 32 (.setRightChild (node (counter)))) |
rlm@0 | 33 base)) |
rlm@0 | 34 (recur |
rlm@0 | 35 (apply concat (map #(vector (.toLeft %) (.toRight %)) |
rlm@0 | 36 base)) |
rlm@0 | 37 (inc level))))))) |
rlm@0 | 38 |
rlm@0 | 39 |
rlm@0 | 40 (defn test-shittiness [n] |
rlm@0 | 41 (time (do (.bfs (make-big-ass-tree n)) nil))) |