import { GenericCallback } from "../models.mjs"; //#region src/function/memoize.d.ts /** * A _Memoized_ function instance, caching and retrieving results based on the its parameters _(or a custom cache key)_ */ declare class Memoized { #private; /** * Maximum cache size * * @returns Maximum cache size _(or `Number.NaN` if the instance has been destroyed)_ */ get maximum(): number; /** * Current cache size * * @returns Current cache size _(or `Number.NaN` if the instance has been destroyed)_ */ get size(): number; constructor(callback: Callback, options: Options); /** * Clear the cache */ clear(): void; /** * Delete a result from the cache * * @param key Key to delete * @returns `true` if the key existed and was removed, otherwise `false` */ delete(key: unknown): boolean; /** * Destroy the instance * * _(When a Memoized instance is destroyed, its cache and callback are removed, and calls to `run` will throw an error)_ */ destroy(): void; /** * Get a result from the cache * * @param key Key to get * @returns Cached result or `undefined` if it does not exist */ get(key: unknown): ReturnType | undefined; /** * Does the result exist? * * @param key Key to check * @returns `true` if the result exists, otherwise `false` */ has(key: unknown): boolean; /** * Run the callback with the provided parameters * * @param parameters Parameters to pass to the callback * @returns Cached or computed _(then cached)_ result */ run(...parameters: Parameters): ReturnType; } /** * Options for a _Memoized_ function */ type MemoizedOptions = { /** * Callback for getting a cache key for the provided parameters */ cacheKey?: (...parameters: Parameters) => unknown; /** * Size of the cache */ cacheSize?: number; }; type Options = { cacheKey?: GenericCallback; cacheSize: number; }; /** * Memoize a function, caching and retrieving results based on the first parameter * * @param callback Callback to memoize * @param options Memoization options * @returns _Memoized_ instance */ declare function memoize(callback: Callback, options?: MemoizedOptions): Memoized; //#endregion export { type Memoized, type MemoizedOptions, memoize };