UNPKG

@traxjs/trax

Version:

Reactive state management

46 lines (45 loc) 1.31 kB
interface ListItem<T> { value: T; next?: ListItem<T>; } /** * Simple Linked list that can be used to manage stacks * Object properties are voluntarily kept minimal to minimize memory footprint */ export declare class LinkedList<T> { private _head?; private _size; get head(): ListItem<T> | undefined; get size(): number; /** * Add a new value at the head of the list * @param value * @returns the list item */ add(value: T): ListItem<T>; /** * Insert an item in the lhe linked list * @param fn function that decides where to insert the item. * Once the function returns an item, the iteration will stop */ insert(fn: (prev?: T, next?: T) => T | void): void; /** * Return the item value at the head of the list, * but doesn't remove it from the list * @returns the head value or undefined */ peek(): T | undefined; /** * Return the item value at the head of the list, * and remove it from the list * @returns the head value or undefined */ shift(): T | undefined; /** * Scan the list and remove the first item with the corresponding value * @param value * @returns true if an item was found and removed */ remove(value: T): boolean; } export {};