X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fdeque.ts;h=52441a3ec25f4f7251575104a0884f9ffeb22d00;hb=5b95eb9bcafda56ce57003da834cf4e153bb0509;hp=fe82a79896a08757e3f261b66aa364b1407ab6e9;hpb=799c9e089724b6402ae72e0a60719017055a6669;p=poolifier.git diff --git a/src/deque.ts b/src/deque.ts index fe82a798..52441a3e 100644 --- a/src/deque.ts +++ b/src/deque.ts @@ -1,19 +1,15 @@ -// Copyright Jerome Benoit. 2023. All Rights Reserved. +// Copyright Jerome Benoit. 2023-2024. All Rights Reserved. /** - * Node. + * Linked list node interface. * - * @typeParam T - Type of node data. + * @typeParam T - Type of linked list node data. * @internal */ -export class Node { - public data: T - public next?: Node - public prev?: Node - - public constructor (data: T) { - this.data = data - } +export interface ILinkedListNode { + data: T + next?: ILinkedListNode + prev?: ILinkedListNode } /** @@ -24,8 +20,8 @@ export class Node { * @internal */ export class Deque { - private head?: Node - private tail?: Node + private head?: ILinkedListNode + private tail?: ILinkedListNode /** The size of the deque. */ public size!: number /** The maximum size of the deque. */ @@ -39,10 +35,10 @@ export class Deque { * Appends data to the deque. * * @param data - Data to append. - * @returns The new size of the queue. + * @returns The new size of the deque. */ public push (data: T): number { - const node = new Node(data) + const node: ILinkedListNode = { data } if (this.tail == null) { this.head = this.tail = node } else { @@ -56,10 +52,10 @@ export class Deque { * Prepends data to the deque. * * @param data - Data to prepend. - * @returns The new size of the queue. + * @returns The new size of the deque. */ public unshift (data: T): number { - const node = new Node(data) + const node: ILinkedListNode = { data } if (this.head == null) { this.head = this.tail = node } else {