Hi Christophe,
I wonder about the real difference of that. Do you have metrics of
both implementations to compare convenience?
Anyway.. my point is that I'm wondering why Hash don't answers to
size itself with the best (possible at the moment) implementation to
query and answer it's actual size?
If your algorithm introduces, let's say 2% o more better
performance, so what Prototype team is waiting to adopt it 1)
increasing the semantic power of Hash 2) without injecting complexity
3) preventing people to do hackish things like injecting that
algorithm in their programs/pages just to know a size 4) hiding
algorithms that tomorrow could be inproved 5) futurely improving them
and automagically everybody's work because they will be prevented to
refactor one line of code in their work (should I continue?) ?
cheers,
Sebastian
On 2 jul, 14:43, Christophe Porteneuve <[EMAIL PROTECTED]> wrote:
> Daniel Eben Elmore a écrit :
>
> > What's the best way to get the length of a hash? ie. the number of keys?
>
> There's no really fast way, so you can go short or efficient. Short:
>
> - with an actual Hash: hash.size()
> - with a regular object: Object.keys(o).length
>
> Efficient: you'll need to write custom functions, /a la RobG/ ;-):
>
> - with an actual Hash:
>
> // Post Enumerable mix-in:
> Hash.prototype.size = function() {
> var result = 0;
> for (var key in this) {
> if (this[key] && this[key] == Hash.prototype[key]) continue;
> ++result;
> }
> return result;
> };
>
> - with a regular object:
>
> Object.getKeyCount = function(o) {
> var result = 0;
> for (var key in o)
> ++resule;
> return result;
> };
> // Then: Object.getKeyCount(o)
>
> 'HTH
>
> --
> Christophe Porteneuve a.k.a. TDD
> "[They] did not know it was impossible, so they did it." --Mark Twain
> Email: [EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---