import { type IndexNumber, type IndexRange, type ReadIndexRangeFunction } from '../value/indexed'; import { type Maybe } from '../value/maybe.type'; import { type ArrayFindDecisionFunction } from './array.find'; /** * Creates an IndexRange for the input array, spanning from index 0 to the array's length. * * @param array - Source whose length defines the maxIndex boundary. * @returns Range pair spanning index 0 through the array's length. */ export declare function indexRangeForArray(array: T[]): IndexRange; /** * Finds a value in the array using the provided decision function, then returns the value at the next index. * * @param array - Source to scan; nullish input short-circuits with undefined. * @param find - Predicate that locates the anchor element to step from. * @param wrapAround - When true, stepping past the end resumes from index 0. * @param steps - Forward step count from the matched element; defaults to 1. * @returns Element after the anchor, or undefined when the anchor or its step target falls outside the array. */ export declare function findNext(array: Maybe, find: ArrayFindDecisionFunction, wrapAround?: boolean, steps?: number): Maybe; /** * Returns the next index of an element in the input array based on the input index. * * Indexes less than 0 are considered to not exist. * * When wrapAround is true, indexes that are larger than the entire array will be used to find an index that is that many steps into the array. * For instance, an index of 5 on an array of length 3 will return the index 1. * * @param array - Source whose bounds anchor the step computation. * @param index - Current position from which to advance. * @param wrapAround - When true, stepping past the end resumes from index 0. * @param steps - Forward step count from the current index. * @returns Stepped index when `index` is inside the array; otherwise undefined. */ export declare function getArrayNextIndex(array: T[], index: number, wrapAround?: boolean, steps?: number): Maybe; /** * Accessor function that returns a value for the given index if any value's range contains that index. */ export type RangedIndexedValuesArrayAccessor = (index: IndexNumber) => Maybe; /** * Factory function that creates a {@link RangedIndexedValuesArrayAccessor} from an array of values. */ export type RangedIndexedValuesArrayAccessorFactory = (values: T[]) => RangedIndexedValuesArrayAccessor; /** * Creates a factory that produces {@link RangedIndexedValuesArrayAccessor} instances. * * Each accessor maps an index to the value whose range contains that index, or undefined if no range matches. * * @param readIndexRange - Function that reads the index range from each value. * @returns A factory that creates ranged accessors from arrays of values. * * @dbxUtil * @dbxUtilCategory array * @dbxUtilKind factory * @dbxUtilTags array, indexed, range, accessor, factory, lookup * @dbxUtilRelated indexed-values-array-accessor-factory, ranged-indexed-values-array-accessor-info-factory * * @__NO_SIDE_EFFECTS__ */ export declare function rangedIndexedValuesArrayAccessorFactory(readIndexRange: ReadIndexRangeFunction): RangedIndexedValuesArrayAccessorFactory; /** * Accessor function that returns a value for the given index. Always returns a value by falling back to the nearest neighbor. */ export type IndexedValuesArrayAccessor = (index: IndexNumber) => T; /** * Factory function that creates an {@link IndexedValuesArrayAccessor} from an array of values. */ export type IndexedValuesArrayAccessorFactory = (values: T[]) => IndexedValuesArrayAccessor; /** * Creates a factory that produces {@link IndexedValuesArrayAccessor} instances. * * Each accessor maps an index to the matching value, falling back to the previous value, then the next value. * This guarantees a value is always returned. * * @param readIndexRange - Function that reads the index range from each value. * @returns A factory that creates indexed accessors from arrays of values. * @throws {Error} If the provided values array is empty. * * @dbxUtil * @dbxUtilCategory array * @dbxUtilKind factory * @dbxUtilTags array, indexed, range, accessor, factory, fallback * @dbxUtilRelated ranged-indexed-values-array-accessor-factory, ranged-indexed-values-array-accessor-info-factory * * @__NO_SIDE_EFFECTS__ */ export declare function indexedValuesArrayAccessorFactory(readIndexRange: ReadIndexRangeFunction): IndexedValuesArrayAccessorFactory; /** * Contains the match result for a ranged index lookup, including the matched value and its neighbors. */ export interface RangedIndexValuesArrayAccessorInfo { /** * The value from the range immediately before the matched or queried range. */ readonly prev?: Maybe; /** * The value whose range contains the queried index, or undefined if no range matched. */ readonly match?: Maybe; /** * The value from the range immediately after the matched or queried range. */ readonly next?: Maybe; } /** * Accessor function that returns detailed match info (match, previous, and next values) for the given index. */ export type RangedIndexedValuesArrayInfoAccessor = (index: IndexNumber) => RangedIndexValuesArrayAccessorInfo; /** * Factory function that creates a {@link RangedIndexedValuesArrayInfoAccessor} from an array of values. */ export type RangedIndexedValuesArrayInfoAccessorFactory = (values: T[]) => RangedIndexedValuesArrayInfoAccessor; /** * Configuration for {@link rangedIndexedValuesArrayAccessorInfoFactory}. */ export interface RangedIndexedValuesArrayInfoAccessorFactoryConfig { /** * Reads the index range from a value. The IndexRange is treated as exclusive. */ readonly readIndexRange: ReadIndexRangeFunction; } /** * Creates a factory that produces {@link RangedIndexedValuesArrayInfoAccessor} instances. * * Each accessor sorts the values by their index ranges in ascending order, then for a given index * returns the matching value along with its previous and next neighbors. * * @param config - Configuration containing the index range reader function. * @returns A factory that creates ranged info accessors from arrays of values. * * @dbxUtil * @dbxUtilCategory array * @dbxUtilKind factory * @dbxUtilTags array, indexed, range, accessor, info, factory, neighbors * @dbxUtilRelated ranged-indexed-values-array-accessor-factory, indexed-values-array-accessor-factory * * @__NO_SIDE_EFFECTS__ */ export declare function rangedIndexedValuesArrayAccessorInfoFactory(config: RangedIndexedValuesArrayInfoAccessorFactoryConfig): RangedIndexedValuesArrayInfoAccessorFactory;