Created
April 9, 2012 21:26
-
-
Save bnyeggen/2346658 to your computer and use it in GitHub Desktop.
Interning with Clojure
This file contains 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 intern-map | |
[m] | |
(let [val-set (set (vals m))] | |
(into {} | |
(for [[k v] m] | |
{k (val-set v)})))) | |
(defn make-duped-hashmap [] | |
(into {} | |
(for [k (range 10000000)] | |
[k (vec (repeatedly 3 #(rand-int 10)))]))) | |
(def a (make-duped-hashmap));4,939,276,440 bytes used | |
(def a nil);and do a full GC | |
(def a (intern-map (make-duped-hashmap)));493,937,040 bytes used |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment