Home Reference Source Test Repository
public class | source

Queue

Creates a new queue. A queue is a first-in-first-out (FIFO) data structure - items are added to the end of the queue and removed from the front.

Constructor Summary

Public Constructor
public

Constructs a Queue instance.

Member Summary

Public Members
public
public

queue: *

public get

size: number: *

Getter for size, allows access as a property).

Method Summary

Public Methods
public

clear()

Clear the queue.

public

dequeue(): *

Dequeues an item and returns it.

public

enqueue(item: *)

Enqueues the specified item.

public

forEach(callback: function(item: *): boolean)

Helper function to loop through all items in the queue.

public

has(item: *): boolean

Check if the queue contains the specified item.

public

peek(): *

Returns the item at the front of the queue (without dequeuing it).

Public Constructors

public constructor source

Constructs a Queue instance.

Public Members

public offset: number source

public queue: * source

public get size: number: * source

Getter for size, allows access as a property).

Return:

number

Size of the queue.

Public Methods

public clear() source

Clear the queue.

public dequeue(): * source

Dequeues an item and returns it. If the queue is empty, the value null is returned.

Return:

* (nullable: true)

The next item in the queue, or null if the queue is empty.

public enqueue(item: *) source

Enqueues the specified item.

Params:

NameTypeAttributeDescription
item *

the item to enqueue

public forEach(callback: function(item: *): boolean) source

Helper function to loop through all items in the queue.

Params:

NameTypeAttributeDescription
callback function(item: *): boolean

Callback function called for each item in the queue. If the return value is false, the remaining items are skipped.

public has(item: *): boolean source

Check if the queue contains the specified item.

Params:

NameTypeAttributeDescription
item *

Item to check.

Return:

boolean

Whether or not the item is in the queue.

Throw:

Error

Throws an error if checking null or undefined.

public peek(): * source

Returns the item at the front of the queue (without dequeuing it). If the queue is empty then null is returned.

Return:

* (nullable: true)

The next item in the queue, or null if the queue is empty.