Class Queue

An ordered, linear, first-in-first-out Collection of items.

Queues have a distinct, linear ordering of their elements and can be added to at the back and removed from in the front. The combination of these ensures that the first elements added are the first ones out of the Queue.

The Queue interface provides a base set of operations for interacting with any abstract Queue type. Abstract data types may provide addtional specific operations based on the particular implemented type. Concrete implementations, such as LinkedQueues, ultimately determine the properties of the concrete Queue such as time and space complexity for any operations.

The Queue interface provides certain optional methods in addition to those in Collection. Some Queues, such as immutable or type-restricted data types, may not be able to provide full functionality for these methods. All Queues are guaranteed to provide a required set of behaviors without exception and, unless otherwise noted, a method is required. All Queues should attempt to provide optional functionality, if they're able, regardless.

Implements: Collection, Enumerable

Functions

Queue.new() Creates a new Queue interface instance.

Methods

Queue:Add(item) Adds an item to the Queue.
Queue:AddAll(items) Adds all provided items to the Queue.
Queue:Clear() Removes everything from the Queue.
Queue:Contains(item) Determines whether the Queue contains an item.
Queue:ContainsAll(items) Determines whether the Queue contains all of the provided items.
Queue:ContainsAny(items) Determines whether the Queue contains any of the provided items.
Queue:Count() Gets the number of items in the Queue.
Queue:Empty() Determines whether the Queue contains no elements.
Queue:Enumerator() Creates an enumerator for the Queue.
Queue:First() Gets the item at the beginning of the Queue.
Queue:Push(item) Adds an item to the end of the Queue.
Queue:Remove(item) Removes the specified item from the Queue.
Queue:RemoveAll(items) Removes all provided items from the Queue.
Queue:RetainAll(items) Removes all items except those provided from the Queue.
Queue:Shift() Gets an item from the beginning and removes that item from the Queue.
Queue:ToArray() Creates a new array-indexed table of this Queue.
Queue:ToTable() Creates a new table of this Queue.


Functions

Methods
Queue.new()
Creates a new Queue interface instance. This should only be used when implementing a new Queue.

Access:

    private

Returns:

    the new Queue interface

Methods

Queue:Add(item)
Adds an item to the Queue.

This method is optional. All Queue implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.

This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this Queue.

Inherited from:

Parameters:

  • item the item to add

Returns:

    true if the Queue changed as a result, false otherwise
Queue:AddAll(items)
Adds all provided items to the Queue. Adds items provided in another Collection in an arbitrary, deterministic order. The order is the same as the order of enumeration.

This method is optional. All Queue implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.

This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this Queue.

Inherited from:

Parameters:

  • items the Collection of items to add to this Queue

Returns:

    true if the Queue changed as a result, false otherwise
Queue:Clear()
Removes everything from the Queue.

This method is optional. All Queue implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.

This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this Queue.

Inherited from:

Queue:Contains(item)
Determines whether the Queue contains an item.

Inherited from:

Parameters:

  • item the item to locate in the Queue

Returns:

    true if the item is in the Queue, false otherwise
Queue:ContainsAll(items)
Determines whether the Queue contains all of the provided items. Checks for items provided in another Collection in an arbitrary, deterministic order. The order is the same as the order of enumeration.

Inherited from:

Parameters:

  • items the Collection of items to locate in this Queue

Returns:

    true if all items are in the Queue, false otherwise
Queue:ContainsAny(items)
Determines whether the Queue contains any of the provided items. Checks for items provided in another Collection in an arbitrary, deterministic order. The order is the same as the order of enumeration.

Inherited from:

Parameters:

  • items the Collection of items to locate in this Queue

Returns:

    true if any items are in the Queue, false otherwise
Queue:Count()
Gets the number of items in the Queue.

Inherited from:

Returns:

    the number of items
Queue:Empty()
Determines whether the Queue contains no elements.

Inherited from:

Returns:

    true if the Queue empty, false otherwise
Queue:Enumerator()
Creates an enumerator for the Queue. The enumerator can be used directly in a generic for loop similar to pairs or ipairs.

Inherited from:

Returns:

  1. the enumerator generator
  2. the invariant state
  3. the control variable state
Queue:First()
Gets the item at the beginning of the Queue.

Returns:

    the first item in the Queue

Raises:

if the Queue is empty
Queue:Push(item)
Adds an item to the end of the Queue.

This method is optional. All Queue implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.

This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this Queue.

Parameters:

  • item the item to add

Returns:

    true if the Queue changed as a result, false otherwise
Queue:Remove(item)
Removes the specified item from the Queue. Removes only a single item. If there are multiple of the same item, it removes only the first encountered.

When an item is removed any others are shifted to fill the gap left at the index of removal.

This method is optional. All Queue implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.

This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this Queue.

Inherited from:

Parameters:

  • item the item to remove from the Queue

Returns:

    true if the Queue changed as a result, false otherwise
Queue:RemoveAll(items)
Removes all provided items from the Queue. Removes each instance of a provided item only once for each time provided. If there are multiple of the same item in this Queue, it removes only the first encountered for each provided.

This method is optional. All Queue implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.

This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this Queue.

Inherited from:

Parameters:

  • items the Collection of items to remove from this Queue

Returns:

    true if the Queue changed as a result, false otherwise
Queue:RetainAll(items)
Removes all items except those provided from the Queue. Retains only the items contained in the specified Collection. If there are duplicates they are all kept.

This method is optional. All Queue implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.

This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this Queue.

Inherited from:

Parameters:

  • items the Collection of items to retain in this Queue

Returns:

    true if the Queue changed as a result, false otherwise
Queue:Shift()
Gets an item from the beginning and removes that item from the Queue. Shifts other elements to fill the gap left.

This method is optional. All Queue implementations should attempt to implement this method, but some may be unable to do so or may need to impose additional conditions to do so.

This method should always be overridden regardless of implementation. If unimplemented, it should return an error specific to the optional functionality that can't be provided by this Queue.

Returns:

    the item in the Queue

Raises:

if the Queue is empty
Queue:ToArray()
Creates a new array-indexed table of this Queue. The order of the array is the same as the order of the Queue. The first element of the Queue will get index 1 and so on.

Inherited from:

Returns:

    the array indexed table

See also:

Queue:ToTable()
Creates a new table of this Queue. Queues, being ordered and linear, need no indices that are not array indices, so this provides a table with all the same array indices as ToArray.

Inherited from:

Returns:

    the table

See also:

generated by LDoc 1.4.6 Last updated 2022-03-30 00:04:00