UNPKG

dastal

Version:

Data Structures & Algorithms implementations

70 lines (69 loc) 2.68 kB
import { CompareFn } from '..'; import { DoublyLinkedNode } from './doublyLinkedNode'; import { List } from './list'; /** * A (circular) doubly-linked list implementation of the {@link List} interface. * * Operations that index into the list will traverse the list from the beginning or the end, whichever is closer to the specified index. */ export declare class DoublyLinkedList<T> implements List<T> { /** * The number of elements in the list */ protected length: number; /** * The sentinel node at the fron of the list */ protected root: DoublyLinkedNode<T>; /** * Instantiate the list. * * @param elements - A set of elements to initialize the list with. */ constructor(elements?: Iterable<T>); add(index: number, value: T): number; addAll(index: number, elements: Iterable<T>): number; clear(): void; concat(...lists: Iterable<T>[]): DoublyLinkedList<T>; copyWithin(index: number, min?: number, max?: number): this; fill(element: T, min?: number, max?: number): this; get(index: number): T | undefined; getSet(index: number, callback: (element: T) => T): T | undefined; pop(): T | undefined; push(value: T): number; remove(index: number): T | undefined; reverse(min?: number, max?: number): this; set(index: number, element: T): T | undefined; shift(): T | undefined; get size(): number; slice(min?: number, max?: number): DoublyLinkedList<T>; splice(start?: number, count?: number, elements?: Iterable<T>): List<T>; sort(compareFn: CompareFn<T>): this; /** * Receive an iterator through the list. * * **Note:** Unexpected behavior can occur if the collection is modified during iteration. * * @returns An iterator through the list */ [Symbol.iterator](): Iterator<T>; unshift(value: T): number; update(callback: (element: T, index: number) => T): this; update(min: number | undefined, callback: (element: T, index: number) => T): this; update(min: number | undefined, max: number | undefined, callback: (element: T, index: number) => T): this; view(min?: number, max?: number): Iterable<T>; /** * */ protected _addAll(next: DoublyLinkedNode<T>, elements: Iterable<T>): void; /** * A helper method to iterate and return the node at the given index. * * Depending on the index, the list will be traversed from beginning or end; whichever is closest to the specified index. * * @param index - The index to retrieve * * @returns The node at the given index */ protected _get(index: number): DoublyLinkedNode<T>; }