Created
January 26, 2010 20:49
-
-
Save jorbsd/287212 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- test2.m 2010-01-26 14:44:47.000000000 -0600 | |
+++ test3.m 2010-01-25 20:18:22.000000000 -0600 | |
@@ -1,4 +1,4 @@ | |
-// /Developer/usr/bin/clang -arch x86_64 -std=gnu99 -fobjc-gc-only -o test2 -F. -Wl,-rpath,. test2.m -framework Foundation -framework JBBPriorityQueue -framework JBBAdditions | |
+// /Developer/usr/bin/clang -arch x86_64 -std=gnu99 -fobjc-gc-only -o test3 -F. -Wl,-rpath,. test3.m -framework Foundation -framework JBBPriorityQueue -framework JBBAdditions | |
#import <objc/objc-auto.h> | |
#import <dispatch/dispatch.h> | |
@@ -16,7 +16,6 @@ | |
- (id)initWithPriority:(NSUInteger)priority; | |
- (NSArray *)children; | |
-- (NSComparisonResult)compare:(id <JBBNodeProtocol>)rhs; | |
@end | |
@implementation JBBNode | |
@@ -68,23 +67,21 @@ | |
return [newArray copy]; | |
} | |
- | |
-- (NSComparisonResult)compare:(id <JBBNodeProtocol>)rhs { | |
- if (self.priority < rhs.priority) { | |
- return NSOrderedAscending; | |
- } else if (self.priority > rhs.priority) { | |
- return NSOrderedDescending; | |
- } else { | |
- return NSOrderedSame; | |
- } | |
-} | |
@end | |
int main(int argc, char *argv[]) { | |
objc_startCollectorThread(); | |
NSAutoreleasePool *mainPool = [[NSAutoreleasePool alloc] init]; | |
- JBBPriorityQueue *localQueue = [[JBBPriorityQueue alloc] initWithClass:[JBBNode class] ordering:NSOrderedAscending]; | |
+ JBBPriorityQueue *localQueue = [[JBBPriorityQueue alloc] initWithBlock:^(id <JBBNodeProtocol> lhs, id <JBBNodeProtocol> rhs) { | |
+ if (lhs.priority < rhs.priority) { | |
+ return NSOrderedAscending; | |
+ } else if (lhs.priority > rhs.priority) { | |
+ return NSOrderedDescending; | |
+ } else { | |
+ return NSOrderedSame; | |
+ } | |
+ }]; | |
[localQueue push:[[JBBNode alloc] init]]; | |
JBBNode *localNode = nil; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// /Developer/usr/bin/clang -arch x86_64 -std=gnu99 -fobjc-gc-only -o test2 -F. -Wl,-rpath,. test2.m -framework Foundation -framework JBBPriorityQueue -framework JBBAdditions | |
#import <objc/objc-auto.h> | |
#import <dispatch/dispatch.h> | |
#import <Foundation/Foundation.h> | |
#import <JBBAdditions/JBBAdditions.h> | |
#import <JBBPriorityQueue/JBBPriorityQueue.h> | |
@protocol JBBNodeProtocol | |
@property NSUInteger priority; | |
@end | |
@interface JBBNode : NSObject <JBBNodeProtocol> | |
+ (NSUInteger)instanceCount; | |
- (id)initWithPriority:(NSUInteger)priority; | |
- (NSArray *)children; | |
- (NSComparisonResult)compare:(id <JBBNodeProtocol>)rhs; | |
@end | |
@implementation JBBNode | |
static dispatch_once_t JBBNode_pred; | |
static dispatch_semaphore_t instanceCountSemaphore; | |
static NSUInteger instanceCount; | |
@synthesize priority; | |
+ (void)initialize { | |
dispatch_once(&JBBNode_pred, ^{ | |
instanceCountSemaphore = dispatch_semaphore_create(1); | |
instanceCount = 0; | |
}); | |
} | |
+ (NSUInteger)instanceCount { | |
return instanceCount; | |
} | |
- (id)init { | |
return [self initWithPriority:0]; | |
} | |
- (id)initWithPriority:(NSUInteger)inPriority { | |
self = [super init]; | |
if (self) { | |
dispatch_semaphore_wait(instanceCountSemaphore, DISPATCH_TIME_FOREVER); | |
instanceCount += 1; | |
dispatch_semaphore_signal(instanceCountSemaphore); | |
self.priority = inPriority + 1; | |
} | |
return self; | |
} | |
- (NSString *)description { | |
return [NSString stringWithFormat:@"JBBNode(%llu)", self.priority]; | |
} | |
- (NSArray *)children { | |
NSMutableArray *newArray = [NSMutableArray array]; | |
for (uint32_t times = 0; times < self.priority + 1; times += 1) { | |
[newArray addObject:[[JBBNode alloc] initWithPriority:self.priority]]; | |
} | |
return [newArray copy]; | |
} | |
- (NSComparisonResult)compare:(id <JBBNodeProtocol>)rhs { | |
if (self.priority < rhs.priority) { | |
return NSOrderedAscending; | |
} else if (self.priority > rhs.priority) { | |
return NSOrderedDescending; | |
} else { | |
return NSOrderedSame; | |
} | |
} | |
@end | |
int main(int argc, char *argv[]) { | |
objc_startCollectorThread(); | |
NSAutoreleasePool *mainPool = [[NSAutoreleasePool alloc] init]; | |
JBBPriorityQueue *localQueue = [[JBBPriorityQueue alloc] initWithClass:[JBBNode class] ordering:NSOrderedAscending]; | |
[localQueue push:[[JBBNode alloc] init]]; | |
JBBNode *localNode = nil; | |
while ((localNode = [localQueue pop]) && ([JBBNode instanceCount] <= 1500)) { | |
[localNode jbb_puts]; | |
[localQueue pushObjects:[localNode children]]; | |
} | |
[mainPool drain]; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// /Developer/usr/bin/clang -arch x86_64 -std=gnu99 -fobjc-gc-only -o test3 -F. -Wl,-rpath,. test3.m -framework Foundation -framework JBBPriorityQueue -framework JBBAdditions | |
#import <objc/objc-auto.h> | |
#import <dispatch/dispatch.h> | |
#import <Foundation/Foundation.h> | |
#import <JBBAdditions/JBBAdditions.h> | |
#import <JBBPriorityQueue/JBBPriorityQueue.h> | |
@protocol JBBNodeProtocol | |
@property NSUInteger priority; | |
@end | |
@interface JBBNode : NSObject <JBBNodeProtocol> | |
+ (NSUInteger)instanceCount; | |
- (id)initWithPriority:(NSUInteger)priority; | |
- (NSArray *)children; | |
@end | |
@implementation JBBNode | |
static dispatch_once_t JBBNode_pred; | |
static dispatch_semaphore_t instanceCountSemaphore; | |
static NSUInteger instanceCount; | |
@synthesize priority; | |
+ (void)initialize { | |
dispatch_once(&JBBNode_pred, ^{ | |
instanceCountSemaphore = dispatch_semaphore_create(1); | |
instanceCount = 0; | |
}); | |
} | |
+ (NSUInteger)instanceCount { | |
return instanceCount; | |
} | |
- (id)init { | |
return [self initWithPriority:0]; | |
} | |
- (id)initWithPriority:(NSUInteger)inPriority { | |
self = [super init]; | |
if (self) { | |
dispatch_semaphore_wait(instanceCountSemaphore, DISPATCH_TIME_FOREVER); | |
instanceCount += 1; | |
dispatch_semaphore_signal(instanceCountSemaphore); | |
self.priority = inPriority + 1; | |
} | |
return self; | |
} | |
- (NSString *)description { | |
return [NSString stringWithFormat:@"JBBNode(%llu)", self.priority]; | |
} | |
- (NSArray *)children { | |
NSMutableArray *newArray = [NSMutableArray array]; | |
for (uint32_t times = 0; times < self.priority + 1; times += 1) { | |
[newArray addObject:[[JBBNode alloc] initWithPriority:self.priority]]; | |
} | |
return [newArray copy]; | |
} | |
@end | |
int main(int argc, char *argv[]) { | |
objc_startCollectorThread(); | |
NSAutoreleasePool *mainPool = [[NSAutoreleasePool alloc] init]; | |
JBBPriorityQueue *localQueue = [[JBBPriorityQueue alloc] initWithBlock:^(id <JBBNodeProtocol> lhs, id <JBBNodeProtocol> rhs) { | |
if (lhs.priority < rhs.priority) { | |
return NSOrderedAscending; | |
} else if (lhs.priority > rhs.priority) { | |
return NSOrderedDescending; | |
} else { | |
return NSOrderedSame; | |
} | |
}]; | |
[localQueue push:[[JBBNode alloc] init]]; | |
JBBNode *localNode = nil; | |
while ((localNode = [localQueue pop]) && ([JBBNode instanceCount] <= 1500)) { | |
[localNode jbb_puts]; | |
[localQueue pushObjects:[localNode children]]; | |
} | |
[mainPool drain]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment