/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ /** * Represents a node in a doubly linked list. * @internal */ export interface ListNode { /** * The list this node belongs to, or undefined if not attached. */ readonly list: DoublyLinkedList | undefined; /** * The data value stored in this node. */ readonly data: T; /** * The next node in the list, or undefined if this is the last node. */ readonly next: ListNode | undefined; /** * The previous node in the list, or undefined if this is the first node. */ readonly prev: ListNode | undefined; /** * Removes this node from its list. * @returns The removed node, or undefined if not in a list. */ remove(): ListNode | undefined; } /** * Represents a range of nodes in a doubly linked list. * @internal */ export interface ListNodeRange { /** * The first node in the range. */ first: ListNode; /** * The last node in the range. */ last: ListNode; } /** * A doubly linked list implementation with array-like methods and node access. * @typeParam T - The type of data stored in the list nodes. * @internal */ export declare class DoublyLinkedList implements Iterable>, // try to match array signature and semantics where possible Pick[], "pop" | "shift" | "length" | "includes"> { /** * Creates a new doubly linked list optionally initialized with values. * @param values - Optional iterable of values to populate the list. */ constructor(values?: Iterable); /** * Finds the first node matching the predicate. * @param predicate - Function to test each node. * @returns The first matching node, or undefined if none found. */ find(predicate: (value: ListNode, obj: DoublyLinkedList) => boolean): ListNode | undefined; /** * Returns an iterable that maps each node to a new value. * @param callbackfn - Function to produce a new value for each node. */ map(callbackfn: (value: ListNode) => U): Iterable; /** * Inserts items after the specified node. * @param preceding - The node to insert after. * @param items - Items to insert. * @returns The range of newly inserted nodes. */ insertAfter(preceding: ListNode, ...items: T[]): ListNodeRange; /** * Removes and returns the last node in the list. * @returns The removed node, or undefined if the list is empty. */ pop(): ListNode | undefined; /** * Appends items to the end of the list. * @param items - Items to append. * @returns The range of newly inserted nodes. */ push(...items: T[]): ListNodeRange; /** * Removes and returns the first node in the list. * @returns The removed node, or undefined if the list is empty. */ shift(): ListNode | undefined; /** * Inserts items at the start of the list. * @param items - Items to insert. * @returns The range of newly inserted nodes. */ unshift(...items: T[]): ListNodeRange; /** * Removes nodes starting at `start` until `end` or `count` is reached. * @param start - The node to start removing from. * @param countOrEnd - The number of nodes to remove or the end node. * @returns A new list containing the removed nodes. */ splice(start: ListNode, countOrEnd?: ListNode | number): DoublyLinkedList; /** * Checks if the node is in this list. * @param node - The node to check. * @returns True if the node is in the list. */ includes(node: ListNode | undefined): node is ListNode; private _includes; private _remove; /** * Removes the specified node from the list. * @param node - The node to remove. * @returns The removed node, or undefined if not in the list. */ remove(node: ListNode | undefined): ListNode | undefined; [Symbol.iterator](): IterableIterator>; private _len; private readonly headNode; /** * The number of nodes in the list. */ get length(): number; /** * Whether the list is empty. */ get empty(): boolean; /** * The first node in the list, or undefined if empty. */ get first(): ListNode | undefined; /** * The last node in the list, or undefined if empty. */ get last(): ListNode | undefined; } /** * Iterates over the nodes of a `DoublyLinkedList`, calling the provided visitor function for each node. * Iteration starts at the specified node (or at the head/tail if not provided) and proceeds forward or backward. * If the visitor returns `false`, iteration stops early. * * @typeParam T - The type of data stored in the list nodes. * @param list - The list to walk. * @param visitor - Function called for each node. If it returns `false`, iteration stops. * @param start - Optional node to start iteration from. If not provided, starts at the first (or last if `forward` is false) node. * @param forward - If `true` (default), iterates forward; if `false`, iterates backward. * @returns `false` if iteration was stopped early by the visitor, otherwise `true`. * * @internal */ export declare function walkList(list: DoublyLinkedList, visitor: (node: ListNode) => boolean | void, start?: ListNode, forward?: boolean): boolean; /** * Creates a lazily evaluated iterable which returns values while the predicate returns true, * and stops iterating at the first value where the predicate is false. * @param start - the node to start the iteration from * @param includePredicate - determine if the current value be included in the iteration or stop if iteration * * @internal */ export declare function iterateListValuesWhile(start: ListNode | undefined, includePredicate: (n: ListNode) => boolean): Iterable; //# sourceMappingURL=list.d.ts.map