macOS ubuntu docs

Heap

A maintained swift heap package that provides min and max heaps in both iterative and recursive variants.

Getting Started

You can easily add as a requirement with SwiftPM.

Know what you’re doing?

Here are some quick copypastas for you

.package(url: "https://github.com/swiftpackages/Heap.git", from: "1.1.1"),
.product(name: "Heap", package: "Heap"),

Need a reminder?

Your Package.swift file should look something like this

// swift-tools-version:5.3

import PackageDescription

let package = Package(
    name: "SuperCoolProject",
    products: [
        .library(
            name: "SuperCoolProject",
            targets: ["SuperCoolProject"]),
    ],
    dependencies: [
        .package(url: "https://github.com/swiftpackages/Heap.git", from: "1.1.1"),
    ],
    targets: [
        .target(
            name: "SuperCoolProject",
            dependencies: [
                .product(name: "Heap", package: "Heap"),
            ]),
        .testTarget(
            name: "SuperCoolProject",
            dependencies: ["SuperCoolProject"])
    ]
)

Usage

The datatype must conform to Comparable.

// initialize MinHeap<Int>
var minHeap = MinHeap<Int>()

// initialize MaxHeap<Int>
var maxHeap = MaxHeap<Int>()

// initialize MinHeapRecursive<Int>
var minHeap = MinHeapRecursive<Int>()

// initialize MaxHeapRecursive<Int>
var maxHeap = MaxHeapRecursive<Int>()

// get root node value without removing it
heap.peak()

// get root node value and remove it
heap.pull()

Additional Documentation

You can find the full documentation on the documentation website.