view 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
line wrap: on
line source
1 (ns coderloop.test-mega-tree)
3 (rlm.ns-rlm/ns-clone rlm.light-base)
4 (import '[com.coderloop.puzzles Megafasttree Megafasttree$Node])
7 (defn node [n]
8 (Megafasttree$Node. n))
11 (defn tree [root]
12 (doto (Megafasttree.)
13 (.addRoot root)))
16 (defn make-counter []
17 (let [a (atom -1)]
18 (fn count [] (swap! a inc))))
21 (defn make-big-ass-tree [depth]
22 (let [counter (make-counter)
23 root (node (counter))]
24 (loop [base [root]
25 level 0]
26 (if (= level depth)
27 (tree root)
28 (do
29 (dorun (map
30 #(doto %
31 (.setLeftChild (node (counter)))
32 (.setRightChild (node (counter))))
33 base))
34 (recur
35 (apply concat (map #(vector (.toLeft %) (.toRight %))
36 base))
37 (inc level)))))))
40 (defn test-shittiness [n]
41 (time (do (.bfs (make-big-ass-tree n)) nil)))