Use this if you want a sorted map: http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/sorted-map
You are using the map literal, which corresponds to the hash map.
Use this if you want a sorted map: http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/sorted-map
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
because of performance reasons, hash-maps are not ordered.
the fact that they are ordered for the first 32 elements is just an implementation detail you shouldn't rely on
--
I know the sorted-map, but my question is : why the map is not 'ordered' when size is larger than 32 ?
I know the sorted-map, but my question is : why the map is not 'ordered' when size is larger than 32 ?Because a hash-map is never guaranteed to be sorted. In your case, it sounds like Clojure is being smart and using a different implementation for small maps (say, less than 32 elements) than it is using for larger maps. This is probably because there's some clever optimization that can be done for very small maps that becomes a pessimization as the map grows larger. The data structure that's being used behind the scenes for small maps might *happen* to have the property of being sorted, but if so, it is just an implementation quirk and you can't rely on that fact in your code. Sorted order is simply not part of the hash-map contract. The 32 element behind-the-scenes limit might change tomorrow, after someone does an analysis and determines that really, three different implementations should be used, one for up to 16 elements, one for up to 128, and one for more. Who knows?
--