DoubleEndedQueue

DoubleEndedQueue

Custom implementation of a double ended queue. Every queue operation is done at a constant O(1) - including random access from .peekAt(index). It May also be used as a stack or a regular queue. Double-ended queue on Wikipedia Queue (abstract data type) on Wikipedia Stack (abstract data type) on Wikipedia

Constructor

new DoubleEndedQueue()

Source:

Members

length

Returns the current length of the queue
Source:

Methods

clear()

Soft clear - does not reset capacity.
Source:

get(index) → {*}

Alias for peekAt()
Parameters:
Name Type Description
index number
Source:
Returns:
Type
*

isEmpty() → {boolean}

Returns true or false whether the list is empty.
Source:
Returns:
Type
boolean

peek() → {*}

Returns the first item in the list without removing it.
Source:
Returns:
Type
*

peekAt(index) → {*}

Returns the item at the specified index from the list. 0 is the first element, 1 is the second, and so on... Elements at negative values are that many from the end: -1 is one before the end (the last element), -2 is two before the end (one before last), etc.
Parameters:
Name Type Description
index number
Source:
Returns:
Type
*

peekBack()

Returns the item that is at the back of the queue without removing it. Uses peekAt(-1)
Source:

peekFront() → {*}

Alias for peek()
Source:
Returns:
Type
*

pop() → {*}

Remove and return the last item on the list. Returns undefined if the list is empty.
Source:
Returns:
Type
*

push(item)

Add an item to the bottom of the list.
Parameters:
Name Type Description
item
Source:

remove(index, count) → {array}

Remove number of items from the specified index from the list. Returns array of removed items. Returns undefined if the list is empty.
Parameters:
Name Type Description
index
count
Source:
Returns:
Type
array

removeOne(index) → {*}

Remove and return the item at the specified index from the list. Returns undefined if the list is empty.
Parameters:
Name Type Description
index
Source:
Returns:
Type
*

shift() → {*}

Remove and return the first item on the list, Returns undefined if the list is empty.
Source:
Returns:
Type
*

size() → {number}

Return the number of items on the list, or 0 if empty.
Source:
Returns:
Type
number

splice(index, count, …elementsopt) → {array}

Native splice implementation. Remove number of items from the specified index from the list and/or add new elements. Returns array of removed items or empty array if count == 0. Returns undefined if the list is empty.
Parameters:
Name Type Attributes Description
index
count
elements * <optional>
<repeatable>
Source:
Returns:
Type
array

toArray() → {Array}

Returns an array of all queue items.
Source:
Returns:
Type
Array

unshift(item)

Add an item at the beginning of the list.
Parameters:
Name Type Description
item
Source: