heap.rb

lib/containers/heap.rb
Last Update: Sun Mar 29 08:31:46 -0400 2009

A Heap is a container that satisfies the heap property that nodes are always smaller in value than their parent node.

The Containers::Heap class is flexible and upon initialization, takes an optional block that determines how the items are ordered. Two versions that are included are the Containers::MaxHeap and Containers::MinHeap that return the largest and smallest items on each invocation, respectively.

This library implements a Fibonacci heap, which allows O(1) complexity for most methods.