Created
April 25, 2010 22:31
-
-
Save michalmarczyk/378784 to your computer and use it in GitHub Desktop.
demonstrating structural sharing in clojure.lang.PersistentVector instances
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
;; demonstrating structural sharing | |
;; in clojure.lang.PersistentVector | |
;; instances | |
(let [v1 (vec (range 100)) | |
v2 (conj v1 :foo) | |
v3 (conj v1 :bar) | |
v4 (conj (vec (range 100)) :quux) | |
PV-root (doto (.getDeclaredField clojure.lang.PersistentVector "root") | |
(.setAccessible true)) | |
v2-root (.get PV-root v2) | |
v3-root (.get PV-root v3) | |
v4-root (.get PV-root v4)] | |
{:v2-and-v3 (identical? v2-root v3-root) | |
:v2-and-v4 (identical? v2-root v4-root)}) | |
;; evaluates to | |
(comment {:v2-and-v3 true, :v2-and-v4 false}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment