On 9 March 2010 06:57, Jonathan Shore <jonathan.sh...@gmail.com> wrote: > the second because maps clearly are not "near the metal"
maps are actually very very efficiently implemented. Small maps are especially efficient as they are implemented as array maps. user=> (type {:a 1, :b 2}) clojure.lang.PersistentArrayMap At ten entries you get hash-maps, and these are still great. user=> (type {:a 1, :b 2, :c 3, :d 4, :e 5, :f 6, :g 7, :h 8, :i 9, :j 10}) clojure.lang.PersistentHashMap You can also define structs which gives a slight optimization. I have yet to find a case where I would prefer a struct over a map though. You also have the option of writing a Java class. Clojure allows pretty much any optimization you can throw at a problem. All the tools are there if you really need to crank out the cpu cycles or memory bytes. But the provided data structures are really really good. I would encourage you to embrace the Clojure data structures and use them as much as possible with as little ceremony as possible, and only look to optimize when you find it necessary to meet your performance/memory goals. For some really specific information on optimizing array access you might be interested in this article http://clj-me.cgrand.net/category/interop/ where Christophe Grand explores the effects of type hinting on arrays and multi-dimensional arrays. The details can be a bit overwhelming so I only recommend it if you are really keen on diving deep! You might also be interested in this library by Konrad (I've not used it but KH libraries are usually great!) http://code.google.com/p/clj-multiarray/ Regards, Tim. -- 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