@thi.ng/dcons
Version:
Double-linked lists with comprehensive set of operations (incl. optional self-organizing behaviors)
52 lines • 1.71 kB
TypeScript
import type { Fn2, Predicate } from "@thi.ng/api";
import type { ConsCell } from "./api.js";
import { DCons } from "./dcons.js";
/**
* Self-organization function/handler. Attempts to re-order given list cell and
* returns cell containing original cell's value after re-ordering. E.g. in
* transpose strategy the original cell's value will now be in predecessor.
*/
export type SOFn<T> = Fn2<SOL<T>, ConsCell<T>, ConsCell<T>>;
/**
* Self-organizing version of {@link DCons} using given re-ordering function.
*
* @remarks
* The list will only be re-ordered upon execution of:
*
* - `nth()`
* - `setNth()`
* - `setTail()`
* - `find()`
* - `findWith()`
*
* Reference:
* https://en.wikipedia.org/wiki/Self-organizing_list
*/
export declare class SOL<T> extends DCons<T> {
protected _reorder: SOFn<T>;
constructor(_reorder: SOFn<T>, src?: Iterable<T>);
copy(): SOL<T>;
empty(): SOL<T>;
find(value: T): ConsCell<T> | undefined;
findWith(fn: Predicate<T>): ConsCell<T> | undefined;
nth(n: number, notFound?: T): T | undefined;
setNth(n: number, v: T): import("@thi.ng/api").Maybe<ConsCell<T>>;
setTail(value: T): ConsCell<T>;
}
/**
* Creates self-organizing list using Move-To-Front strategy.
*
* @remarks
* Reference:
* https://en.wikipedia.org/wiki/Self-organizing_list#Move_to_front_method_(MTF)
*/
export declare const defMTF: <T>(src?: Iterable<T>) => SOL<T>;
/**
* Created self-organizing list using Swap-With-Neighbor (transpose) strategy.
*
* @remarks
* Reference:
* https://en.wikipedia.org/wiki/Self-organizing_list#Transpose_method
*/
export declare const defTranspose: <T>(src?: Iterable<T>) => SOL<T>;
//# sourceMappingURL=sol.d.ts.map