OpenTTD GameScript API  20240420-master-g08140fdca3
Public Member Functions
GSPriorityQueue Class Reference

Class that creates a queue which keeps its items ordered by an item priority. More...

Inheritance diagram for GSPriorityQueue:

Public Member Functions

bool Insert (void *item, SQInteger priority)
 Add a single item to the queue. More...
 
void * Pop ()
 Remove and return the item with the lowest priority. More...
 
void * Peek ()
 Get the item with the lowest priority, keeping it in the queue. More...
 
bool Exists (void *item)
 Check if an items is already included in the queue. More...
 
void Clear ()
 Clear the queue, making Count() returning 0 and IsEmpty() returning true.
 
bool IsEmpty ()
 Check if the queue is empty. More...
 
SQInteger Count ()
 Returns the amount of items in the queue. More...
 

Detailed Description

Class that creates a queue which keeps its items ordered by an item priority.

Member Function Documentation

◆ Count()

SQInteger GSPriorityQueue::Count ( )

Returns the amount of items in the queue.

Returns
amount of items in the queue.

◆ Exists()

bool GSPriorityQueue::Exists ( void *  item)

Check if an items is already included in the queue.

Parameters
itemThe item to check whether it's already in this queue.
Returns
true if the items is already in the queue.
Note
Performance is O(n), use only when absolutely required.

◆ Insert()

bool GSPriorityQueue::Insert ( void *  item,
SQInteger  priority 
)

Add a single item to the queue.

Parameters
itemThe item to add. Can be any Squirrel type. Should be unique, otherwise it is ignored.
priorityThe priority to assign the item.
Returns
True if the item was inserted, false if it was already in the queue.

◆ IsEmpty()

bool GSPriorityQueue::IsEmpty ( )

Check if the queue is empty.

Returns
true if the queue is empty.

◆ Peek()

void* GSPriorityQueue::Peek ( )

Get the item with the lowest priority, keeping it in the queue.

Returns
The item with the lowest priority. Returns null on an empty queue.
Precondition
!IsEmpty()

◆ Pop()

void* GSPriorityQueue::Pop ( )

Remove and return the item with the lowest priority.

Returns
The item with the lowest priority, removed from the queue. Returns null on an empty queue.
Precondition
!IsEmpty()