Re: Transient HashMaps with not more than 8 elements?
On Sat, May 29, 2010 at 08:52:59PM -0700, ataggart wrote: Yup, you need to use the transient functions, e.g., assoc!, just as you would the persistent functions. This is nice since you can write your code in the persistent style, then if you need to make some performance tweaks, simply add some exclamation points; the structure of the code remains the same. As for why you see what you're seeing, the assoc! does generally mutate the passed in map, thus you see some map entries. The rub is that assoc! is smart enough to choose the right implementation for the size; for small maps (0-8 entries) an array-map is used (and the {} literal is also an array-map). Once you assoc! the 9th element, the function instead returns a hashmap, thus no longer mutating the instance referenced by thm. Ah, yes: user (loop [thm (transient {}), i 0] (if (= 10 i) (persistent! thm) (recur (assoc! thm i i) (inc i {0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7, 8 8, 9 9} So, a fundamental misconception of mine then ;) Thanks! Daniel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Transient HashMaps with not more than 8 elements?
Hi, recently I discovered the following behaviour of transient hash-maps which seems a bit odd to me: user (def thm (transient {})) #'user/thm user (dotimes [i 10] (assoc! thm i i)) nil user (count thm) 8 user (persistent! thm) {0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7} The same happens if i goes up to 100, 1000, ... Is this a bug or is this a fundamental misconception of mine? Daniel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: ClassNotFoundException with def
On Sun, Jun 28, 2009 at 01:25:15PM -0700, hoeck wrote: [...] Tried it, and had the same results. Somehow defining a class object as a root value triggers some mechanism to load it with the root classloader instead of the clojure one. However, putting /home/me on the classpath using -cp works. Thank you, erik! Daniel --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---