import { comparisonFunctions } from '../query/builder/functions.js'; import { RangeQueryOptions } from './btree-index.js'; import { CompareOptions } from '../query/builder/types.js'; import { BasicExpression, OrderByDirection } from '../query/ir.js'; /** * Operations that indexes can support, imported from available comparison functions */ export declare const IndexOperation: readonly ["eq", "gt", "gte", "lt", "lte", "in", "like", "ilike"]; /** * Type for index operation values */ export type IndexOperation = (typeof comparisonFunctions)[number]; /** * Statistics about index usage and performance */ export interface IndexStats { readonly entryCount: number; readonly lookupCount: number; readonly averageLookupTime: number; readonly lastUpdated: Date; } export interface IndexInterface { add: (key: TKey, item: any) => void; remove: (key: TKey, item: any) => void; update: (key: TKey, oldItem: any, newItem: any) => void; build: (entries: Iterable<[TKey, any]>) => void; clear: () => void; lookup: (operation: IndexOperation, value: any) => Set; equalityLookup: (value: any) => Set; inArrayLookup: (values: Array) => Set; rangeQuery: (options: RangeQueryOptions) => Set; rangeQueryReversed: (options: RangeQueryOptions) => Set; take: (n: number, from: TKey, filterFn?: (key: TKey) => boolean) => Array; takeFromStart: (n: number, filterFn?: (key: TKey) => boolean) => Array; takeReversed: (n: number, from: TKey, filterFn?: (key: TKey) => boolean) => Array; takeReversedFromEnd: (n: number, filterFn?: (key: TKey) => boolean) => Array; get keyCount(): number; get orderedEntriesArray(): Array<[any, Set]>; get orderedEntriesArrayReversed(): Array<[any, Set]>; get indexedKeysSet(): Set; get valueMapData(): Map>; supports: (operation: IndexOperation) => boolean; matchesField: (fieldPath: Array) => boolean; matchesCompareOptions: (compareOptions: CompareOptions) => boolean; matchesDirection: (direction: OrderByDirection) => boolean; getStats: () => IndexStats; } /** * Base abstract class that all index types extend */ export declare abstract class BaseIndex implements IndexInterface { readonly id: number; readonly name?: string; readonly expression: BasicExpression; abstract readonly supportedOperations: Set; protected lookupCount: number; protected totalLookupTime: number; protected lastUpdated: Date; protected compareOptions: CompareOptions; constructor(id: number, expression: BasicExpression, name?: string, options?: any); abstract add(key: TKey, item: any): void; abstract remove(key: TKey, item: any): void; abstract update(key: TKey, oldItem: any, newItem: any): void; abstract build(entries: Iterable<[TKey, any]>): void; abstract clear(): void; abstract lookup(operation: IndexOperation, value: any): Set; abstract take(n: number, from: TKey, filterFn?: (key: TKey) => boolean): Array; abstract takeFromStart(n: number, filterFn?: (key: TKey) => boolean): Array; abstract takeReversed(n: number, from: TKey, filterFn?: (key: TKey) => boolean): Array; abstract takeReversedFromEnd(n: number, filterFn?: (key: TKey) => boolean): Array; abstract get keyCount(): number; abstract equalityLookup(value: any): Set; abstract inArrayLookup(values: Array): Set; abstract rangeQuery(options: RangeQueryOptions): Set; abstract rangeQueryReversed(options: RangeQueryOptions): Set; abstract get orderedEntriesArray(): Array<[any, Set]>; abstract get orderedEntriesArrayReversed(): Array<[any, Set]>; abstract get indexedKeysSet(): Set; abstract get valueMapData(): Map>; supports(operation: IndexOperation): boolean; matchesField(fieldPath: Array): boolean; /** * Checks if the compare options match the index's compare options. * The direction is ignored because the index can be reversed if the direction is different. */ matchesCompareOptions(compareOptions: CompareOptions): boolean; /** * Checks if the index matches the provided direction. */ matchesDirection(direction: OrderByDirection): boolean; getStats(): IndexStats; protected abstract initialize(options?: any): void; protected evaluateIndexExpression(item: any): any; protected trackLookup(startTime: number): void; protected updateTimestamp(): void; } /** * Type for index constructor */ export type IndexConstructor = new (id: number, expression: BasicExpression, name?: string, options?: any) => BaseIndex;