In my testing NSDictionary's objectForKey: is extremely fast, with NSSet's 
member: coming in second and everything else trailing waayyy back. 

I was using simple immutable keys and complex, mutable objects, which may have 
affected the results. YMMV.

So if you make a dictionary where the ZIPs are keys, with whatever you want as 
the objects, then your validity search consists of objectForKey: followed by a 
nil check on the result. If you make the result useful (perhaps the 
city,state?), even better.

I have used NSDictionaries with over a million keys and never saw a performance 
hit worth worrying about. (NOT TESTED ON iPHONE, HOWEVER) Note that if you use 
immutable NSStrings for your keys, and use the same string for the object and 
the key, only one instance of the key will be created, making the overhead of 
this seemingly wasteful strategy very small. (This is because although 
NSDictionary "copies" its keys, -copy on an immutable object is just a retain).

> To help make this thread more Cocoa-y, I would like to ask: Do the  
> NSSet and NSArray methods like -containsObject perform in a fashion  
> comparable to a home-rolled binary search? I greatly prefer to use the  
> Cocoa stuff rather than try to remember/learn how to properly code  
> such things.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to