• 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: Why doesn't CFDictionaryContainsKey() work?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • [SOLVED] Why doesn't CFDictionaryContainsKey() work?
      • From: "Alan Smith" <email@hidden>
References: 
 >Why doesn't CFDictionaryContainsKey() work? (From: "Alan Smith" <email@hidden>)

  • Prev by Date: Using NSTextCell to act like the Address Book in custom NSTextView
  • Next by Date: Re: Garbage collection in Leopard - not an NDA answer
  • Previous by thread: Re: Why doesn't CFDictionaryContainsKey() work?
  • Next by thread: [SOLVED] Why doesn't CFDictionaryContainsKey() work?
  • Index(es):
    • Date
    • Thread