diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/test_mega_tree.clj	Tue Oct 18 01:17:49 2011 -0700
     1.3 @@ -0,0 +1,41 @@
     1.4 +(ns coderloop.test-mega-tree)
     1.5 +
     1.6 +(rlm.ns-rlm/ns-clone rlm.light-base)
     1.7 +(import '[com.coderloop.puzzles Megafasttree Megafasttree$Node])
     1.8 +
     1.9 +
    1.10 +(defn node [n]
    1.11 +  (Megafasttree$Node. n))
    1.12 +
    1.13 +
    1.14 +(defn tree [root]
    1.15 +  (doto (Megafasttree.)
    1.16 +    (.addRoot root)))
    1.17 +
    1.18 +
    1.19 +(defn make-counter []
    1.20 +  (let [a (atom -1)]
    1.21 +    (fn count [] (swap! a inc))))
    1.22 +
    1.23 +
    1.24 +(defn make-big-ass-tree [depth]
    1.25 +  (let [counter (make-counter)
    1.26 +	root (node (counter))]
    1.27 +    (loop [base [root]
    1.28 +	   level 0]
    1.29 +      (if (= level depth)
    1.30 +	(tree root)
    1.31 +	(do
    1.32 +	  (dorun (map
    1.33 +		  #(doto %
    1.34 +		     (.setLeftChild (node (counter)))
    1.35 +		     (.setRightChild (node (counter))))
    1.36 +		  base))
    1.37 +	  (recur
    1.38 +	   (apply concat (map #(vector (.toLeft %) (.toRight %))
    1.39 +			base))
    1.40 +	   (inc level)))))))
    1.41 +	   
    1.42 +
    1.43 +(defn test-shittiness [n]
    1.44 +  (time (do (.bfs (make-big-ass-tree n)) nil)))