Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
assoc! order problem
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
llj098  
View profile  
 More options Aug 3 2012, 8:03 pm
From: llj098 <liulijin.w...@gmail.com>
Date: Fri, 3 Aug 2012 17:03:51 -0700 (PDT)
Local: Fri, Aug 3 2012 8:03 pm
Subject: assoc! order problem

Hi list,

I'm learning Clojure now and  I was confused by assoc!.

Here is my code , I want to use the code to distinct items (I cannot use
'distinct' function here for some reasons.)

(defn fn2[x]
  (vals (persistent!
    (reduce (fn [ret l] (assoc! ret l l ))
      (transient {}) x))))

user=> (fn2 (range 32))
(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
28 29 30 31)
user=> (fn2 (range 33))
(0 32 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31)
user=> (fn2 (range 50))
(0 32 1 33 2 34 3 35 4 36 5 37 6 38 7 39 8 40 9 41 10 42 11 43 12 44 13 45
14 46 15 47 16 48 17 49 18 19 20 21 22 23 24 25 26 27 28 29 30 31)

*So my question is : ** why the result is not ordered when the size of
input is larger than 32?*

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeff Heon  
View profile  
 More options Aug 4 2012, 3:53 pm
From: Jeff Heon <jfh...@gmail.com>
Date: Sat, 4 Aug 2012 12:53:04 -0700 (PDT)
Local: Sat, Aug 4 2012 3:53 pm
Subject: assoc! order problem

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bronsa  
View profile  
 More options Aug 4 2012, 3:59 pm
From: Bronsa <brobro...@gmail.com>
Date: Sat, 4 Aug 2012 21:59:30 +0200
Local: Sat, Aug 4 2012 3:59 pm
Subject: Re: assoc! order problem

Note that you can't use a sorted-map in a transient

2012/8/4 Jeff Heon <jfh...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Warren Lynn  
View profile  
 More options Aug 4 2012, 5:34 pm
From: Warren Lynn <wrn.l...@gmail.com>
Date: Sat, 4 Aug 2012 14:34:51 -0700 (PDT)
Local: Sat, Aug 4 2012 5:34 pm
Subject: Re: assoc! order problem

I have not used transient yet so I don't understand your code. But for
ordered maps, I use ArrayMap.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
llj098  
View profile  
 More options Aug 5 2012, 4:10 am
From: llj098 <liulijin.w...@gmail.com>
Date: Sun, 5 Aug 2012 01:10:05 -0700 (PDT)
Local: Sun, Aug 5 2012 4:10 am
Subject: Re: assoc! order problem

thanks for reply,

I know the sorted-map, but my question is : *why the map is not 'ordered'
when size is larger than 32 ? *
*
*
*
*


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bronsa  
View profile  
 More options Aug 5 2012, 4:37 am
From: Bronsa <brobro...@gmail.com>
Date: Sun, 5 Aug 2012 10:37:17 +0200
Local: Sun, Aug 5 2012 4:37 am
Subject: Re: assoc! order problem

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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Evan Mezeske  
View profile  
 More options Aug 5 2012, 4:40 am
From: Evan Mezeske <emeze...@gmail.com>
Date: Sun, 5 Aug 2012 01:40:18 -0700 (PDT)
Local: Sun, Aug 5 2012 4:40 am
Subject: Re: assoc! order problem

> 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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian Sperandio  
View profile  
 More options Aug 5 2012, 5:31 am
From: Christian Sperandio <christian.speran...@gmail.com>
Date: Sun, 5 Aug 2012 11:31:44 +0200
Local: Sun, Aug 5 2012 5:31 am
Subject: Re: assoc! order problem

Hi,

By default, maps are array-map for short map and hash map for larger one.
That explains why the map seems sorted at the beginning.

Christian

Le 5 août 2012 à 10:40, Evan Mezeske <emeze...@gmail.com> a écrit :


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »