Skip to content

Instantly share code, notes, and snippets.

@jorbsd
Created November 25, 2009 03:55
Show Gist options
  • Save jorbsd/242457 to your computer and use it in GitHub Desktop.
Save jorbsd/242457 to your computer and use it in GitHub Desktop.
// gcc -o heap3 heap3.m -framework Foundation && ./heap3
#import <Foundation/Foundation.h>
CFTypeRef JBBRetainCallBack(CFAllocatorRef allocator, const void *obj) {
return [(id)obj retain];
}
void JBBReleaseCallBack(CFAllocatorRef allocator, const void *obj) {
[(id)obj release];
}
CFComparisonResult JBBCompareCallBack(const void *lhs, const void *rhs, void *info) {
return [(id)lhs compare:(id)rhs];
}
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
CFBinaryHeapCallBacks ourCallbacks = {
.version = 0,
.copyDescription = CFCopyDescription,
.retain = JBBRetainCallBack,
.release = JBBReleaseCallBack,
.compare = JBBCompareCallBack,
};
CFBinaryHeapRef heap = CFBinaryHeapCreate(NULL, 0, &ourCallbacks, NULL);
CFBinaryHeapAddValue(heap, CFSTR("Jane"));
CFBinaryHeapAddValue(heap, @"Joe");
id minValue = [(id)CFBinaryHeapGetMinimum(heap) retain];
NSLog(@"minValue = %@", minValue);
[minValue release];
CFShow(heap);
CFRelease(heap);
[pool drain];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment