Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Ordered Hash Usefulness

Reply
Thread Tools

Ordered Hash Usefulness

 
 
Ralph Siegler
Guest
Posts: n/a
 
      11-22-2007
On Nov 21, 2007 2:29 PM, Trans <(E-Mail Removed)> wrote:
>
> facets/dictionary, brought to you by jan molic might say you some
> time. unless you're writing it in c of course --speaking if which and
> good c implementations out there?
>


thank you for pointing me at the facets project, I've been away from
following ruby-lang for awhile, some great and useful data structure
handling in there. But of course the docs and install have some
issues which I have to figure out (typical of anything gem related)


sudo task/install
task/install:18:in `initialize': No such file or directory -
meta/project.yaml (Errno::ENOENT)
from task/install:18:in `open'
from task/install:18:in `start_install'
from task/install:92


*sigh*

Ralph Siegler

 
Reply With Quote
 
 
 
 
Trans
Guest
Posts: n/a
 
      11-22-2007


On Nov 21, 9:15 pm, "Ralph Siegler" <(E-Mail Removed)> wrote:
> On Nov 21, 2007 2:29 PM, Trans <(E-Mail Removed)> wrote:
>
>
>
> > facets/dictionary, brought to you by jan molic might say you some
> > time. unless you're writing it in c of course --speaking if which and
> > good c implementations out there?

>
> thank you for pointing me at the facets project, I've been away from
> following ruby-lang for awhile, some great and useful data structure
> handling in there. But of course the docs and install have some
> issues which I have to figure out (typical of anything gem related)
>
> sudo task/install
> task/install:18:in `initialize': No such file or directory -
> meta/project.yaml (Errno::ENOENT)
> from task/install:18:in `open'
> from task/install:18:in `start_install'
> from task/install:92


Ah, Thanks for reporting this! Sorry for the inconvenience. I'll have
a fix out this afternoon.

HTG,
T.

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      11-22-2007
2007/11/21, MenTaLguY <(E-Mail Removed)>:
> On Thu, 22 Nov 2007 05:25:07 +0900, Robert Klemme <(E-Mail Removed)> wrote:
> >> In Ruby 1.8 the enumeration order of a Hash is undefined, in Ruby 1.9,
> >> unless it's been backed out recently, it's defined as above.

> >
> > Does Ruby 1.9 really impose the overhead to maintain insertion order for
> > *every* Hash?

>
> I asked matz about that on ruby-core. The overhead turns out to be very
> small; 1.9 maintains a doubly-linked list of hash elements, which has
> constant-time insertion and removal.


Yeah, clearly.

> Memory overhead is two words per
> hash element.


I'm less concerned with the CPU overhead but rather the memory overhead.

> We may implement the 1.9 ordering in JRuby soon, as it solves a number of
> problems with concurrency and iterator stability.


Hm, concurrently iterating and modifying is a bad idea anyway IMHO.
But I can see how some issues can be resolved with this. I just think
that making this impl. the default for all Hashes might have some
adversary effects. I'd rather leave the old impl as is and add
another (sub) class that has the ordered behavior.

Kind regards

robert

--
use.inject do |as, often| as.you_can - without end

 
Reply With Quote
 
Trans
Guest
Posts: n/a
 
      11-22-2007

On Nov 22, 6:16 am, Trans <(E-Mail Removed)> wrote:

> > thank you for pointing me at the facets project, I've been away from
> > following ruby-lang for awhile, some great and useful data structure
> > handling in there. But of course the docs and install have some
> > issues which I have to figure out (typical of anything gem related)


The gem install should be okay. The docs are not generated
automatically on purpose btw, b/c Facets has special doc requirements.
You can find them on-line (http://facets.rubyforge.org/learn.html).
They still have some rough edges, but I'm working on an update this
week.

> > sudo task/install
> > task/install:18:in `initialize': No such file or directory -
> > meta/project.yaml (Errno::ENOENT)
> > from task/install:18:in `open'
> > from task/install:18:in `start_install'
> > from task/install:92

>
> Ah, Thanks for reporting this! Sorry for the inconvenience. I'll have
> a fix out this afternoon.


New release 2.1.2, should fix it for you.

Let me know if you had any other problems.

T.

 
Reply With Quote
 
Daniel Sheppard
Guest
Posts: n/a
 
      11-22-2007
=20
> Well, that's just /one/ way to order a Hash. You could as=20
> well order a=20
> Hash by the key's natural order (<=3D>).


Yes, but nothing extra needs to be added to Hash to get a=20
natural order enumeration - A hash.sort.each sorts that out.

An ordered hash almost always refers to insertion order, as
that's the order that is unrecoverable from a regular hash.

Dan.

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      11-23-2007
2007/11/23, Daniel Sheppard <(E-Mail Removed)>:
>
> > Well, that's just /one/ way to order a Hash. You could as
> > well order a
> > Hash by the key's natural order (<=>).

>
> Yes, but nothing extra needs to be added to Hash to get a
> natural order enumeration - A hash.sort.each sorts that out.


Which would still be something different than a Hash that
automatically maintains this order. Granted, insertions would be
O(log(N)) instead of O(1) but lookups could still be O(1). And you
save the memory overhead of Hash#sort.

> An ordered hash almost always refers to insertion order, as
> that's the order that is unrecoverable from a regular hash.


I just find the terminology a bit muddy because "ordered" in itself is
too ambiguous. That's all I wanted to point out all the time.

Kind regards

robert

--
use.inject do |as, often| as.you_can - without end

 
Reply With Quote
 
Ralph Siegler
Guest
Posts: n/a
 
      11-25-2007
On Nov 22, 2007 5:16 AM, Trans <(E-Mail Removed)> wrote:
>
> Ah, Thanks for reporting this! Sorry for the inconvenience. I'll have
> a fix out this afternoon.
>
>

wow, thanks much for very speedy and surprising response! It does
indeed work and well.

another minor change for it's README on next version would be to
instruct to run task/install not task/setup

I had wimped out that day and instead of using my ruby from source
installed my distro's ruby (which of course was spread over many
packages) and it's gems and then installed facets that way. An
amazing and useful collection it is.

 
Reply With Quote
 
James Edward Gray II
Guest
Posts: n/a
 
      11-26-2007
On Nov 21, 2007, at 1:51 PM, Ralph Siegler wrote:

> On Nov 13, 2007 2:53 PM, Devi Web Development
> <(E-Mail Removed)> wrote:
>
>>
>> I've been wondering what the real usefulness of an ordered hash is.

>
>
> writing one write now to deal with csv text files, like to use "column
> names" internally but have to respect the proper order when writing
> out.


FasterCSV does this, if you just want an out-of-the-box solution.

James Edward Gray II

 
Reply With Quote
 
Ralph Siegler
Guest
Posts: n/a
 
      11-26-2007
On Nov 26, 2007 12:49 PM, James Edward Gray II
<(E-Mail Removed)> wrote:

> FasterCSV does this, if you just want an out-of-the-box solution.
>
> James Edward Gray II
>
>


thanks for bringing useful in future project to my attention (
http://fastercsv.rubyforge.org/ ) , but for what I'm doing now I'm
actually reading in a sort of "outline" and constructing multiple
product & option cvs files for database tables, the ordered hash of
facets/dictionary.rb is quite sufficient & dirty-quick

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Ordered list inside ordered list DL Javascript 6 11-21-2009 11:43 PM
Usefulness of %hd in printf Old Wolf C Programming 34 01-24-2007 09:29 PM
Usefulness of Norton's "GoBack" dr_dementia@excite.com Computer Support 2 03-28-2005 08:17 PM
DVD burner usefulness Special Ed Computer Support 7 11-24-2004 12:44 AM



Advertisments