Skip to content

Latest commit

 

History

History
690 lines (387 loc) · 17.2 KB

CircularLinkedDeque.md

File metadata and controls

690 lines (387 loc) · 17.2 KB

circle-ds / Exports / CircularLinkedDeque

Class: CircularLinkedDeque<T>

A circular deque is similar to a traditional deque, but uses a fixed-size, circular buffer. When the deque reaches its maximum capacity and a new element is added, the oldest is discarded, thus maintaining its size.

This structure efficiently utilizes memory for applications where only the most recent additions are of interest and older data can be discarded.

See

Wikipedia

Type parameters

Name
T

Implements

Table of contents

Constructors

Accessors

Methods

Constructors

constructor

new CircularLinkedDeque<T>(): CircularLinkedDeque<T>

Creates a new stack with capacity defaulted to Infinity.

Type parameters

Name
T

Returns

CircularLinkedDeque<T>

Defined in

collections/deque/circularLinkedDeque.ts:26

new CircularLinkedDeque<T>(capacity?): CircularLinkedDeque<T>

Creates a new stack with the given capacity.

Type parameters

Name
T

Parameters

Name Type Description
capacity? null | number the stack's capacity.

Returns

CircularLinkedDeque<T>

Defined in

collections/deque/circularLinkedDeque.ts:32

new CircularLinkedDeque<T>(items): CircularLinkedDeque<T>

Creates a new stack. Initial capacity is the number of items given.

Type parameters

Name
T

Parameters

Name Type Description
items Iterable<T> the values to store in the stack.

Returns

CircularLinkedDeque<T>

Defined in

collections/deque/circularLinkedDeque.ts:38

Accessors

[toStringTag]

get [toStringTag](): string

A string tag for the Collection class that is used in Object.prototype.toString.

Returns

string

Implementation of

Deque.[toStringTag]

Defined in

collections/deque/circularLinkedDeque.ts:51


capacity

get capacity(): number

Represents the maximum number of elements that the collection can hold. Once capacity is reached, no additional elements can be added without removing existing elements first. This is integral to the behavior of bounded collections, providing a way to manage size.

  1. Capacity should be a non-negative integer.

  2. Implementers may choose to support dynamic capacity updates.

  3. Implementers may choose to accept positive infinity (Number.POSITIVE_INFINITY) as a valid capacity. This would effectively remove the upper limit on the collection size, allowing it to grow unbounded. That said, size may still be constrained by the implementation. For example, a simple array-based collection would be limited to an array's maximum length (2^32 - 1 in JavaScript).

Returns

number

Implementation of

Bounded.capacity

Defined in

collections/deque/circularLinkedDeque.ts:43

set capacity(capacity): void

Represents the maximum number of elements that the collection can hold. Once capacity is reached, no additional elements can be added without removing existing elements first. This is integral to the behavior of bounded collections, providing a way to manage size.

  1. Capacity should be a non-negative integer.

  2. Implementers may choose to support dynamic capacity updates.

  3. Implementers may choose to accept positive infinity (Number.POSITIVE_INFINITY) as a valid capacity. This would effectively remove the upper limit on the collection size, allowing it to grow unbounded. That said, size may still be constrained by the implementation. For example, a simple array-based collection would be limited to an array's maximum length (2^32 - 1 in JavaScript).

Parameters

Name Type
capacity number

Returns

void

Implementation of

Bounded.capacity

Defined in

collections/deque/circularLinkedDeque.ts:55


size

get size(): number

Gets the number of elements contained in the Collection.

Returns

number

Implementation of

Deque.size

Defined in

collections/deque/circularLinkedDeque.ts:47

Methods

[iterator]

[iterator](): IterableIterator<T>

Returns the default iterator through the queue's elements.

Returns

IterableIterator<T>

Implementation of

Deque.[iterator]

Defined in

collections/deque/circularLinkedDeque.ts:106


addListener

addListener(event, listener): this

Attaches a listener to the end of the listeners array for the specified event. If the same listener is added multiple times for the same event, it will be invoked multiple times when the event is emitted.

Parameters

Name Type Description
event "overflow" The specific event to listen for. Use BoundedEvent.Overflow for overflow-specific handling or other events as defined by the implementation.
listener (elems: T[]) => void The callback function to execute when the event occurs. For BoundedEvent.Overflow, it receives an array of elements removed due to overflow.

Returns

this

The instance of the collection, allowing for method chaining.

Implementation of

Bounded.addListener

Defined in

collections/deque/circularLinkedDeque.ts:122


clear

clear(): void

Removes all elements from the Collection, effectively resetting it.

Returns

void

Implementation of

Deque.clear

Defined in

collections/deque/circularLinkedDeque.ts:67


entries

entries(): IterableIterator<[number, T]>

Returns a new iterator object that contains an array of [key, value] pairs for each element in the Collection.

Returns

IterableIterator<[number, T]>

An iterable iterator for the entries of the collection.

Implementation of

Deque.entries

Defined in

collections/deque/circularLinkedDeque.ts:71


first

first(): undefined | T

Retrieves the first element added to the queue without removing it.

Returns

undefined | T

The first element of the queue, or undefined if the queue is empty.

Implementation of

Deque.first

Defined in

collections/deque/circularLinkedDeque.ts:59


forEach

forEach(callbackfn, thisArg?): void

Executes a provided function once for each key-value pair in the Collection.

Parameters

Name Type Description
callbackfn (value: T, index: number, collection: this) => void A function to execute for each element, receiving the value, key, and collection instance as arguments.
thisArg? unknown An optional value to use as this when executing callbackfn.

Returns

void

Implementation of

Deque.forEach

Defined in

collections/deque/circularLinkedDeque.ts:75


front

front(): undefined | T

Retrieves the element at the front of the queue without removing it.

This method provides semantic clarity in contexts where the term "front" is preferred over "first" to describe the element that was added earliest and will be processed next.

Returns

undefined | T

The element at the front of the queue, or undefined if the queue is empty.

Implementation of

Deque.front

Defined in

collections/deque/circularLinkedDeque.ts:63


has

has(value): boolean

Determines whether a specific element exists within the queue.

Parameters

Name Type Description
value T The value to locate.

Returns

boolean

true if the value exists, false otherwise.

Implementation of

Deque.has

Defined in

collections/deque/circularLinkedDeque.ts:82


keys

keys(): IterableIterator<number>

Returns a new iterator that contains the keys for each element in the Collection.

Returns

IterableIterator<number>

An iterable iterator for the keys of the collection.

Implementation of

Deque.keys

Defined in

collections/deque/circularLinkedDeque.ts:86


last

last(): undefined | T

Retrieves the last element added to the stack without removing it.

Returns

undefined | T

The last element of the stack, or undefined if the stack is empty.

Implementation of

Deque.last

Defined in

collections/deque/circularLinkedDeque.ts:90


on

on(event, listener): this

An alias to addListener, providing a semantic way to register event listeners. Follows the same behavior and signature as addListener.

Parameters

Name Type
event "overflow"
listener (elems: T[]) => void

Returns

this

Implementation of

Bounded.on

Defined in

collections/deque/circularLinkedDeque.ts:130


pop

pop(): undefined | T

Removes the last element added to the stack and returns it.

Returns

undefined | T

The last element of the stack, or undefined if the stack is empty.

Implementation of

Deque.pop

Defined in

collections/deque/circularLinkedDeque.ts:94


push

push(...elems): number

Adds one or more elements to the end of the queue and returns the queue's new length.

Parameters

Name Type Description
...elems T[] The elements to add.

Returns

number

The new length of the queue.

Implementation of

Deque.push

Defined in

collections/deque/circularLinkedDeque.ts:98


removeListener

removeListener(event, listener): this

Removes the specified listener from the listener array for the event. Only one instance of the listener is removed per call. If the listener was added multiple times for the same event, multiple calls are required to remove each instance.

Parameters

Name Type Description
event "overflow" The specific event from which to remove the listener.
listener (elems: T[]) => void The callback function to remove from the event's listeners array.

Returns

this

The instance of the collection, allowing for method chaining.

Implementation of

Bounded.removeListener

Defined in

collections/deque/circularLinkedDeque.ts:138


shift

shift(): undefined | T

Removes and returns the first element of the queue.

Returns

undefined | T

The first element of the queue, or undefined if the queue is empty.

Implementation of

Deque.shift

Defined in

collections/deque/circularLinkedDeque.ts:102


top

top(): undefined | T

Retrieves the element at the top of the stack without removing it.

This method provides semantic clarity in contexts where the term "top" is preferred over "last" to describe the most recently added element.

Returns

undefined | T

The element at the top of the stack, or undefined if the stack is empty.

Implementation of

Deque.top

Defined in

collections/deque/circularLinkedDeque.ts:110


unshift

unshift(...elems): number

Adds one or more elements to the front of the deque and returns the new length.

This method allows for efficient front-end insertion, complementing the push method inherited from the Stack interface for back-end insertion.

Parameters

Name Type Description
...elems T[] The elements to add to the front of the deque.

Returns

number

The new length of the deque after the elements are added.

Implementation of

Deque.unshift

Defined in

collections/deque/circularLinkedDeque.ts:114


values

values(): IterableIterator<T>

Returns a new iterator that contains the values for each element in the Collection.

Returns

IterableIterator<T>

An iterable iterator for the values of the collection.

Implementation of

Deque.values

Defined in

collections/deque/circularLinkedDeque.ts:118