Skip to content

Instantly share code, notes, and snippets.

@michalmarczyk
Created April 25, 2010 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michalmarczyk/378784 to your computer and use it in GitHub Desktop.
Save michalmarczyk/378784 to your computer and use it in GitHub Desktop.
demonstrating structural sharing in clojure.lang.PersistentVector instances
;; 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