UNPKG

dastal

Version:

Data Structures & Algorithms implementations

75 lines (74 loc) 2.74 kB
import { CompareFn } from '..'; import { LinkedNode } from './linkedNode'; import { List } from './list'; /** * A (circular) linked list implementation of the {@link List} interface. */ export declare class LinkedList<T> implements List<T> { /** * The number of elements in the list. */ protected length: number; /** * The sentinel node at the front of the list. */ protected root: LinkedNode<T>; /** * The last node of the list. */ protected tail: LinkedNode<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>[]): LinkedList<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): LinkedList<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(prev: LinkedNode<T>, elements: Iterable<T>): LinkedNode<T>; /** * Copy values from 'from' to 'to'. * * @param from - The initial node to copy from * @param prev - The root of the initial node to copy to * @param count - The number of values to copy */ protected _copyWithin(from: LinkedNode<T>, to: LinkedNode<T>, count: number): LinkedNode<T>; /** * Get the node at the given index. * * @param index - The index to retrieve * * @returns The node at the given index */ protected _get(index: number, root?: LinkedNode<T>): LinkedNode<T>; }