@Samuel: > I've been working on this too and had quite reasonable performance
I like it, _should_ perform a *lot* better than a straight array given a reasonable distribution of keys. This is similar to what Java's HashMap does (not that I'm holding it up as a model of high performance). @Jim: > Yep, this is Java-esque but that doesn't *always* equal evil! Hardly ever! I'd say hashCode has a place. Let's step back and ask the question: What are the use cases for a hash keyed by non-string objects? Are they compelling? (I'm not saying they aren't, just saying that before running off on an idea, we need to ask the question.) -- T.J. :-) On Sep 11, 11:07 am, Jim Higson <j...@wikizzle.org> wrote: > On Friday 11 September 2009 10:39:14 Samuel Lebeau wrote: > > > > > > > Hi, > > > I think it's indeed a good feature to discuss for 2.0. > > I've been working on this too and had quite reasonable performance > > when using a hash function that avoids collision. > > The simplest implementation consists in storing array of [key, value] > > tuples indexed by `key.toString()` in a vanilla object. > > > i.e. : > > hash.set(true, value1); > > hash.set("true", value2); > > is stored as: > > { "true": [ [true, value1], ["true", value2] ] } > > > Custom classes should override their `toString` method to be > > efficiently stored in such a structure, otherwise fetching a value > > would be as slow as a `Array#find` call. > > Having real hashes allows to implement sets too. > > Would it be reasonable to to look for a hashcode() method which, if present, > is used in preference to toString()? In most cases I could write a hashcode > implementation that runs faster and is more evenly distributed than a human- > readable toString. > > Yep, this is Java-esque but that doesn't *always* equal evil! > > -- > Jim > my wiki ajaxification thing:http://wikizzle.org > my blog:http://jimhigson.blogspot.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---