OperatorUtilizationHeap
The OperatorUtilizationHeap
library provides functionality for managing an in-memory heap data structure that organizes operators based on their utilization. The heap allows for efficient insertion, removal, and update of operator utilizations, as well as retrieval of the operators with the minimum or maximum utilizations. https://people.scs.carleton.ca/~santoro/Reports/MinMaxHeap.pdf
State Variables
ROOT_INDEX
The root index of the heap.
Functions
initialize
Initializes the heap.
Parameters
Name | Type | Description |
---|---|---|
|
| The maximum number of operators that can be stored in the heap. |
isEmpty
Returns whether the heap is empty.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
isFull
Returns whether the heap is full.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
store
Inserts the heap into storage.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The stored heap. |
|
| The maximum number of operators that can currently be stored in the heap. |
insert
Inserts an operator into the heap.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The operator to insert. |
remove
Removes an operator from the heap.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The index of the operator to remove. |
removeByID
Removes an operator from the heap by its ID.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The ID of the operator to remove. |
updateUtilization
Updates the utilization of an operator in the heap.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The index of the operator to update. |
|
| The new utilization of the operator. |
updateUtilizationByID
Updates the utilization of an operator in the heap by its ID.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The ID of the operator to update. |
|
| The new utilization of the operator. |
extractMin
Extracts the minimum operator from the heap.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
extractMax
Extracts the maximum operator from the heap.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
getMin
Returns the minimum operator from the heap.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
getMax
Returns the maximum operator from the heap.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
getMaxIndex
Returns the index of the maximum operator from the heap.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
_bubbleDown
Adjusts the position of an operator downwards in the heap to ensure the heap's properties are maintained.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The index of the operator to bubble down. |
_bubbleDownMin
Adjusts the position of an operator downwards in the heap to ensure the heap's properties are maintained. The operator is assumed to be on a min level.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The index of the operator to bubble down. |
_bubbleDownMax
Adjusts the position of an operator downwards in the heap to ensure the heap's properties are maintained. The operator is assumed to be on a max level.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The index of the operator to bubble down. |
_bubbleUp
Adjusts the position of an operator upwards in the heap to ensure the heap's properties are maintained.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The index of the operator to bubble up. |
_bubbleUpMin
Adjusts the position of an operator upwards in the heap to ensure the heap's properties are maintained. The operator is assumed to be on a min level.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The index of the operator to bubble up. |
_bubbleUpMax
Adjusts the position of an operator upwards in the heap to ensure the heap's properties are maintained. The operator is assumed to be on a max level.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The index of the operator to bubble up. |
_hasGrandparent
Returns whether the node at the specified index has a grandparent.
Parameters
Name | Type | Description |
---|---|---|
|
| The index of the node in the heap. |
_hasParent
Returns whether the node at the specified index has a parent.
Parameters
Name | Type | Description |
---|---|---|
|
| The index of the node in the heap. |
_hasChildren
Returns whether the node at the specified index has children.
Parameters
Name | Type | Description |
---|---|---|
|
| |
|
| The index of the node in the heap. |
_isGrandchild
Returns whether the node at m
is a grandchild of the node at i
.
Parameters
Name | Type | Description |
---|---|---|
|
| The index of the node in the heap. |
|
| The index of the child or grandchild of the node at index |
_findOperatorIndex
Finds the index of the operator with the specified ID in the heap.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The ID of the operator to find. |
_swap
Swaps the operators at the specified indices in the heap.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The index of the first operator to swap. |
|
| The index of the second operator to swap. |
_push
Pushes an operator onto the end of the heap.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The operator to push. |
_remove
Removes the operator at the specified index from the heap by swapping it with the last operator in the heap.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The index of the operator to extract. |
_getSmallestChildIndexOrGrandchild
Returns the index of the smallest child or grandchild of the node at index i
.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The index of the node whose children and grandchildren are to be compared. |
_getLargestChildIndexOrGrandchild
Returns the index of the largest child or grandchild of the node at index i
.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The index of the node whose children and grandchildren are to be compared. |
_getExtremeChildIndexOrGrandchild
Returns the index of the extreme child or grandchild of the node at index i
.
Parameters
Name | Type | Description |
---|---|---|
|
| The heap. |
|
| The index of the node whose children and grandchildren are to be compared. |
|
| The comparison function to use. |
_isSmaller
Comparison function to determine if the first value is smaller than the second.
Parameters
Name | Type | Description |
---|---|---|
|
| The first value. |
|
| The second value. |
Returns
Name | Type | Description |
---|---|---|
|
| bool True if |
_isLarger
Comparison function to determine if the first value is larger than the second.
Parameters
Name | Type | Description |
---|---|---|
|
| The first value. |
|
| The second value. |
Returns
Name | Type | Description |
---|---|---|
|
| bool True if |
_isOnMinLevel
Returns whether the node at the specified index is on a min level.
Parameters
Name | Type | Description |
---|---|---|
|
| The index of the node in the heap. |
_getLevel
Determines the level of a node in a binary heap.
Parameters
Name | Type | Description |
---|---|---|
|
| The index of the node in the heap. |
Errors
OPERATOR_NOT_FOUND
Thrown when an operator is not found in the heap.
INVALID_HEAP_SIZE
Thrown when attempting to initialize a heap with a size of 0.
INVALID_INDEX
Thrown when attempting an operation on an invalid operator index.
HEAP_OVERFLOW
Thrown when attempting to insert an operator into a full heap.
HEAP_UNDERFLOW
Thrown when attempting to fetch an operator from an empty heap.
Structs
Operator
The data structure representing an operator and its utilization.
Data
The data structure representing the heap.
Last updated