Created
December 3, 2014 18:39
-
-
Save erasmas/a3086c6e13a259434e83 to your computer and use it in GitHub Desktop.
This file contains hidden or 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- transform-values [parse-tree values-map] | |
"Replaces all expressions in parsed tree with values from a given map." | |
(loop [loc (zip/vector-zip parse-tree)] | |
(if (zip/end? loc) | |
(zip/root loc) | |
(if (zip/branch? loc) | |
(let [id (last (zip/children loc))] | |
(if (contains? values-map id) | |
(recur (zip/next (zip/replace loc (zip/node [(get values-map id)])))) | |
(recur (zip/next (zip/edit loc #(into [] (butlast %))))))) | |
(recur (zip/next loc))) | |
))) | |
(time | |
(dotimes | |
[_ 100000] | |
(transform-values | |
[:DIV [:ADD [:ID "P1" "exp_2420"] [:ID "P2" "exp_2421"] "exp_2419"] [:ID "P3" "exp_2422"] "exp_2418"] | |
{"exp_2420" 100 "exp_2421" 20 "exp_2422" 5}))) | |
"Elapsed time: 2317.491 msecs" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment