• 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: Binary search on sorted NSArray in Cocoa?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Binary search on sorted NSArray in Cocoa?


  • Subject: Re: Binary search on sorted NSArray in Cocoa?
  • From: Ken Thomases <email@hidden>
  • Date: Tue, 6 Jan 2009 22:24:28 -0600

On Jan 6, 2009, at 10:42 AM, Karan, Cem (Civ, ARL/CISD) wrote:

I know I'm being pedantic, but just to make sure, will the following code work?

// mySortedArray is an NSArray of NSString instances that has been sorted
// via caseInsensitiveCompare:. [...]


	CFRange arrayRange;
	arrayRange.location = 0;
	arrayRange.length = [mySortedArray count];

	CFIndex stringIndex;
	stringIndex = CFArrayBSearchValues(	mySortedArray,
							arrayRange,
							myString,
							CFStringCompare,

kCFCompareForcedOrdering);

If the array has been sorted with caseInsensitiveCompare:, then you need to provide string comparison flags to match. You would need kCFCompareCaseInsensitive|kCFCompareNonliteral. Passing kCFCompareForcedOrdering when you didn't use NSForcedOrderingSearch when originally sorting the array seems like asking for trouble, too.


Regards,
Ken

_______________________________________________

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


  • Follow-Ups:
    • RE: Binary search on sorted NSArray in Cocoa?
      • From: "Karan, Cem (Civ, ARL/CISD)" <email@hidden>
References: 
 >Binary search on sorted NSArray in Cocoa? (From: "Karan, Cem (Civ, ARL/CISD)" <email@hidden>)
 >Re: Binary search on sorted NSArray in Cocoa? (From: "Adam R. Maxwell" <email@hidden>)
 >RE: Binary search on sorted NSArray in Cocoa? (From: "Karan, Cem (Civ, ARL/CISD)" <email@hidden>)

  • Prev by Date: How to get the current view controller in iPhone application
  • Next by Date: Re: How to get the current view controller in iPhone application
  • Previous by thread: RE: Binary search on sorted NSArray in Cocoa?
  • Next by thread: RE: Binary search on sorted NSArray in Cocoa?
  • Index(es):
    • Date
    • Thread