Created
November 25, 2009 03:54
-
-
Save jorbsd/242456 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
// gcc -o heap2 heap2.m -framework Foundation && ./heap2 | |
#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 = nil; | |
BOOL hasMin = CFBinaryHeapGetMinimumIfPresent(heap, (const void **)&minValue); | |
[minValue retain]; | |
NSLog(@"hasMin = %i, minValue = %@", hasMin, 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