Heap
Generic binary heap
heap := Collection.Heap->New(Collection.Heap->Order->MIN)<IntRef>;
heap->Insert(IntRef->New(3));
heap->Insert(IntRef->New(1));
heap->Insert(IntRef->New(9));
heap->Insert(IntRef->New(8));
heap->Insert(IntRef->New(6));
heap->Insert(IntRef->New(2));
while(<>heap->IsEmpty()) {
heap->Pop()->PrintLine();
};
Operations
Capacity
Returns the heap capacity
method : public : Capacity() ~ Int
Return
Type | Description |
---|---|
Int | heap capacity |
Insert
Inserts a value into the heap and extends the heap size if necessary
method : public : Insert(value:H) ~ Nil
Parameters
Name | Type | Description |
---|---|---|
value | H | value to insert |
IsEmpty
Checks to see if the heap is empty
method : public : IsEmpty() ~ Bool
Return
Type | Description |
---|---|
Bool | true if empty, false otherwise |
New
Constructor
New(array:H[], order:Heap->Order)
Parameters
Name | Type | Description |
---|---|---|
array | H[] | array of values to insert |
order | Heap->Order | sort order |
Pop
Pop either the smallest or largest value depending upon the sort order
method : public : Pop() ~ H
Return
Type | Description |
---|---|
H | smallest or largest value |
Pop
Searches and pops the given value
method : public : Pop(value:H) ~ Bool
Parameters
Name | Type | Description |
---|---|---|
value | H | value to remove |
Return
Type | Description |
---|---|
Bool | true if successful, false otherwise |
Size
Size of heap, including Nil values
method : public : Size() ~ Int
Return
Type | Description |
---|---|
Int | size of heap |
ToArray
Returns a list of non-Nil values
method : public : ToArray() ~ H[]
Return
Type | Description |
---|---|
H[] | list of values |
ToString
Formats the collection into a string. If an element implements the 'Stringify' interface, it's 'ToString()' is called.
method : public : ToString() ~ String
Return
Type | Description |
---|---|
String | string representation |