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.
Свойства
Count
|
Return the number of elements in the Heap.
|
First
|
Return or set the first element of the Heap.
|
IsEmpty
|
Return whether the Heap is empty.
|
Методы
Insert
|
Insert an element into the Heap.
|
Remove
|
Remove and return the first element.
|
Update
|
Find all occurences of Old and replace them by New. It searches the
entire heap and is thus an O(n) operation per se.
|
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