turtleeeeee / MCBinaryHeap

An Objective-C wrapper of CFBinaryHeap. Core Foundation priority queue implementation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MCBinaryHeap License MIT

Badge w/ Version Badge w/ Platform

An Objective-C wrapper of CFBinaryHeap. Core Foundation priority queue implementation.

Installation

Add the following to your CocoaPods Podfile

pod 'MCBinaryHeap', '~> 0.1'

or clone as a git submodule,

or just copy files in the MCBinaryHeap folder into your project.

Using MCBinaryHeap

Objects you add to MCBinaryHeap must implement - (NSComparisonResult)compare:(id)otherObject;.

The usage is very similar to NSMutableArray.

MCBinaryHeap *heap = [MCBinaryHeap heapWithArray:@[@3, @4, @5, @2]];
[heap addObject:@(1)];
NSLog(@"heap count %lu", heap.count);

[heap enumerateObjectsUsingBlock: ^(id object) {
    NSLog(@"heap item %@", object);
}];

NSLog(@"min object %@", [heap popMinimumObject]);

See the demo project for more details.

License

MCBinaryHeap is under the MIT license.

About

An Objective-C wrapper of CFBinaryHeap. Core Foundation priority queue implementation.

License:MIT License


Languages

Language:Objective-C 88.6%Language:Ruby 11.4%