Gambas Documentation - /comp/gb.data/heap

/comp/gb.data/heap

# Heap (gb.data)

This class implements a dynamic heap data structure. It can be a MinHeap or a MaxHeap, depending on what mode you specify on construction.

Being "dynamic" means that this class allows you to update the data or the position of elements which are already in the heap.

This class is
Creates a new Heap.
creatable
.

Properties | Methods
--- | ---
Return the number of elements in the Heap. Count Return or set the first element of the Heap. First Return whether the Heap is empty. IsEmpty | Insert an element into the Heap. Insert Remove and return the first element. Remove Find all occurences of Old and replace them by New. It searches the entire heap and is thus an O(n) operation per se. Update

Objects in the Heap are all Variants. The ordering in the heap is implicitly defined via comparison of these values. You can put primitive values in there (Boolean, Integer, String, etc.) and also objects. The special _compare() method is used to compare objects.

Note that you cannot compare objects to primitives or to objects of different classes in Gambas (at the time of this writing). If you don't keep your heap homogeneous in the just defined sense, it will throw an error while trying to order itself.

### See also

Wikipedia on heaps