> --
> 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+unsubscribe@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
Il giorno 05/ago/2012 10.10, "llj098" <liulijin.w...@gmail.com> ha scritto:
> --
> 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+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> 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?
> 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? > -- > 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+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en