Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bluenote10/nim-heap
Simple binary heap implementation in Nim
https://github.com/bluenote10/nim-heap
Last synced: 1 day ago
JSON representation
Simple binary heap implementation in Nim
- Host: GitHub
- URL: https://github.com/bluenote10/nim-heap
- Owner: bluenote10
- License: mit
- Created: 2015-05-19T15:00:12.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-06-09T09:23:23.000Z (over 3 years ago)
- Last Synced: 2024-08-04T03:06:08.033Z (3 months ago)
- Language: Nim
- Size: 12.7 KB
- Stars: 20
- Watchers: 4
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-nim - binaryheap - Simple binary heap implementation in Nim. (Data / Data Structures)
README
Nim-Heap [![Build Status](https://github.com/bluenote10/nim-heap/workflows/ci/badge.svg)](https://github.com/bluenote10/nim-heap/actions?query=workflow%3Aci)
========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.```nimrod
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
```