Re: Why doesn't CFDictionaryContainsKey() work?
Re: Why doesn't CFDictionaryContainsKey() work?
- Subject: Re: Why doesn't CFDictionaryContainsKey() work?
- From: Aurélien Hugelé <email@hidden>
- Date: Thu, 16 Nov 2006 17:22:45 +0100
I think you do not really understand the NSDictionary interest and usage
- (BOOL)hasKey:(id)key
{
return [[self allKeys] containsObject: key];
}
if equivalent to return ([self objectForKey:key] != nil); except that
your method is zillion times slower and completely defeats the usage
of dictionaries because your look up is O(n) where dictionaries are
usualy O(log(n)) or even O(1).
On 16 nov. 06, at 17:07, Alan Smith wrote:
I added in my category of NSDictionary a method:
- (BOOL)hasKey:(id)key
{
return CFDictionaryContainsKey(self, *key);
}
I didn't get any compiler errors or warnings but when I used it, it
returned 0 every time. So I changed it to this:
- (BOOL)hasKey:(id)key
{
return [[self allKeys] containsObject: key];
}
And that works fine. The only problem I have with the latter code is
that allKeys may be very big and would slow my program down and use a
big chunk of memory.
So, if anyone can quell these fears please tell me.
Cheers, Alan
--
// Quotes from yours truly -------------------------
"You don't forget, you just don't remember."
"Maturity resides in the mind."
"Silence is the Universe's greatest gift."
"When the World realizes that religion really is unnecessary, then it
shall evolve."
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gumitech.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden