Class Deque

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

Deques have a distinct, linear ordering of their elements and can be added to and removed from at the back and front. The combination of these ensures that the first elements added from either end are the first ones out of the other end of the Deque.

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

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

Implements: Queue, Collection, Enumerable

Functions

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

Methods

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


Functions

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

Access:

    private

Returns:

    the new Deque interface

Methods

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

This method is optional. All Deque 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 Deque.

Inherited from:

Parameters:

  • item the item to add

Returns:

    true if the Deque changed as a result, false otherwise
Deque:AddAll(items)
Adds all provided items to the Deque. 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 Deque 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 Deque.

Inherited from:

Parameters:

  • items the Collection of items to add to this Deque

Returns:

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

This method is optional. All Deque 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 Deque.

Inherited from:

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

Inherited from:

Parameters:

  • item the item to locate in the Deque

Returns:

    true if the item is in the Deque, false otherwise
Deque:ContainsAll(items)
Determines whether the Deque contains all of the 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 Deque

Returns:

    true if all items are in the Deque, false otherwise
Deque:ContainsAny(items)
Determines whether the Deque 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 Deque

Returns:

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

Inherited from:

Returns:

    the number of items
Deque:Empty()
Determines whether the Deque has no elements.

Inherited from:

Returns:

    true if the Deque empty, false otherwise
Deque:Enumerator()
Creates an enumerator for the Deque. 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
Deque:First()
Gets the item at the beginning of the Deque.

Inherited from:

Returns:

    the first item in the Deque

Raises:

if the Deque is empty
Deque:Last()
Gets the item at the end of the Deque.

Returns:

    the last item in the Deque

Raises:

if the Deque is empty
Deque:Pop()
Gets an item from the end and removes that item from the Deque. Shifts other elements to fill the gap left.

This method is optional. All Deque 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 Deque.

Returns:

    the item in the Deque

Raises:

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

This method is optional. All Deque 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 Deque.

Inherited from:

Parameters:

  • item the item to add

Returns:

    true if the Deque changed as a result, false otherwise
Deque:Remove(item)
Removes the specified item from the Deque. 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 Deque 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 Deque.

Inherited from:

Parameters:

  • item the item to remove from the Deque

Returns:

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

This method is optional. All Deque 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 Deque.

Inherited from:

Parameters:

  • items the Collection of items to remove from this Deque

Returns:

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

This method is optional. All Deque 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 Deque.

Inherited from:

Parameters:

  • items the Collection of items to retain in this Deque

Returns:

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

This method is optional. All Deque 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 Deque.

Inherited from:

Returns:

    the item in the Deque

Raises:

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

Inherited from:

Returns:

    the array indexed table

See also:

Deque:ToTable()
Creates a new table of this Deque. Deques, 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:

Deque:Unshift(item)
Adds an item to the beginning of the Deque.

This method is optional. All Deque 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 Deque.

Parameters:

  • item the item to add

Returns:

    true if the Deque changed as a result, false otherwise
generated by LDoc 1.4.6 Last updated 2022-03-30 00:04:00