circle-ds / Exports / CircularLinkedDeque
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
Name |
---|
T |
- [iterator]
- addListener
- clear
- entries
- first
- forEach
- front
- has
- keys
- last
- on
- pop
- push
- removeListener
- shift
- top
- unshift
- values
• new CircularLinkedDeque<T
>(): CircularLinkedDeque
<T
>
Creates a new stack with capacity
defaulted to Infinity
.
Name |
---|
T |
collections/deque/circularLinkedDeque.ts:26
• new CircularLinkedDeque<T
>(capacity?
): CircularLinkedDeque
<T
>
Creates a new stack with the given capacity.
Name |
---|
T |
Name | Type | Description |
---|---|---|
capacity? |
null | number |
the stack's capacity. |
collections/deque/circularLinkedDeque.ts:32
• new CircularLinkedDeque<T
>(items
): CircularLinkedDeque
<T
>
Creates a new stack. Initial capacity is the number of items given.
Name |
---|
T |
Name | Type | Description |
---|---|---|
items |
Iterable <T > |
the values to store in the stack. |
collections/deque/circularLinkedDeque.ts:38
• get
[toStringTag](): string
A string tag for the Collection
class that is used in Object.prototype.toString
.
string
Deque.[toStringTag]
collections/deque/circularLinkedDeque.ts:51
• 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.
-
Capacity should be a non-negative integer.
-
Implementers may choose to support dynamic capacity updates.
-
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).
number
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.
-
Capacity should be a non-negative integer.
-
Implementers may choose to support dynamic capacity updates.
-
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).
Name | Type |
---|---|
capacity |
number |
void
collections/deque/circularLinkedDeque.ts:55
• get
size(): number
Gets the number of elements contained in the Collection
.
number
Deque.size
collections/deque/circularLinkedDeque.ts:47
▸ [iterator](): IterableIterator
<T
>
Returns the default iterator through the queue's elements.
IterableIterator
<T
>
collections/deque/circularLinkedDeque.ts:106
▸ 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.
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. |
this
The instance of the collection, allowing for method chaining.
collections/deque/circularLinkedDeque.ts:122
▸ clear(): void
Removes all elements from the Collection
, effectively resetting it.
void
collections/deque/circularLinkedDeque.ts:67
▸ entries(): IterableIterator
<[number
, T
]>
Returns a new iterator object that contains an array of [key, value]
pairs for each element in the Collection
.
IterableIterator
<[number
, T
]>
An iterable iterator for the entries of the collection.
collections/deque/circularLinkedDeque.ts:71
▸ first(): undefined
| T
Retrieves the first element added to the queue without removing it.
undefined
| T
The first element of the queue, or undefined
if the queue is empty.
collections/deque/circularLinkedDeque.ts:59
▸ forEach(callbackfn
, thisArg?
): void
Executes a provided function once for each key-value pair in the Collection
.
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 . |
void
collections/deque/circularLinkedDeque.ts:75
▸ 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.
undefined
| T
The element at the front of the queue, or undefined
if the queue is empty.
collections/deque/circularLinkedDeque.ts:63
▸ has(value
): boolean
Determines whether a specific element exists within the queue.
Name | Type | Description |
---|---|---|
value |
T |
The value to locate. |
boolean
true
if the value exists, false
otherwise.
collections/deque/circularLinkedDeque.ts:82
▸ keys(): IterableIterator
<number
>
Returns a new iterator that contains the keys for each element
in the Collection
.
IterableIterator
<number
>
An iterable iterator for the keys of the collection.
collections/deque/circularLinkedDeque.ts:86
▸ last(): undefined
| T
Retrieves the last element added to the stack without removing it.
undefined
| T
The last element of the stack, or undefined
if the stack is empty.
collections/deque/circularLinkedDeque.ts:90
▸ on(event
, listener
): this
An alias to addListener
, providing a semantic way to register event listeners.
Follows the same behavior and signature as addListener
.
Name | Type |
---|---|
event |
"overflow" |
listener |
(elems : T []) => void |
this
collections/deque/circularLinkedDeque.ts:130
▸ pop(): undefined
| T
Removes the last element added to the stack and returns it.
undefined
| T
The last element of the stack, or undefined
if the stack is empty.
collections/deque/circularLinkedDeque.ts:94
▸ push(...elems
): number
Adds one or more elements to the end of the queue and returns the queue's new length.
Name | Type | Description |
---|---|---|
...elems |
T [] |
The elements to add. |
number
The new length of the queue.
collections/deque/circularLinkedDeque.ts:98
▸ 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.
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. |
this
The instance of the collection, allowing for method chaining.
collections/deque/circularLinkedDeque.ts:138
▸ shift(): undefined
| T
Removes and returns the first element of the queue.
undefined
| T
The first element of the queue, or undefined
if the queue is empty.
collections/deque/circularLinkedDeque.ts:102
▸ 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.
undefined
| T
The element at the top of the stack, or undefined
if the stack is empty.
collections/deque/circularLinkedDeque.ts:110
▸ 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.
Name | Type | Description |
---|---|---|
...elems |
T [] |
The elements to add to the front of the deque. |
number
The new length of the deque after the elements are added.
collections/deque/circularLinkedDeque.ts:114
▸ values(): IterableIterator
<T
>
Returns a new iterator that contains the values for each element
in the Collection
.
IterableIterator
<T
>
An iterable iterator for the values of the collection.