@tanstack/db 0.0.29 → 0.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/collection.cjs +6 -6
- package/dist/cjs/collection.cjs.map +1 -1
- package/dist/cjs/collection.d.cts +4 -4
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/indexes/auto-index.cjs +2 -2
- package/dist/cjs/indexes/auto-index.cjs.map +1 -1
- package/dist/cjs/indexes/{ordered-index.cjs → btree-index.cjs} +27 -63
- package/dist/cjs/indexes/btree-index.cjs.map +1 -0
- package/dist/{esm/indexes/ordered-index.d.ts → cjs/indexes/btree-index.d.cts} +6 -4
- package/dist/cjs/utils/btree.cjs +677 -0
- package/dist/cjs/utils/btree.cjs.map +1 -0
- package/dist/cjs/utils/btree.d.cts +197 -0
- package/dist/esm/collection.d.ts +4 -4
- package/dist/esm/collection.js +6 -6
- package/dist/esm/collection.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/indexes/auto-index.js +2 -2
- package/dist/esm/indexes/auto-index.js.map +1 -1
- package/dist/{cjs/indexes/ordered-index.d.cts → esm/indexes/btree-index.d.ts} +6 -4
- package/dist/esm/indexes/{ordered-index.js → btree-index.js} +27 -63
- package/dist/esm/indexes/btree-index.js.map +1 -0
- package/dist/esm/utils/btree.d.ts +197 -0
- package/dist/esm/utils/btree.js +677 -0
- package/dist/esm/utils/btree.js.map +1 -0
- package/package.json +1 -1
- package/src/collection.ts +9 -11
- package/src/index.ts +1 -1
- package/src/indexes/auto-index.ts +2 -2
- package/src/indexes/{ordered-index.ts → btree-index.ts} +42 -84
- package/src/utils/btree.ts +1010 -0
- package/dist/cjs/indexes/ordered-index.cjs.map +0 -1
- package/dist/cjs/utils/array-utils.cjs +0 -18
- package/dist/cjs/utils/array-utils.cjs.map +0 -1
- package/dist/esm/indexes/ordered-index.js.map +0 -1
- package/dist/esm/utils/array-utils.js +0 -18
- package/dist/esm/utils/array-utils.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
3
|
+
const btreeIndex = require("./btree-index.cjs");
|
|
4
4
|
function ensureIndexForExpression(expression, collection) {
|
|
5
5
|
if (collection.config.autoIndex !== `eager`) {
|
|
6
6
|
return;
|
|
@@ -19,7 +19,7 @@ function ensureIndexForExpression(expression, collection) {
|
|
|
19
19
|
try {
|
|
20
20
|
collection.createIndex((row) => row[fieldName], {
|
|
21
21
|
name: `auto_${fieldName}`,
|
|
22
|
-
indexType:
|
|
22
|
+
indexType: btreeIndex.BTreeIndex
|
|
23
23
|
});
|
|
24
24
|
} catch (error) {
|
|
25
25
|
console.warn(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-index.cjs","sources":["../../../src/indexes/auto-index.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"auto-index.cjs","sources":["../../../src/indexes/auto-index.ts"],"sourcesContent":["import { BTreeIndex } from \"./btree-index\"\nimport type { BasicExpression } from \"../query/ir\"\nimport type { CollectionImpl } from \"../collection\"\n\nexport interface AutoIndexConfig {\n autoIndex?: `off` | `eager`\n}\n\n/**\n * Analyzes a where expression and creates indexes for all simple operations on single fields\n */\nexport function ensureIndexForExpression<\n T extends Record<string, any>,\n TKey extends string | number,\n>(\n expression: BasicExpression,\n collection: CollectionImpl<T, TKey, any, any, any>\n): void {\n // Only proceed if auto-indexing is enabled\n if (collection.config.autoIndex !== `eager`) {\n return\n }\n\n // Don't auto-index during sync operations\n if (\n collection.status === `loading` ||\n collection.status === `initialCommit`\n ) {\n return\n }\n\n // Extract all indexable expressions and create indexes for them\n const indexableExpressions = extractIndexableExpressions(expression)\n\n for (const { fieldName, fieldPath } of indexableExpressions) {\n // Check if we already have an index for this field\n const existingIndex = Array.from(collection.indexes.values()).find(\n (index) => index.matchesField(fieldPath)\n )\n\n if (existingIndex) {\n continue // Index already exists\n }\n\n // Create a new index for this field using the collection's createIndex method\n try {\n collection.createIndex((row) => (row as any)[fieldName], {\n name: `auto_${fieldName}`,\n indexType: BTreeIndex,\n })\n } catch (error) {\n console.warn(\n `Failed to create auto-index for field \"${fieldName}\":`,\n error\n )\n }\n }\n}\n\n/**\n * Extracts all indexable expressions from a where expression\n */\nfunction extractIndexableExpressions(\n expression: BasicExpression\n): Array<{ fieldName: string; fieldPath: Array<string> }> {\n const results: Array<{ fieldName: string; fieldPath: Array<string> }> = []\n\n function extractFromExpression(expr: BasicExpression): void {\n if (expr.type !== `func`) {\n return\n }\n\n const func = expr as any\n\n // Handle 'and' expressions by recursively processing all arguments\n if (func.name === `and`) {\n for (const arg of func.args) {\n extractFromExpression(arg)\n }\n return\n }\n\n // Check if this is a supported operation\n const supportedOperations = [`eq`, `gt`, `gte`, `lt`, `lte`, `in`]\n if (!supportedOperations.includes(func.name)) {\n return\n }\n\n // Check if the first argument is a property reference (single field)\n if (func.args.length < 1 || func.args[0].type !== `ref`) {\n return\n }\n\n const fieldRef = func.args[0]\n const fieldPath = fieldRef.path\n\n // Skip if it's not a simple field (e.g., nested properties or array access)\n if (fieldPath.length !== 1) {\n return\n }\n\n const fieldName = fieldPath[0]\n results.push({ fieldName, fieldPath })\n }\n\n extractFromExpression(expression)\n return results\n}\n"],"names":["BTreeIndex"],"mappings":";;;AAWO,SAAS,yBAId,YACA,YACM;AAEN,MAAI,WAAW,OAAO,cAAc,SAAS;AAC3C;AAAA,EACF;AAGA,MACE,WAAW,WAAW,aACtB,WAAW,WAAW,iBACtB;AACA;AAAA,EACF;AAGA,QAAM,uBAAuB,4BAA4B,UAAU;AAEnE,aAAW,EAAE,WAAW,UAAA,KAAe,sBAAsB;AAE3D,UAAM,gBAAgB,MAAM,KAAK,WAAW,QAAQ,OAAA,CAAQ,EAAE;AAAA,MAC5D,CAAC,UAAU,MAAM,aAAa,SAAS;AAAA,IAAA;AAGzC,QAAI,eAAe;AACjB;AAAA,IACF;AAGA,QAAI;AACF,iBAAW,YAAY,CAAC,QAAS,IAAY,SAAS,GAAG;AAAA,QACvD,MAAM,QAAQ,SAAS;AAAA,QACvB,WAAWA,WAAAA;AAAAA,MAAA,CACZ;AAAA,IACH,SAAS,OAAO;AACd,cAAQ;AAAA,QACN,0CAA0C,SAAS;AAAA,QACnD;AAAA,MAAA;AAAA,IAEJ;AAAA,EACF;AACF;AAKA,SAAS,4BACP,YACwD;AACxD,QAAM,UAAkE,CAAA;AAExE,WAAS,sBAAsB,MAA6B;AAC1D,QAAI,KAAK,SAAS,QAAQ;AACxB;AAAA,IACF;AAEA,UAAM,OAAO;AAGb,QAAI,KAAK,SAAS,OAAO;AACvB,iBAAW,OAAO,KAAK,MAAM;AAC3B,8BAAsB,GAAG;AAAA,MAC3B;AACA;AAAA,IACF;AAGA,UAAM,sBAAsB,CAAC,MAAM,MAAM,OAAO,MAAM,OAAO,IAAI;AACjE,QAAI,CAAC,oBAAoB,SAAS,KAAK,IAAI,GAAG;AAC5C;AAAA,IACF;AAGA,QAAI,KAAK,KAAK,SAAS,KAAK,KAAK,KAAK,CAAC,EAAE,SAAS,OAAO;AACvD;AAAA,IACF;AAEA,UAAM,WAAW,KAAK,KAAK,CAAC;AAC5B,UAAM,YAAY,SAAS;AAG3B,QAAI,UAAU,WAAW,GAAG;AAC1B;AAAA,IACF;AAEA,UAAM,YAAY,UAAU,CAAC;AAC7B,YAAQ,KAAK,EAAE,WAAW,UAAA,CAAW;AAAA,EACvC;AAEA,wBAAsB,UAAU;AAChC,SAAO;AACT;;"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const comparison = require("../utils/comparison.cjs");
|
|
4
|
-
const
|
|
4
|
+
const btree = require("../utils/btree.cjs");
|
|
5
5
|
const baseIndex = require("./base-index.cjs");
|
|
6
|
-
class
|
|
7
|
-
constructor() {
|
|
8
|
-
super(
|
|
6
|
+
class BTreeIndex extends baseIndex.BaseIndex {
|
|
7
|
+
constructor(id, expression, name, options) {
|
|
8
|
+
super(id, expression, name, options);
|
|
9
9
|
this.supportedOperations = /* @__PURE__ */ new Set([
|
|
10
10
|
`eq`,
|
|
11
11
|
`gt`,
|
|
@@ -14,13 +14,13 @@ class OrderedIndex extends baseIndex.BaseIndex {
|
|
|
14
14
|
`lte`,
|
|
15
15
|
`in`
|
|
16
16
|
]);
|
|
17
|
-
this.orderedEntries = [];
|
|
18
17
|
this.valueMap = /* @__PURE__ */ new Map();
|
|
19
18
|
this.indexedKeys = /* @__PURE__ */ new Set();
|
|
20
19
|
this.compareFn = comparison.ascComparator;
|
|
21
|
-
}
|
|
22
|
-
initialize(options) {
|
|
23
20
|
this.compareFn = (options == null ? void 0 : options.compareFn) ?? comparison.ascComparator;
|
|
21
|
+
this.orderedEntries = new btree.BTree(this.compareFn);
|
|
22
|
+
}
|
|
23
|
+
initialize(_options) {
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Adds a value to the index
|
|
@@ -39,12 +39,7 @@ class OrderedIndex extends baseIndex.BaseIndex {
|
|
|
39
39
|
} else {
|
|
40
40
|
const keySet = /* @__PURE__ */ new Set([key]);
|
|
41
41
|
this.valueMap.set(indexedValue, keySet);
|
|
42
|
-
|
|
43
|
-
this.orderedEntries,
|
|
44
|
-
indexedValue,
|
|
45
|
-
this.compareFn
|
|
46
|
-
);
|
|
47
|
-
this.orderedEntries.splice(insertIndex, 0, [indexedValue, keySet]);
|
|
42
|
+
this.orderedEntries.set(indexedValue, void 0);
|
|
48
43
|
}
|
|
49
44
|
this.indexedKeys.add(key);
|
|
50
45
|
this.updateTimestamp();
|
|
@@ -68,12 +63,7 @@ class OrderedIndex extends baseIndex.BaseIndex {
|
|
|
68
63
|
keySet.delete(key);
|
|
69
64
|
if (keySet.size === 0) {
|
|
70
65
|
this.valueMap.delete(indexedValue);
|
|
71
|
-
|
|
72
|
-
([value]) => this.compareFn(value, indexedValue) === 0
|
|
73
|
-
);
|
|
74
|
-
if (index !== -1) {
|
|
75
|
-
this.orderedEntries.splice(index, 1);
|
|
76
|
-
}
|
|
66
|
+
this.orderedEntries.delete(indexedValue);
|
|
77
67
|
}
|
|
78
68
|
}
|
|
79
69
|
this.indexedKeys.delete(key);
|
|
@@ -99,7 +89,7 @@ class OrderedIndex extends baseIndex.BaseIndex {
|
|
|
99
89
|
* Clears all data from the index
|
|
100
90
|
*/
|
|
101
91
|
clear() {
|
|
102
|
-
this.orderedEntries
|
|
92
|
+
this.orderedEntries.clear();
|
|
103
93
|
this.valueMap.clear();
|
|
104
94
|
this.indexedKeys.clear();
|
|
105
95
|
this.updateTimestamp();
|
|
@@ -130,7 +120,7 @@ class OrderedIndex extends baseIndex.BaseIndex {
|
|
|
130
120
|
result = this.inArrayLookup(value);
|
|
131
121
|
break;
|
|
132
122
|
default:
|
|
133
|
-
throw new Error(`Operation ${operation} not supported by
|
|
123
|
+
throw new Error(`Operation ${operation} not supported by BTreeIndex`);
|
|
134
124
|
}
|
|
135
125
|
this.trackLookup(startTime);
|
|
136
126
|
return result;
|
|
@@ -155,48 +145,22 @@ class OrderedIndex extends baseIndex.BaseIndex {
|
|
|
155
145
|
rangeQuery(options = {}) {
|
|
156
146
|
const { from, to, fromInclusive = true, toInclusive = true } = options;
|
|
157
147
|
const result = /* @__PURE__ */ new Set();
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
from
|
|
166
|
-
|
|
167
|
-
);
|
|
168
|
-
if (fromInclusive) {
|
|
169
|
-
startIndex = fromInsertIndex;
|
|
170
|
-
} else {
|
|
171
|
-
startIndex = fromInsertIndex;
|
|
172
|
-
if (startIndex < this.orderedEntries.length && this.compareFn(this.orderedEntries[startIndex][0], from) === 0) {
|
|
173
|
-
startIndex++;
|
|
148
|
+
const fromKey = from ?? this.orderedEntries.minKey();
|
|
149
|
+
const toKey = to ?? this.orderedEntries.maxKey();
|
|
150
|
+
this.orderedEntries.forRange(
|
|
151
|
+
fromKey,
|
|
152
|
+
toKey,
|
|
153
|
+
toInclusive,
|
|
154
|
+
(indexedValue, _) => {
|
|
155
|
+
if (!fromInclusive && this.compareFn(indexedValue, from) === 0) {
|
|
156
|
+
return;
|
|
174
157
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (to !== void 0) {
|
|
179
|
-
const toInsertIndex = arrayUtils.findInsertPosition(
|
|
180
|
-
this.orderedEntries,
|
|
181
|
-
to,
|
|
182
|
-
this.compareFn
|
|
183
|
-
);
|
|
184
|
-
if (toInclusive) {
|
|
185
|
-
endIndex = toInsertIndex;
|
|
186
|
-
if (toInsertIndex < this.orderedEntries.length && this.compareFn(this.orderedEntries[toInsertIndex][0], to) === 0) {
|
|
187
|
-
endIndex = toInsertIndex + 1;
|
|
158
|
+
const keys = this.valueMap.get(indexedValue);
|
|
159
|
+
if (keys) {
|
|
160
|
+
keys.forEach((key) => result.add(key));
|
|
188
161
|
}
|
|
189
|
-
} else {
|
|
190
|
-
endIndex = toInsertIndex;
|
|
191
162
|
}
|
|
192
|
-
|
|
193
|
-
if (startIndex >= endIndex) {
|
|
194
|
-
return result;
|
|
195
|
-
}
|
|
196
|
-
for (let i = startIndex; i < endIndex; i++) {
|
|
197
|
-
const keys = this.orderedEntries[i][1];
|
|
198
|
-
keys.forEach((key) => result.add(key));
|
|
199
|
-
}
|
|
163
|
+
);
|
|
200
164
|
return result;
|
|
201
165
|
}
|
|
202
166
|
/**
|
|
@@ -217,11 +181,11 @@ class OrderedIndex extends baseIndex.BaseIndex {
|
|
|
217
181
|
return this.indexedKeys;
|
|
218
182
|
}
|
|
219
183
|
get orderedEntriesArray() {
|
|
220
|
-
return this.orderedEntries;
|
|
184
|
+
return this.orderedEntries.keysArray().map((key) => [key, this.valueMap.get(key) ?? /* @__PURE__ */ new Set()]);
|
|
221
185
|
}
|
|
222
186
|
get valueMapData() {
|
|
223
187
|
return this.valueMap;
|
|
224
188
|
}
|
|
225
189
|
}
|
|
226
|
-
exports.
|
|
227
|
-
//# sourceMappingURL=
|
|
190
|
+
exports.BTreeIndex = BTreeIndex;
|
|
191
|
+
//# sourceMappingURL=btree-index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"btree-index.cjs","sources":["../../../src/indexes/btree-index.ts"],"sourcesContent":["import { ascComparator } from \"../utils/comparison.js\"\nimport { BTree } from \"../utils/btree.js\"\nimport { BaseIndex } from \"./base-index.js\"\nimport type { BasicExpression } from \"../query/ir.js\"\nimport type { IndexOperation } from \"./base-index.js\"\n\n/**\n * Options for Ordered index\n */\nexport interface BTreeIndexOptions {\n compareFn?: (a: any, b: any) => number\n}\n\n/**\n * Options for range queries\n */\nexport interface RangeQueryOptions {\n from?: any\n to?: any\n fromInclusive?: boolean\n toInclusive?: boolean\n}\n\n/**\n * B+Tree index for sorted data with range queries\n * This maintains items in sorted order and provides efficient range operations\n */\nexport class BTreeIndex<\n TKey extends string | number = string | number,\n> extends BaseIndex<TKey> {\n public readonly supportedOperations = new Set<IndexOperation>([\n `eq`,\n `gt`,\n `gte`,\n `lt`,\n `lte`,\n `in`,\n ])\n\n // Internal data structures - private to hide implementation details\n // The `orderedEntries` B+ tree is used for efficient range queries\n // The `valueMap` is used for O(1) lookups of PKs by indexed value\n private orderedEntries: BTree<any, undefined> // we don't associate values with the keys of the B+ tree (the keys are indexed values)\n private valueMap = new Map<any, Set<TKey>>() // instead we store a mapping of indexed values to a set of PKs\n private indexedKeys = new Set<TKey>()\n private compareFn: (a: any, b: any) => number = ascComparator\n\n constructor(\n id: number,\n expression: BasicExpression,\n name?: string,\n options?: any\n ) {\n super(id, expression, name, options)\n this.compareFn = options?.compareFn ?? ascComparator\n this.orderedEntries = new BTree(this.compareFn)\n }\n\n protected initialize(_options?: BTreeIndexOptions): void {}\n\n /**\n * Adds a value to the index\n */\n add(key: TKey, item: any): void {\n let indexedValue: any\n try {\n indexedValue = this.evaluateIndexExpression(item)\n } catch (error) {\n throw new Error(\n `Failed to evaluate index expression for key ${key}: ${error}`\n )\n }\n\n // Check if this value already exists\n if (this.valueMap.has(indexedValue)) {\n // Add to existing set\n this.valueMap.get(indexedValue)!.add(key)\n } else {\n // Create new set for this value\n const keySet = new Set<TKey>([key])\n this.valueMap.set(indexedValue, keySet)\n this.orderedEntries.set(indexedValue, undefined)\n }\n\n this.indexedKeys.add(key)\n this.updateTimestamp()\n }\n\n /**\n * Removes a value from the index\n */\n remove(key: TKey, item: any): void {\n let indexedValue: any\n try {\n indexedValue = this.evaluateIndexExpression(item)\n } catch (error) {\n console.warn(\n `Failed to evaluate index expression for key ${key} during removal:`,\n error\n )\n return\n }\n\n if (this.valueMap.has(indexedValue)) {\n const keySet = this.valueMap.get(indexedValue)!\n keySet.delete(key)\n\n // If set is now empty, remove the entry entirely\n if (keySet.size === 0) {\n this.valueMap.delete(indexedValue)\n\n // Remove from ordered entries\n this.orderedEntries.delete(indexedValue)\n }\n }\n\n this.indexedKeys.delete(key)\n this.updateTimestamp()\n }\n\n /**\n * Updates a value in the index\n */\n update(key: TKey, oldItem: any, newItem: any): void {\n this.remove(key, oldItem)\n this.add(key, newItem)\n }\n\n /**\n * Builds the index from a collection of entries\n */\n build(entries: Iterable<[TKey, any]>): void {\n this.clear()\n\n for (const [key, item] of entries) {\n this.add(key, item)\n }\n }\n\n /**\n * Clears all data from the index\n */\n clear(): void {\n this.orderedEntries.clear()\n this.valueMap.clear()\n this.indexedKeys.clear()\n this.updateTimestamp()\n }\n\n /**\n * Performs a lookup operation\n */\n lookup(operation: IndexOperation, value: any): Set<TKey> {\n const startTime = performance.now()\n\n let result: Set<TKey>\n\n switch (operation) {\n case `eq`:\n result = this.equalityLookup(value)\n break\n case `gt`:\n result = this.rangeQuery({ from: value, fromInclusive: false })\n break\n case `gte`:\n result = this.rangeQuery({ from: value, fromInclusive: true })\n break\n case `lt`:\n result = this.rangeQuery({ to: value, toInclusive: false })\n break\n case `lte`:\n result = this.rangeQuery({ to: value, toInclusive: true })\n break\n case `in`:\n result = this.inArrayLookup(value)\n break\n default:\n throw new Error(`Operation ${operation} not supported by BTreeIndex`)\n }\n\n this.trackLookup(startTime)\n return result\n }\n\n /**\n * Gets the number of indexed keys\n */\n get keyCount(): number {\n return this.indexedKeys.size\n }\n\n // Public methods for backward compatibility (used by tests)\n\n /**\n * Performs an equality lookup\n */\n equalityLookup(value: any): Set<TKey> {\n return new Set(this.valueMap.get(value) ?? [])\n }\n\n /**\n * Performs a range query with options\n * This is more efficient for compound queries like \"WHERE a > 5 AND a < 10\"\n */\n rangeQuery(options: RangeQueryOptions = {}): Set<TKey> {\n const { from, to, fromInclusive = true, toInclusive = true } = options\n const result = new Set<TKey>()\n\n const fromKey = from ?? this.orderedEntries.minKey()\n const toKey = to ?? this.orderedEntries.maxKey()\n\n this.orderedEntries.forRange(\n fromKey,\n toKey,\n toInclusive,\n (indexedValue, _) => {\n if (!fromInclusive && this.compareFn(indexedValue, from) === 0) {\n // the B+ tree `forRange` method does not support exclusive lower bounds\n // so we need to exclude it manually\n return\n }\n\n const keys = this.valueMap.get(indexedValue)\n if (keys) {\n keys.forEach((key) => result.add(key))\n }\n }\n )\n\n return result\n }\n\n /**\n * Performs an IN array lookup\n */\n inArrayLookup(values: Array<any>): Set<TKey> {\n const result = new Set<TKey>()\n\n for (const value of values) {\n const keys = this.valueMap.get(value)\n if (keys) {\n keys.forEach((key) => result.add(key))\n }\n }\n\n return result\n }\n\n // Getter methods for testing compatibility\n get indexedKeysSet(): Set<TKey> {\n return this.indexedKeys\n }\n\n get orderedEntriesArray(): Array<[any, Set<TKey>]> {\n return this.orderedEntries\n .keysArray()\n .map((key) => [key, this.valueMap.get(key) ?? new Set()])\n }\n\n get valueMapData(): Map<any, Set<TKey>> {\n return this.valueMap\n }\n}\n"],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eACT,UAAA,EACA,IAAI,CAAC,QAAQ,CAAC,KAAK,KAAK,SAAS,IAAI,GAAG,KAAK,oBAAI,IAAA,CAAK,CAAC;AAAA,EAC5D;AAAA,EAEA,IAAI,eAAoC;AACtC,WAAO,KAAK;AAAA,EACd;AACF;;"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { BaseIndex, IndexOperation } from './base-index.js';
|
|
2
|
+
import { BasicExpression } from '../query/ir.js';
|
|
2
3
|
/**
|
|
3
4
|
* Options for Ordered index
|
|
4
5
|
*/
|
|
5
|
-
export interface
|
|
6
|
+
export interface BTreeIndexOptions {
|
|
6
7
|
compareFn?: (a: any, b: any) => number;
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
@@ -15,16 +16,17 @@ export interface RangeQueryOptions {
|
|
|
15
16
|
toInclusive?: boolean;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
|
-
*
|
|
19
|
+
* B+Tree index for sorted data with range queries
|
|
19
20
|
* This maintains items in sorted order and provides efficient range operations
|
|
20
21
|
*/
|
|
21
|
-
export declare class
|
|
22
|
+
export declare class BTreeIndex<TKey extends string | number = string | number> extends BaseIndex<TKey> {
|
|
22
23
|
readonly supportedOperations: Set<"eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "ilike">;
|
|
23
24
|
private orderedEntries;
|
|
24
25
|
private valueMap;
|
|
25
26
|
private indexedKeys;
|
|
26
27
|
private compareFn;
|
|
27
|
-
|
|
28
|
+
constructor(id: number, expression: BasicExpression, name?: string, options?: any);
|
|
29
|
+
protected initialize(_options?: BTreeIndexOptions): void;
|
|
28
30
|
/**
|
|
29
31
|
* Adds a value to the index
|
|
30
32
|
*/
|