Created
September 25, 2010 10:50
-
-
Save juergenhoetzel/596728 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 mapmap | |
"Return a new map, mapping keys to (keyfn key) and mapping values to | |
(valfn val)" | |
([valfn map] | |
(mapmap identity valfn map)) | |
([keyfn valfn map] | |
(persistent! (reduce | |
(fn [c [k v]] (assoc! c (keyfn k) (valfn v))) | |
(transient {}) | |
map)))) |
Performance using persistant data only:
user> (time ((mapmap identity identity bigmap) :noexist))
"Elapsed time: 513.812028 msecs"
Transients can really speed-up:
user> (time ((mapmap identity identity bigmap) :noexist))
"Elapsed time: 301.332019 msecs"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by http://tech.puredanger.com/2010/09/24/meet-my-little-friend-mapmap/: