The second one is actually a PersistentArrayMap and hence properties
that might indicate (falsely) that it's a sorted-map (aka
PersistentTreeMap). Clojure uses PersistentArrayMap for small maps as
an optimisation and automatically promotes to PersistentHashMap when
the number of items crosses a certain threshold (32, IIRC).

Regards,
BG

On Mon, Sep 30, 2013 at 3:54 PM, Gavin Sinclair <gsincl...@gmail.com> wrote:
> I have a value 'y' in my REPL that is a sequence containing two sequences of
> numbers:
>
> (def y '(
>   (15 18 17 17 16 19 16 10 21 16 21 23 19 16 18 15 21 14 21
>    12 26 17 13 22 26 16 14 17 11 15 16 18 13 10 18 18 19 13
>    14 17 19 18 15 20 20 17 20 19 12 20 14 21 13 17 15 22 17
>    21 13 15 16 17 14 21 14 15 17 16 25 22 13 19 23 20 16 16
>    17 13 15 19 20 14 15 17 13 17 11 17 16 20 16 20 15 14 13
>    18 18 17 15 16 15 18 28 12 20 16 17 22 20 23 15 16 21 24
>    18 18 18 18 14 18 21 15 12 19 19 16 12 15 21 19 18 17 16
>    17 16 18 18 12 18 18 17 20 21 15 20 19 19 15 21 17 13 18
>    11 19 18 21 17 23 15 16 17 17 15 17 17 15 15 14 19 18 18
>    14 17 14 18 25 24 11 20 15 13 20 18 16 20 20 16 16 18 15
>    18 22 18)
>
>    (24 18 20 17 19 19 20)
>   ))
> When I ask for the frequencies of the two sequences, one is a sorted map and
> the other is unsorted.
>
> => (keys (frequencies (first y)))
> (10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 28)
> => (keys (frequencies (second y)))
> (24 18 20 17 19)
>
> The classes of the maps don't indicate that the first map is indeed sorted,
> but it cannot be a coincidence that they keys are returned in order.  (I
> tried it with some more data concatenated and it was still in order.)
>
> The source for 'frequencies' (version 1.5.1) does not reveal to me why I get
> sorted in one case and unsorted in the other.  It must be to do with the
> length of the sequence, but what is the full explanation?
>
> Thanks,
> Gavin
>
> --
> --
> 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/groups/opt_out.



-- 
Baishampayan Ghose
b.ghose at gmail.com

-- 
-- 
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/groups/opt_out.

Reply via email to