@tanstack/db
Version:
A reactive client store for building super fast apps on sync
75 lines (74 loc) • 2.19 kB
text/typescript
import { BaseIndex, IndexOperation } from './base-index.js';
import { BasicExpression } from '../query/ir.js';
/**
* Options for Ordered index
*/
export interface BTreeIndexOptions {
compareFn?: (a: any, b: any) => number;
}
/**
* Options for range queries
*/
export interface RangeQueryOptions {
from?: any;
to?: any;
fromInclusive?: boolean;
toInclusive?: boolean;
}
/**
* B+Tree index for sorted data with range queries
* This maintains items in sorted order and provides efficient range operations
*/
export declare class BTreeIndex<TKey extends string | number = string | number> extends BaseIndex<TKey> {
readonly supportedOperations: Set<"eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "ilike">;
private orderedEntries;
private valueMap;
private indexedKeys;
private compareFn;
constructor(id: number, expression: BasicExpression, name?: string, options?: any);
protected initialize(_options?: BTreeIndexOptions): void;
/**
* Adds a value to the index
*/
add(key: TKey, item: any): void;
/**
* Removes a value from the index
*/
remove(key: TKey, item: any): void;
/**
* Updates a value in the index
*/
update(key: TKey, oldItem: any, newItem: any): void;
/**
* Builds the index from a collection of entries
*/
build(entries: Iterable<[TKey, any]>): void;
/**
* Clears all data from the index
*/
clear(): void;
/**
* Performs a lookup operation
*/
lookup(operation: IndexOperation, value: any): Set<TKey>;
/**
* Gets the number of indexed keys
*/
get keyCount(): number;
/**
* Performs an equality lookup
*/
equalityLookup(value: any): Set<TKey>;
/**
* Performs a range query with options
* This is more efficient for compound queries like "WHERE a > 5 AND a < 10"
*/
rangeQuery(options?: RangeQueryOptions): Set<TKey>;
/**
* Performs an IN array lookup
*/
inArrayLookup(values: Array<any>): Set<TKey>;
get indexedKeysSet(): Set<TKey>;
get orderedEntriesArray(): Array<[any, Set<TKey>]>;
get valueMapData(): Map<any, Set<TKey>>;
}