Re: iPhone: validate a NSString for US zipcode
Re: iPhone: validate a NSString for US zipcode
- Subject: Re: iPhone: validate a NSString for US zipcode
- From: James Bucanek <email@hidden>
- Date: Fri, 8 Jan 2010 08:23:35 -0700
Paul Bruneau <mailto:email@hidden> wrote
(Thursday, January 7, 2010 11:00 AM -0500):
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.
NSSet (and NSDictionary) use hash tables to organize and look up
their objects/keys. Look up and insertion times are nearly
linear--assuming a well distributed hash function--regardless of
collection size.
NSArray does not impose an order on its contents. While arrays
can be sorted--and as others have pointed out, there are binary
search functions in Core Foundation--NSArray never assumes that
its contents are ordered and searches are always preformed using
a sequential, brute force, comparison of objects.
It's easy to demonstrate all of this by setting a breakpoint in
the -hash and -isEqual: methods of the objects added to a collection.
For ZIP code membership, an NSIndexSet makes a lot more sense.
--
James Bucanek
_______________________________________________
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