A use case for an ordered hash

B

Bil Kleb

Phillip said:
Using an ordered hash for one
person's benefit would kill the speed and jack up memory usage.

[..] but replacing the Hash is not the way to go.

I don't think anyone is suggesting replacing the
existing Hash. As I see it, the ordered hash would
merely be an alternative to the standard hash.

Regards,
 
R

Rick DeNatale

Phillip said:
Using an ordered hash for one
person's benefit would kill the speed and jack up memory usage.

[..] but replacing the Hash is not the way to go.

I don't think anyone is suggesting replacing the
existing Hash. As I see it, the ordered hash would
merely be an alternative to the standard hash.

Which, as has been shown can be provided without changes to the base
specification/implementation of Ruby.

The fly in the ointment, is that a few of the proponents of
OrderedHash seem to strongly require a literal syntax for the beast.
That's the one thing which seems to require divine intervention <G>.

Personally, I don't feel a burning need for it, and not knowing the
implementation cost, I'm not sure if the idea "pulls it's own weight."
But that's just a personal opinion.

Heck, the old Smalltalk equivalent of hash Dictionary, gave you the
keys as a Set, and the values as a Bag when you asked for them!
 
F

Fergal J Byrne

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rick said:
Phillip said:
Using an ordered hash for one
person's benefit would kill the speed and jack up memory usage.

[..] but replacing the Hash is not the way to go.

I don't think anyone is suggesting replacing the
existing Hash. As I see it, the ordered hash would
merely be an alternative to the standard hash.

Which, as has been shown can be provided without changes to the base
specification/implementation of Ruby.

The fly in the ointment, is that a few of the proponents of
OrderedHash seem to strongly require a literal syntax for the beast.
That's the one thing which seems to require divine intervention <G>.

This functionality is not part of Hash as traditionally
understood, including those new to Ruby. Adding it to the
core Hash in the language will add a space and time cost
to all programs currently using Hash.

If you need a hash with this functionality, create a
mixin module containing the extra code (several examples
have appeared in these threads) and include it where
you need it.

I often have a hankering for this kind of functionality
in random access data structures (database tables more
than in-memory structures), so I can see the use of it.

Doesn't strike me as a must-have addition (or subtraction)
for the core Hash class...

And I wouldn't call it an OrderedHash (suggests sorting
by the data rather than by insertion order). Call the
mixin something like InsertionOrderMemory and you could
conceivably use it for other structures...

- --

regards

fergal byrne
technical director

Adnet Web Development - Building for Business since 1995
http://www.adnet.ie/ t:+353 1 676 4262 aim/skype:FergByrne

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFE6gFqd3SE35LsMPcRAlnwAJwN7FcUim+5ljQ+fliYBc3HVii7RgCghVNO
hveor+GT98zkVDHTW9FNuYc=
=b63O
-----END PGP SIGNATURE-----
 
H

Hal Fulton

Robert said:
Not necessarily
that was why I suggested an
OrderedHash (where insertion would not be slower )
and a
SortedHash (where indeed insertion would be slower)

and iteration (and to_a) would

I meant an ordered hash would be slowed down simply
because you are storing an extra piece of information.



Hal
 
H

Hal Fulton

Rick said:
Phillip said:
Using an ordered hash for one
person's benefit would kill the speed and jack up memory usage.

[..] but replacing the Hash is not the way to go.

I don't think anyone is suggesting replacing the
existing Hash. As I see it, the ordered hash would
merely be an alternative to the standard hash.


Which, as has been shown can be provided without changes to the base
specification/implementation of Ruby.

Sure. And if you didn't have Hash, you could implenent
your own.
The fly in the ointment, is that a few of the proponents of
OrderedHash seem to strongly require a literal syntax for the beast.
That's the one thing which seems to require divine intervention <G>.

Yes. That's the thing which makes hashes in Ruby bearable.
(How do they work in Java? I forgot.)

After all, C has arrays. But even if they were "heterogeneous"
like Ruby arrays, they still wouldn't be as fun and convenient
as the ones in Ruby. And OO is part of that, but syntax is also
part. Notation does matter.
Personally, I don't feel a burning need for it, and not knowing the
implementation cost, I'm not sure if the idea "pulls it's own weight."
But that's just a personal opinion.

Heck, the old Smalltalk equivalent of hash Dictionary, gave you the
keys as a Set, and the values as a Bag when you asked for them!

That would give me a headache. :)


Hal
 
M

Martin DeMello

First there would be the SortedHash and all you sayed was true about it
(save that iteration would be slower, which seems wrong to me).
And then there might be the OrderedHash, which is a Hash without any
overhead, just offering different access methods,
which would implement order this might be a bad idea, as the access sorting
can so easily be done ourselfs.

The thing is, there's no way to preserve insertion order in a hash
without using some extra storage, and taking a bit of extra time on
insertion and deletion. Lookup and iteration would not have their
speed affected, but insertion and deletion definitely would because
you'd have to make sure the insertion order was preserved too.

martin
 
A

ara.t.howard

You did it, thank you, I was *not* talking about InsertionOrder in Hash,
which is of course a
*very* important one, so I want three now!!!
SortedHash
OrderableHash (maybe better naming)
HistoricalHash (the name's a joke of course ;)

my alib has an orderedhash which maintains insertion order.

fyi.

-a
 
J

Just Another Victim of the Ambient Morality

Hal Fulton said:
Rick said:
Phillip Hutchings wrote:
Using an ordered hash for one
person's benefit would kill the speed and jack up memory usage.

[..] but replacing the Hash is not the way to go.

I don't think anyone is suggesting replacing the
existing Hash. As I see it, the ordered hash would
merely be an alternative to the standard hash.


Which, as has been shown can be provided without changes to the base
specification/implementation of Ruby.

Sure. And if you didn't have Hash, you could implenent
your own.
The fly in the ointment, is that a few of the proponents of
OrderedHash seem to strongly require a literal syntax for the beast.
That's the one thing which seems to require divine intervention <G>.

Yes. That's the thing which makes hashes in Ruby bearable.
(How do they work in Java? I forgot.)

I disagree. I dislike the hash literal syntax and I can't believe that
this is the only useful thing about hashes to some people. If the lack of
pretty syntax for hash literals is your problem then life has been pretty
good to you...
 
G

gwtmp01

Which, as has been shown can be provided without changes to the base
specification/implementation of Ruby.

A ordered hash implementation in the standard library would be better
than nothing. Similar to the way that Set is not in Core but is in
the standard library.

A literal syntax would be a bonus but of course would require a change
to core.


Gary Wright
 
A

ara.t.howard

A ordered hash implementation in the standard library would be better
than nothing. Similar to the way that Set is not in Core but is in
the standard library.

A literal syntax would be a bonus but of course would require a change
to core.

not if

require 'orderedhash'

__replaces__ the builtin Hash

-a
 
H

Hal Fulton

Just said:
I disagree. I dislike the hash literal syntax and I can't believe that
this is the only useful thing about hashes to some people. If the lack of
pretty syntax for hash literals is your problem then life has been pretty
good to you...

Haha... I don't think anyone said it's the *only* useful thing. :)
And granted, I dislike it because of the shift key I have to hit,
but I dislike it less than an array of arrays, or a flat list of
ordered pairs.

And yes, life has been good to me... ;)


Hal
 
A

Austin Ziegler

Which, as has been shown can be provided without changes to the base
specification/implementation of Ruby.

Such implementations *are* a bit slower and less efficient since
they're pure Ruby.
The fly in the ointment, is that a few of the proponents of
OrderedHash seem to strongly require a literal syntax for the beast.
That's the one thing which seems to require divine intervention <G>.

Not require, but *desire*.

-austin
 
H

Hal Fulton

not if

require 'orderedhash'

__replaces__ the builtin Hash

No, I think it would still require a core change -- because a
literal would get converted internally before we wanted it to,
right?


Hal
 
A

Austin Ziegler

not if

require 'orderedhash'

__replaces__ the builtin Hash

Which, IIRC, no one but opponents to an (insertion) ordered
associative array with hash-like lookup has proposed seriously.

;)

-austin
 
P

Phrogz

Coming to Ruby from JavaScript (among other paths) I personally dislike
Ruby's two-character Hash delimiter. It's been brought up before, and I
know that the colon makes it harder to parse with symbols, but I wish
we had a one-char (preferably without shift on an English keyboard
layout) hash delimiter.

hash = [ foo:bar, whee~la, dunno|what, delimiter=wouldbe ]

Heck, even two no-shift chars would be a nice improvement:

hash = [ foo--bar, jim..jam ]

....but now I'm hijacking the thread.
 
W

William James

Phrogz said:
Coming to Ruby from JavaScript (among other paths) I personally dislike
Ruby's two-character Hash delimiter. It's been brought up before, and I
know that the colon makes it harder to parse with symbols, but I wish
we had a one-char (preferably without shift on an English keyboard
layout) hash delimiter.

hash = [ foo:bar, whee~la, dunno|what, delimiter=wouldbe ]

Heck, even two no-shift chars would be a nice improvement:

hash = [ foo--bar, jim..jam ]

...but now I'm hijacking the thread.

We already do; it's just that the pompous popinjays refuse to use it.

{ :gee, 'whiz', :gosh, 'darn' }
==>{:gee=>"whiz", :gosh=>"darn"}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top