No description
Find a file
2021-06-09 11:23:23 +02:00
.github/workflows switch to github action 2021-06-09 11:22:06 +02:00
.gitignore Add gitignore 2015-06-06 10:34:08 -07:00
binaryheap.nim Updated for latest nim 2018-08-06 14:37:51 +02:00
binaryheap.nimble Updated for latest nim 2018-08-06 14:37:51 +02:00
LICENSE Initial commit 2015-05-19 17:00:12 +02:00
Makefile Add Makefile 2015-06-06 10:35:35 -07:00
readme.md switch to github action 2021-06-09 11:22:06 +02:00

Nim-Heap Build Status

This is a simple binary heap implementation, using a dynamic array (seq) as backend. Apart from the standard functionality peek/push/pop it also provides optimized versions for performing push+pop or pop+push, which can be handy for fixed-sized priority queues. The code should be self-explanatory.

A Partial Tour

Below is an example of how to use this module. It contains a few of the procs available, but not all. Check out the source for the full set of functionality.

import binaryheap

# Create a heap of ints
var heap = newHeap[int]() do (a, b: int) -> int:
    return a - b

# Push a bunch of values
heap.push(30)
heap.push(4)
heap.push(15)
heap.push(1)

# Prints "1" because our comparison function keeps the smallest value on top.
# This also removes the value from the heap
echo heap.pop

# Prints "4" and leaves the value on the heap
echo heap.peek

# Print all values in the heap in unsorted order
for item in heap:
    echo item