Why Does Hash Apparently Reorder Its Internal Representation AndOther Associated Ponderings

H

Hal Fulton

Phrogz said:
I don't. I wouldn't call most JavaScript engines 'fast', but I suspect
that has to do with aspects other than the native Object type.

Without having tried it, I would think that preserving insertion order
would be a (small) memory size addition to each hash (as you've
mentioned before), a *tiny* slowdown in the speed to store a new entry,
and no performance change in accessing an entry.

Anyhow, because I'm too lazy to do so, you (or someone else) can get
source code for the SpiderMonkey[1] and Rhino[2] and check out how
insertion order is preserved on Object.

[1] http://www.mozilla.org/js/spidermonkey/ - the C-based JS engine
[2] http://www.mozilla.org/rhino/ - the Java-based JS engine

Haha... I've put that in my notes. That's all I guarantee right now.

Don't ever get in a laziness contest with a master.


Hal
 
D

David Vallner

Hi --


You mean TMTOTMTOWTDIS? :)

Groan.

And while we're sliding horribly Hoff topic, is it just me, or is there
an uncanny amount of 'The Newbie that cried "Wolf!"' (or rather "Bug!")
threads cropping out lately? Not like I'm complaining, they sidetrack
into relatively interesting, if not too related exchanges very soon, but
still.

David Vallner
 
R

Rick DeNatale

The fact that something can be "sorted" at all is only because it
has an order, i.e., is sequential.

Uh, no.

Whether it can be sorted depends on whether the contents are comparable.

irb(main):004:0> class Foo
irb(main):005:1> end
=> nil
irb(main):006:0> [Foo.new, Foo.new].sort
NoMethodError: undefined method `<=>' for #<Foo:0xb7dfe658>
from (irb):6:in `sort'
from (irb):6
from :0
 
M

Matthew Johnson

I don't think 'ordered' is a good name for something sorted by
Uh, no.

Whether it can be sorted depends on whether the contents are
comparable.

Both are partly true. The sorting depends on comparable, but if the
data structure is not sequencable (for lack of a better term) the
results of sorting will need to be returned in something that is
(such as an Array) rather than updated in place. In other words, you
could implement #sort, but not #sort!.

Matthew
 
H

Hal Fulton

Rick said:
Uh, no.

Whether it can be sorted depends on whether the contents are comparable.

I wasn't speaking in a Ruby sense. And even if I were, there
are other ways of sorting besides calling the sort method.


Hal
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top