dcsext.containers.PriorityQueue

PriorityQueue - min-heap priority queue.

Contents

  1. Description
  2. Metamethods
    1. priorityqueue:__call()
  3. Methods
    1. priorityqueue:size()
    2. priorityqueue:empty()
    3. priorityqueue:push(p, v)
    4. priorityqueue:pop()
    5. priorityqueue:peek()
    6. priorityqueue:remove(itemindex)
    7. priorityqueue:increase(itemindex, deltaprio)
    8. priorityqueue:decrease(itemindex, deltaprio)

Description

Values are stored together with a numeric priority and are popped in ascending priority order, so the value with the lowest priority is always returned first. Create a priority queue by calling the class directly, e.g. local pq = PriorityQueue().

Metamethods

priorityqueue:__call()

Constructor. Create a new, empty priority queue by calling the class directly, e.g. local pq = PriorityQueue().

Returns

  • a new, empty PriorityQueue instance

Methods

priorityqueue:size()

Return the number of values stored in the queue.

Returns

  • the number of stored values

priorityqueue:empty()

Test if the queue holds no values.

Returns

  • bool, true when the queue is empty

priorityqueue:push(p, v)

Insert a value into the queue with the given priority.

Parameters

p
priority used to order the value, lower priorities are popped first
v
value to store

priorityqueue:pop()

Remove and return the value with the lowest priority.

Returns

  • the stored value or nil when the queue is empty
  • the priority of the returned value

priorityqueue:peek()

Return the value with the lowest priority without removing it.

Returns

  • the stored value or nil when the queue is empty
  • the priority of the returned value

priorityqueue:remove(itemindex)

Remove an item from the queue by index. Not implemented yet, calling this method raises an assertion error.

Parameters

itemindex
index of the item to remove

priorityqueue:increase(itemindex, deltaprio)

Increase the priority of an item by a given amount. Not implemented yet, calling this method raises an assertion error.

Parameters

itemindex
index of the item to change
deltaprio
amount to add to the item priority

priorityqueue:decrease(itemindex, deltaprio)

Decrease the priority of an item by a given amount. Not implemented yet, calling this method raises an assertion error.

Parameters

itemindex
index of the item to change
deltaprio
amount to subtract from the item priority