Class Deque<T>

Source
Expand description

A high-performance, memory-efficient double-ended queue (deque) that automatically grows and can be configured to shrink.

Constructors§

Source§

new Deque<T>(initialCapacity?: number, autoShrink?: boolean): Deque<T>

Accessors§

Source§

get empty(): boolean

Checks if the deque is empty.

complexity

O(1)

Source§

get first(): undefined | T

Returns the first element.

complexity

O(1)

Source§

get last(): undefined | T

Returns the last element.

complexity

O(1)

Source§

get length(): number

The number of elements in the deque.

complexity

O(1)

Methods§

Source§

"[iterator]"(): Iterator<T>

Returns an iterator over the elements of the deque.

complexity

O(n)

Source§

clear(): void

Clears all elements from the deque.

complexity

O(n)

Source§

pop(): undefined | T

Removes and returns the element from the back of the deque.

complexity

O(1) amortized

Source§

push(value: T): number

Adds an element to the back of the deque.

complexity

O(1) amortized

Source§

shift(): undefined | T

Removes and returns the element from the front of the deque.

complexity

O(1) amortized

Source§

unshift(value: T): number

Adds an element to the front of the deque.

complexity

O(1) amortized