array-map preserving order is a property of its implementation, but not a
promise to those who use them.

Adding a key/value pair to an array-map that takes it over a certain
threshold size changes its implementation to a hash-map, which in general
changes the seq order completely.  This is by design, because operations on
large hash-maps are move efficient than operations on large array-maps.

If you want a map that preserves order, check out the various variants of
ordered maps mentioned in the Clojure cheat sheet (although it is not an
exhaustive list of such implementations): http://jafingerhut.github.io
Check especially the section on Maps, subsection "Create ordered".

In particular the 'ordered-map' constructor creates maps that are
guaranteed to preserve the order in which keys were inserted for the first
time.

Andy

On Sun, Aug 9, 2015 at 6:28 PM, Young Kim <philo...@gmail.com> wrote:

> This works well as excepted. The order of input elements is maintained.
>
> (into (array-map) [[1 :a] [2 :b] [3 :c] [4 :d] [5 :e] [6 :f] [7 :g] [8
> :h]])
> ; => {1 :a, 2 :b, 3 :c, 4 :d, 5 :e, 6 :f, 7 :g, 8 :h}
>
> However, as soon as the number of the input elements exceeds 9, the order
> is not maintained any more.
>
> (into (array-map) [[1 :a] [2 :b] [3 :c] [4 :d] [5 :e] [6 :f] [7 :g] [8 :h]
> [9 :i]])
> ; => {7 :g, 1 :a, 4 :d, 6 :f, 3 :c, 2 :b, 9 :i, 5 :e, 8 :h}
>
> Is this a bug or the intended result?
>
> --
> 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
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to