OpenTTD AI API: AIPriorityQueue Class Reference

OpenTTD AI API 15.0-RC2

Public Member Functions
AIPriorityQueue Class Reference

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

`#include <script_priorityqueue.hpp>`

Inheritance diagram for AIPriorityQueue:

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

## Detailed Description

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

## Member Function Documentation

## ◆ Count()

int AIPriorityQueue::Count | ( |  | ) |

Returns the amount of items in the queue.

Returns
  amount of items in the queue.

## ◆ Exists()

bool AIPriorityQueue::Exists | ( | object | item | ) |

Check if an items is already included in the queue.

Parameters

  item | The 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 AIPriorityQueue::Insert | ( | object | item,
|  | int | priority
| ) |  |

Add a single item to the queue.

Parameters

  item | The item to add. Can be any Squirrel type. Should be unique, otherwise it is ignored.
  priority | The priority to assign the item.

Returns
  True if the item was inserted, false if it was already in the queue.

## ◆ IsEmpty()

bool AIPriorityQueue::IsEmpty | ( |  | ) |

Check if the queue is empty.

Returns
  true if the queue is empty.

## ◆ Peek()

object AIPriorityQueue::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()

object AIPriorityQueue::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()