UNPKG

@thi.ng/dcons

Version:

Double-linked lists with comprehensive set of operations (incl. optional self-organizing behaviors)

78 lines 2.85 kB
import type { Comparator, Fn, ICompare, IEmpty, ISeq, ISeqable, IStack, Maybe } from "@thi.ng/api"; import type { IRandom } from "@thi.ng/random"; import { AList } from "./alist.js"; import type { ConsCell } from "./api.js"; export declare class DCons<T> extends AList<DCons<T>, T> implements ICompare<DCons<T>>, IEmpty<DCons<T>>, IStack<T, T, DCons<T>>, ISeqable<T> { protected _tail: Maybe<ConsCell<T>>; constructor(src?: Iterable<T>); get tail(): Maybe<ConsCell<T>>; append(value: T): ConsCell<T>; asHead(cell: ConsCell<T>): this; asTail(cell: ConsCell<T>): this; /** @deprecated use {@link DCons.prepend} */ cons(value: T): DCons<T>; copy(): DCons<T>; cycle(): Generator<T, void, unknown>; drop(): T | undefined; empty(): DCons<T>; insertAfter(cell: ConsCell<T>, value: T): ConsCell<T>; insertAfterNth(n: number, x: T): ConsCell<T>; insertBefore(cell: ConsCell<T>, value: T): ConsCell<T>; insertBeforeNth(n: number, x: T): ConsCell<T>; map<R>(fn: Fn<T, R>): DCons<R>; nth(n: number, notFound?: T): T | undefined; nthCell(n: number): Maybe<ConsCell<T>>; pop(): T | undefined; prepend(value: T): ConsCell<T>; push(value: T): DCons<T>; release(): boolean; remove(cell: ConsCell<T>): this; rotateLeft(): DCons<T>; rotateRight(): this; /** * Implementation of * [ISeqable.seq](https://docs.thi.ng/umbrella/api/interfaces/ISeqable.html#seq.seq-1) */ seq(start?: number, end?: number): ISeq<T> | undefined; /** * Shuffles list by probabilistically moving cells to head or tail * positions. * * @remarks * Supports configurable iterations and custom PRNG via * [`IRandom`](https://docs.thi.ng/umbrella/random/interfaces/IRandom.html) * (default: * [`SYSTEM`](https://docs.thi.ng/umbrella/random/variables/SYSTEM.html)). * * Default iterations: `ceil(3/2 * log2(n))` * * @param iter - * @param rnd - */ shuffle(iter?: number, rnd?: IRandom): this; slice(from?: number, to?: number): DCons<T>; /** * Merge sort implementation based on Simon Tatham's algorithm: * https://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html * * @remarks * Uses * [`compare`](https://docs.thi.ng/umbrella/compare/functions/compare.html) * as default comparator. * * @param cmp - */ sort(cmp?: Comparator<T>): this; splice(at: ConsCell<T> | number, del?: number, insert?: Iterable<T>): DCons<T>; } /** * Functional syntax sugar for `new DCons(src?)`. * * @param src - */ export declare const defDCons: <T>(src?: Iterable<T>) => DCons<T>; /** * @deprecated use {@link defDCons} instead */ export declare const dcons: <T>(src?: Iterable<T>) => DCons<T>; //# sourceMappingURL=dcons.d.ts.map