[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Preserve insert order in a Hash

Yukihiro Matsumoto

9/18/2008 10:28:00 AM

Hi,

In message "Re: Preserve insert order in a Hash"
on Thu, 18 Sep 2008 18:54:20 +0900, "Thomas B." <tpreal@gmail.com> writes:

|Could anybody explain why this feature was added?

Useful for some cases, especially for keyword arguments.

|Isn't it going to slow down the operations on the Hash?

No. hash reference operation does not touch order information, only
for iteration. Memory consumption increased a bit.

matz.

2 Answers

Rick DeNatale

9/18/2008 12:44:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Thu, Sep 18, 2008 at 6:28 AM, Yukihiro Matsumoto <matz@ruby-lang.org>wrote:

> Hi,
>
> In message "Re: Preserve insert order in a Hash"
> on Thu, 18 Sep 2008 18:54:20 +0900, "Thomas B." <tpreal@gmail.com>
> writes:
>
> |Could anybody explain why this feature was added?
>
> Useful for some cases, especially for keyword arguments.
>
> |Isn't it going to slow down the operations on the Hash?
>
> No. hash reference operation does not touch order information, only
> for iteration. Memory consumption increased a bit.
>

If I remember correctly, it's been a while since I looked at the code, 1.9
implements this by using a singly linked list which introduces a small
overhead only when elements are either added or deleted.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...

Nobuyoshi Nakada

9/18/2008 12:47:00 PM

0

Hi,

Yukihiro Matsumoto wrote in [ruby-talk:315237]:
At Thu, 18 Sep 2008 19:28:28 +0900,
> |Could anybody explain why this feature was added?
>
> Useful for some cases, especially for keyword arguments.

And the performance of iterations improved a little, but
significantly.

--
Nobu Nakada