• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSDictionary trouble
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDictionary trouble


  • Subject: Re: NSDictionary trouble
  • From: Shawn Rutledge <email@hidden>
  • Date: Tue, 19 Jan 2010 16:09:20 -0700

On Tue, Jan 19, 2010 at 2:33 PM, Jeremy Pereira <email@hidden> wrote:
>
> On 19 Jan 2010, at 16:53, Shawn Rutledge wrote:
>
>>  I'm accustomed to
>> things like Qt and Java where hashtables can contain anything for both
>> key and value.
>
> This is not true (at least for Java and probably for QT for the same reason).  From the API docs for the Map abstract class:
>
> "Note: great care must be exercised if mutable objects are used as map keys. The behavior of a map is not specified if the value of an object is changed in a manner that affects equals comparisons while the object is a key in the map. "

Well yeah, that's one of the reasons java.lang.String is immutable.
But it helps that java.lang.Object has both hashCode and equals, so
any object can be put into a collection that depends on those... you
just have the option of improving the implementation of those for
better hash distribution, comparing two objects by content rather than
reference location, etc.  I just wanted a hashtable that uses keys by
pointer rather than expecting to copy them.  Nice to know that copying
protocol doesn't mean you have to actually copy it though.

As for C++, you can use template containers to store either pointers
or copies of objects, whichever you like.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSDictionary trouble
      • From: Kyle Sluder <email@hidden>
References: 
 >NSDictionary trouble (From: Shawn Rutledge <email@hidden>)
 >Re: NSDictionary trouble (From: Jeremy Pereira <email@hidden>)

  • Prev by Date: Re: NSDictionary trouble
  • Next by Date: Re: NSDictionary trouble
  • Previous by thread: Re: NSDictionary trouble
  • Next by thread: Re: NSDictionary trouble
  • Index(es):
    • Date
    • Thread