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: "Karan, Cem (Civ, ARL/CISD)" <email@hidden>
- Date: Wed, 7 Jan 2009 07:32:54 -0500
- Thread-topic: Binary search on sorted NSArray in Cocoa?
Ken Thomases wrote on Tuesday, January 06, 2009 11:24 PM:
> 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.
Hmmm, it sounds like I'm going to be doing a LOT of automated fuzz
testing of my code then. Thanks for the help!
Thanks,
Cem Karan
_______________________________________________
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