Re: Bindings Problem
Re: Bindings Problem
- Subject: Re: Bindings Problem
- From: Jeffrey Oleander <email@hidden>
- Date: Mon, 18 Jan 2010 09:01:42 -0800 (PST)
> On Sun, 2010/01/17, Ken Thomases <email@hidden> wrote:
>> On 2010 Jan 17, at 11:15, Jeffrey Oleander wrote:
>>> On Sat, 2010/01/16, Ken Thomases <email@hidden>
> wrote:
>>>> On 2010 Jan 14, at 17:11, Carter R. Harrison wrote:
>>>> My model is an NSMutableSet that contains
>>>> NSMutableDictionaries.
>>>
>>> I think this is asking for trouble. A set of
>>> mutable dictionaries doesn't make much sense.
>>>
>>> ..."Equal" is determined by the -isEqual: and
>>> -hash methods, not by identity (memory location).
>> So, it's quite possible that he has a "hash" used by
>> the NSMutableSet which doesn't depend on the contents
>> of the mutable dictionary once it's been created.
>
> Huh? The hash in question is that of the mutable
> dictionaries. He doesn't get to decide this.
> It's a near certainty that the hash of a dictionary is
> sensitive to its contents. First, logically, how else
> would the NSDictionary implement equality? Second, the
> documentation I cited virtually asserted that it's so.
>
> So, if you mutate a dictionary while it's inside a
> collection, that will cause trouble. The documentation
> I cited says this, too, without equivocation.
>
> He also doesn't get to decide on the hash of the set, if
> that's what you were thinking about.
>
> He could implement some custom class and decide how its
> hash is implemented, but that's beside the point I was
> making. In fact, that was one of my suggested
> solutions.
>
> In other words, I'm not sure what you're trying to say.
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Collections/Articles/Sets.html
"Set Fundamentals: Note that if mutable objects are stored in a set, either the hash method of the objects shouldn’t depend on the internal state of the mutable objects or the mutable objects shouldn’t be modified while they’re in the set (note that it can be difficult to know whether or not a given object is in a collection)."
So, you can use your own hash function to determine where in the set each item is stored. In this case, each item stored in the set is an NSMutableDictionary.
http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/Reference/Reference.html
"Internally, a dictionary uses a hash table to organize its storage and to provide rapid access to a value given the corresponding key. However, the methods defined in this cluster insulate you from the complexities of working with hash tables, hashing functions, or the hashed value of keys. The methods described below take keys directly, not their hashed form."
So, you may use your own hash function to create your keys... or not, as you wish. But then the NSDictionary and NSMutableDictionary will hash the keys you pass to their methods using their own, internal, hash function, to determine where objects are stored in the dictionary.
But my primary point was to ask the original poster to think about why he is using this arrangement of instances of NSMutableDictionary stored in an NSMutableSet.
_______________________________________________
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