March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
|
|
@ -13,7 +13,7 @@
|
|||
NSInteger hi = [self count] - 1;
|
||||
while (lo <= hi) {
|
||||
NSInteger mid = lo + (hi - lo) / 2;
|
||||
id midVal = [self objectAtIndex:mid];
|
||||
id midVal = self[mid];
|
||||
switch ([midVal compare:key]) {
|
||||
case NSOrderedAscending:
|
||||
lo = mid + 1;
|
||||
|
|
@ -31,21 +31,11 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
|
||||
NSArray *a = [NSArray arrayWithObjects:
|
||||
[NSNumber numberWithInt: 1],
|
||||
[NSNumber numberWithInt: 3],
|
||||
[NSNumber numberWithInt: 4],
|
||||
[NSNumber numberWithInt: 5],
|
||||
[NSNumber numberWithInt: 6],
|
||||
[NSNumber numberWithInt: 7],
|
||||
[NSNumber numberWithInt: 8],
|
||||
[NSNumber numberWithInt: 9],
|
||||
[NSNumber numberWithInt: 10],
|
||||
nil];
|
||||
NSLog(@"6 is at position %d", [a binarySearch:[NSNumber numberWithInt: 6]]); // prints 4
|
||||
NSArray *a = @[@1, @3, @4, @5, @6, @7, @8, @9, @10];
|
||||
NSLog(@"6 is at position %d", [a binarySearch:@6]); // prints 4
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
if (range.length == 0)
|
||||
return NSNotFound;
|
||||
NSInteger mid = range.location + range.length / 2;
|
||||
id midVal = [self objectAtIndex:mid];
|
||||
id midVal = self[mid];
|
||||
switch ([midVal compare:key]) {
|
||||
case NSOrderedAscending:
|
||||
return [self binarySearch:key
|
||||
|
|
@ -28,22 +28,11 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
|
||||
NSArray *a = [NSArray arrayWithObjects:
|
||||
[NSNumber numberWithInt: 1],
|
||||
[NSNumber numberWithInt: 3],
|
||||
[NSNumber numberWithInt: 4],
|
||||
[NSNumber numberWithInt: 5],
|
||||
[NSNumber numberWithInt: 6],
|
||||
[NSNumber numberWithInt: 7],
|
||||
[NSNumber numberWithInt: 8],
|
||||
[NSNumber numberWithInt: 9],
|
||||
[NSNumber numberWithInt: 10],
|
||||
nil];
|
||||
NSLog(@"6 is at position %d", [a binarySearch:[NSNumber numberWithInt: 6]
|
||||
inRange:NSMakeRange(0, [a count])]); // prints 4
|
||||
NSArray *a = @[@1, @3, @4, @5, @6, @7, @8, @9, @10];
|
||||
NSLog(@"6 is at position %d", [a binarySearch:@6]); // prints 4
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,24 +2,14 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
|
||||
NSArray *a = [NSArray arrayWithObjects:
|
||||
[NSNumber numberWithInt: 1],
|
||||
[NSNumber numberWithInt: 3],
|
||||
[NSNumber numberWithInt: 4],
|
||||
[NSNumber numberWithInt: 5],
|
||||
[NSNumber numberWithInt: 6],
|
||||
[NSNumber numberWithInt: 7],
|
||||
[NSNumber numberWithInt: 8],
|
||||
[NSNumber numberWithInt: 9],
|
||||
[NSNumber numberWithInt: 10],
|
||||
nil];
|
||||
NSLog(@"6 is at position %lu", [a indexOfObject:[NSNumber numberWithInt: 6]
|
||||
inSortedRange:NSMakeRange(0, [a count])
|
||||
options:0
|
||||
usingComparator:^(id x, id y){ return [x compare: y]; }]); // prints 4
|
||||
NSArray *a = @[@1, @3, @4, @5, @6, @7, @8, @9, @10];
|
||||
NSLog(@"6 is at position %lu", [a indexOfObject:@6
|
||||
inSortedRange:NSMakeRange(0, [a count])
|
||||
options:0
|
||||
usingComparator:^(id x, id y){ return [x compare: y]; }]); // prints 4
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +1,19 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
CFComparisonResult myComparator(const void *x, const void *y, void *context) {
|
||||
return [(id)x compare:(id)y];
|
||||
return [(__bridge id)x compare:(__bridge id)y];
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
int main(int argc, const char *argv[]) {
|
||||
@autoreleasepool {
|
||||
|
||||
NSArray *a = [NSArray arrayWithObjects:
|
||||
[NSNumber numberWithInt: 1],
|
||||
[NSNumber numberWithInt: 3],
|
||||
[NSNumber numberWithInt: 4],
|
||||
[NSNumber numberWithInt: 5],
|
||||
[NSNumber numberWithInt: 6],
|
||||
[NSNumber numberWithInt: 7],
|
||||
[NSNumber numberWithInt: 8],
|
||||
[NSNumber numberWithInt: 9],
|
||||
[NSNumber numberWithInt: 10],
|
||||
nil];
|
||||
NSLog(@"6 is at position %d", CFArrayBSearchValues((CFArrayRef)a,
|
||||
CFRangeMake(0, [a count]),
|
||||
[NSNumber numberWithInt: 6],
|
||||
myComparator,
|
||||
NULL)); // prints 4
|
||||
NSArray *a = @[@1, @3, @4, @5, @6, @7, @8, @9, @10];
|
||||
NSLog(@"6 is at position %ld", CFArrayBSearchValues((__bridge CFArrayRef)a,
|
||||
CFRangeMake(0, [a count]),
|
||||
(__bridge const void *)@6,
|
||||
myComparator,
|
||||
NULL)); // prints 4
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue