Re: Binary search on sorted NSArray in Cocoa?
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