• 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: iPhone: validate a NSString for US zipcode
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: iPhone: validate a NSString for US zipcode (From: Paul Bruneau <email@hidden>)

  • Prev by Date: Re: wait for sheet result
  • Next by Date: Re: Julian date
  • Previous by thread: Re: iPhone: validate a NSString for US zipcode
  • Next by thread: Re: iPhone: validate a NSString for US zipcode
  • Index(es):
    • Date
    • Thread