Priority Queue
PriorityItem(x, priority)
dataclass
Dataclass representing an item inside the priority queue. An item is a pair element/priority.
PriorityQueue()
Implementation of a priority queue using a heap from the heapq package.
Attributes:
Name | Type | Description |
---|---|---|
data |
list
|
the list representing the queue |
Initializes an empty queue.
front: PriorityItem
property
The first element of the queue. Is accessed but not removed from the queue
Returns:
Name | Type | Description |
---|---|---|
PriorityItem |
PriorityItem
|
The first element of the queue |
empty()
Tests if the queue contains any element.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the queue is empty |
get()
Returns the first element of the queue. The element is removed from the queue.
Returns:
Name | Type | Description |
---|---|---|
PriorityItem |
PriorityItem
|
The first element of the queue |
Raises:
Type | Description |
---|---|
IndexError
|
if the queue is empty |
pop()
Returns the first element of the queue. Same method as get
.
Returns:
Name | Type | Description |
---|---|---|
PriorityItem |
PriorityItem
|
The first element of the queue |
Raises:
Type | Description |
---|---|
IndexError
|
if the queue is empty |
push(x, w)
Inserts an element inside the queue.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Element to insert in the queue |
required | |
w |
float
|
Priority of the element. |
required |