Queue

class Queue<T>

FIFO Queue

Example:

// Create a new queue
val queue = Queue<Int>()

for (i in 1 .. 3)
queue += i

for (i in 1 .. 3)
require(queue.next() == i)

Author

Elizabeth Paige Harper - https://github.com/foxcapades

Since

1.0.0

Parameters

T

Type of items that will be appended to this queue.

Constructors

Link copied to clipboard
fun Queue(initialCapacity: Int = 8, scaleFactor: Float = 1.5f, maxSize: Int = Int.MAX_VALUE)

Constructs a new Queue instance.

Functions

Link copied to clipboard
fun append(value: T)

Appends the given value to the tail end of the queue.

Link copied to clipboard
fun clear()

Clears all elements from this queue.

Link copied to clipboard
operator fun contains(element: T): Boolean

Tests whether this Queue contains the given item.

Link copied to clipboard
fun containsAll(vararg elements: T): Boolean
fun containsAll(elements: Collection<T>): Boolean

Tests whether this Queue contains all the given elements.

Link copied to clipboard
inline fun destructiveForEach(fn: (T) -> Unit)
Link copied to clipboard
Link copied to clipboard
operator fun get(i: Int): T

Gets the target queue element without removing it from the queue.

Link copied to clipboard
fun next(): T

Removes and returns the value from the head of the queue.

Link copied to clipboard
inline fun nonDestructiveForEach(fn: (T) -> Unit)
Link copied to clipboard
Link copied to clipboard
fun peek(): T

Returns the value at the head of the queue without removing it.

Link copied to clipboard
operator fun plusAssign(value: T)

Alias for append.

Properties

Link copied to clipboard

Current capacity of this queue.

Link copied to clipboard

Returns the range of valid indices in this Queue.

Link copied to clipboard

true if this Queue contains zero items.

Link copied to clipboard

true if this Queue contains one or more items.

Link copied to clipboard

Last valid index in this Queue.

Link copied to clipboard

The maximum size this queue may grow to.

Link copied to clipboard
var size: Int

Current size of this queue.