March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
|
|
@ -3,33 +3,32 @@
|
|||
typedef NSArray *(^SOfN)(id);
|
||||
|
||||
SOfN s_of_n_creator(int n) {
|
||||
NSMutableArray *sample = [NSMutableArray arrayWithCapacity:n];
|
||||
NSMutableArray *sample = [[NSMutableArray alloc] initWithCapacity:n];
|
||||
__block int i = 0;
|
||||
return [[^(id item) {
|
||||
return [^(id item) {
|
||||
i++;
|
||||
if (i <= n) {
|
||||
[sample addObject:item];
|
||||
} else if (rand() % i < n) {
|
||||
[sample replaceObjectAtIndex:rand() % n withObject:item];
|
||||
sample[rand() % n] = item;
|
||||
}
|
||||
return sample;
|
||||
} copy] autorelease];
|
||||
} copy];
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
|
||||
NSCountedSet *bin = [[NSCountedSet alloc] init];
|
||||
for (int trial = 0; trial < 100000; trial++) {
|
||||
SOfN s_of_n = s_of_n_creator(3);
|
||||
NSArray *sample;
|
||||
for (int i = 0; i < 10; i++)
|
||||
sample = s_of_n(@(i));
|
||||
[bin addObjectsFromArray:sample];
|
||||
}
|
||||
NSLog(@"%@", bin);
|
||||
|
||||
NSCountedSet *bin = [[NSCountedSet alloc] init];
|
||||
for (int trial = 0; trial < 100000; trial++) {
|
||||
SOfN s_of_n = s_of_n_creator(3);
|
||||
NSArray *sample;
|
||||
for (int i = 0; i < 10; i++)
|
||||
sample = s_of_n([NSNumber numberWithInt:i]);
|
||||
[bin addObjectsFromArray:sample];
|
||||
}
|
||||
NSLog(@"%@", bin);
|
||||
[bin release];
|
||||
|
||||
[pool release];
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue