Here's a use case:

I have objects that register themselves as listeners for system
notifications. When an object registers, I want to make sure we don't
add that object twice. If the listener list is an array, then I have
to iterate through the array every time we add a listener, which is
expensive with a lot of listeners. If I could instead store the
listeners in a hash, the add operation would just have to check if the
object exists in the hash instead of looping through the entire array
of listeners to check equality. I found this group because I'm looking
for such a solution without having to implement toHashKey().


On Sep 11, 9:05 am, Allen Madsen <bla...@gmail.com> wrote:
> I'm with kangax on this one. I have never needed this functionality.
>
> Allen Madsenhttp://www.allenmadsen.com
>
> On Fri, Sep 11, 2009 at 11:59 AM, James Aimonetti
>
> <james.aimone...@gmail.com> wrote:
>
> > My interest was piqued when reading
> >http://www.timdown.co.uk/jshashtable/index.htmlif that helps further
> > discussion of including the feature.
>
> > kangax wrote:
>
> >> On Sep 11, 7:08 am, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> >> [...]
>
> >>> @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.)
>
> >> I would actually like to hear about use cases too. Developing web apps
> >> for 3 years now I haven't ever needed to use hash with arbitrary keys.
> >> It doesn't mean such thing is not useful; I'm just failing to see how
> >> (and where) it can be applied in practice (especially in a context of
> >> web apps).
>
> >> [...]
>
> >> --
> >> kangax
>
> > --
> > James Aimonetti
> > mobile: 314.809.6307
> > work: 540.459.2220
> > email: james.aimone...@gmail.com
> > website:http://jamesaimonetti.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
-~----------~----~----~----~------~----~------~--~---

Reply via email to