Heap queue algorithm (a.k.a. priority queue). Ported from Python heapq.
Heaps are arrays for which a[k] <= a[2*k+1] and a[k] <= a[2*k+2] for all k, counting elements from 0. For the sake of comparison, non-existing elements are considered to be infinite. The interesting property of a heap is that a[0] is always its smallest element.
HeapQueue[T] = distinct seq[T]
proc newHeapQueue[T](): HeapQueue[T] {...}{.inline.}
proc newHeapQueue[T](h: var HeapQueue[T]) {...}{.inline.}
proc len[T](h: HeapQueue[T]): int {...}{.inline.}
proc `[]`[T](h: HeapQueue[T]; i: int): T {...}{.inline.}
proc push[T](heap: var HeapQueue[T]; item: T)
proc pop[T](heap: var HeapQueue[T]): T
proc del[T](heap: var HeapQueue[T]; index: int)
proc replace[T](heap: var HeapQueue[T]; item: T): T
proc pushpop[T](heap: var HeapQueue[T]; item: T): T
© 2006–2018 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/heapqueue.html