@devisfuture/mega-collection 2.4.5 → 2.4.7
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/README.md +2 -2
- package/dist/State.d.ts +42 -0
- package/dist/{chunk-BJZg_1dI.mjs → State.mjs} +2 -2
- package/dist/constants.d.ts +5 -0
- package/dist/constants.mjs +4 -0
- package/dist/filter/chain.d.ts +9 -0
- package/dist/filter/chain.mjs +22 -0
- package/dist/filter/constants.d.ts +2 -0
- package/dist/filter/criterion.d.ts +6 -0
- package/dist/filter/criterion.mjs +64 -0
- package/dist/filter/errors.d.ts +7 -0
- package/dist/filter/errors.mjs +17 -0
- package/dist/filter/filter.d.ts +89 -0
- package/dist/filter/filter.mjs +439 -0
- package/dist/filter/index.mjs +2 -891
- package/dist/filter/nested.d.ts +32 -0
- package/dist/filter/nested.mjs +246 -0
- package/dist/filter/types.d.ts +74 -0
- package/dist/filter/utils.d.ts +4 -0
- package/dist/filter/utils.mjs +29 -0
- package/dist/index.mjs +1 -1
- package/dist/indexer.d.ts +41 -0
- package/dist/indexer.mjs +101 -0
- package/dist/internal.d.ts +6 -0
- package/dist/{chunk-C5Zpu_ol.mjs → internal.mjs} +1 -1
- package/dist/merge/chain.d.ts +9 -0
- package/dist/merge/chain.mjs +23 -0
- package/dist/merge/constants.d.ts +6 -0
- package/dist/merge/constants.mjs +8 -0
- package/dist/merge/errors.d.ts +8 -0
- package/dist/merge/errors.mjs +19 -0
- package/dist/merge/index.mjs +1 -1
- package/dist/merge/merge-engines.d.ts +75 -0
- package/dist/{chunk-BURK5sks.mjs → merge/merge-engines.mjs} +35 -108
- package/dist/merge/module-adapters.d.ts +7 -0
- package/dist/merge/module-adapters.mjs +41 -0
- package/dist/merge/types.d.ts +125 -0
- package/dist/search/constants.d.ts +5 -0
- package/dist/search/index.mjs +2 -1010
- package/dist/search/nested.d.ts +41 -0
- package/dist/search/nested.mjs +210 -0
- package/dist/search/ngram.d.ts +23 -0
- package/dist/search/ngram.mjs +96 -0
- package/dist/search/text-search.d.ts +146 -0
- package/dist/search/text-search.mjs +696 -0
- package/dist/search/types.d.ts +93 -0
- package/dist/search/utils.d.ts +4 -0
- package/dist/search/utils.mjs +22 -0
- package/dist/sort/errors.d.ts +5 -0
- package/dist/sort/errors.mjs +11 -0
- package/dist/sort/index.mjs +2 -416
- package/dist/sort/sorter.d.ts +47 -0
- package/dist/sort/sorter.mjs +375 -0
- package/dist/sort/types.d.ts +18 -0
- package/dist/sort/utils.d.ts +17 -0
- package/dist/sort/utils.mjs +38 -0
- package/dist/types.d.ts +73 -0
- package/package.json +11 -34
- /package/dist/filter/{index.d.mts → index.d.ts} +0 -0
- /package/dist/{index.d.mts → index.d.ts} +0 -0
- /package/dist/merge/{index.d.mts → index.d.ts} +0 -0
- /package/dist/search/{index.d.mts → index.d.ts} +0 -0
- /package/dist/sort/{index.d.mts → index.d.ts} +0 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { State as e } from "../State.mjs";
|
|
2
|
+
import { DEFER_SORT_MUTATION_CACHE_UPDATES_KEY as t, MERGE_SHARED_SCOPE as n } from "../constants.mjs";
|
|
3
|
+
import { SortEngineError as r } from "./errors.mjs";
|
|
4
|
+
import { canUseUint32Radix as i, createSortRuntime as a, radixSortUint32 as o } from "./utils.mjs";
|
|
5
|
+
//#region src/sort/sorter.ts
|
|
6
|
+
var s = class {
|
|
7
|
+
constructor(t = {}) {
|
|
8
|
+
if (this.state = t.state ?? new e(t.data ?? []), this.namespace = this.state.createNamespace("sort"), this.state.subscribe((e) => this.handleStateMutation(e)), t.fields?.length) {
|
|
9
|
+
for (let e of t.fields) this.indexedFields.add(e);
|
|
10
|
+
this.dataset.length > 0 && this.rebuildConfiguredIndexes();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
get dataset() {
|
|
14
|
+
return this.state.getOriginData();
|
|
15
|
+
}
|
|
16
|
+
get runtime() {
|
|
17
|
+
return this.state.getOrCreateScopedValue(this.namespace, "runtime", a);
|
|
18
|
+
}
|
|
19
|
+
get cache() {
|
|
20
|
+
return this.runtime.cache;
|
|
21
|
+
}
|
|
22
|
+
get indexedFields() {
|
|
23
|
+
return this.runtime.indexedFields;
|
|
24
|
+
}
|
|
25
|
+
shouldDeferMutationCacheUpdates() {
|
|
26
|
+
return this.state.getScopedValue(n, t) === !0;
|
|
27
|
+
}
|
|
28
|
+
invalidateCachedIndexes() {
|
|
29
|
+
for (let e of this.indexedFields) this.cache.delete(e);
|
|
30
|
+
}
|
|
31
|
+
rebuildConfiguredIndexes() {
|
|
32
|
+
this.cache.clear();
|
|
33
|
+
for (let e of this.indexedFields) this.buildIndexForDataset(e);
|
|
34
|
+
}
|
|
35
|
+
buildIndexForDataset(e) {
|
|
36
|
+
this.dataset.length && this.buildIndexFromData(this.dataset, e);
|
|
37
|
+
}
|
|
38
|
+
buildIndexFromData(e, t) {
|
|
39
|
+
let n = e.length, r = new Uint32Array(n);
|
|
40
|
+
for (let e = 0; e < n; e++) r[e] = e;
|
|
41
|
+
let a = 0;
|
|
42
|
+
for (; a < n && e[a][t] == null;) a++;
|
|
43
|
+
if (a < n && typeof e[a][t] == "number") {
|
|
44
|
+
let a = new Float64Array(n);
|
|
45
|
+
for (let r = 0; r < n; r++) a[r] = e[r][t];
|
|
46
|
+
i(a, n) ? o(r, a, n) : r.sort((e, t) => a[e] - a[t]);
|
|
47
|
+
} else {
|
|
48
|
+
let i = Array(n);
|
|
49
|
+
for (let r = 0; r < n; r++) i[r] = e[r][t];
|
|
50
|
+
r.sort((e, t) => {
|
|
51
|
+
let n = i[e], r = i[t];
|
|
52
|
+
return n < r ? -1 : n > r ? 1 : 0;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
let s = new Uint32Array(n);
|
|
56
|
+
for (let e = 0; e < n; e++) s[r[e]] = e;
|
|
57
|
+
this.cache.set(t, {
|
|
58
|
+
indexes: r,
|
|
59
|
+
reverseIndex: s,
|
|
60
|
+
ascItems: null,
|
|
61
|
+
descItems: null,
|
|
62
|
+
hasDuplicateValues: this.hasDuplicateValuesForIndexes(e, r, t),
|
|
63
|
+
version: this.state.getMutationVersion()
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
clearIndexes() {
|
|
67
|
+
return this.cache.clear(), this;
|
|
68
|
+
}
|
|
69
|
+
clearData() {
|
|
70
|
+
return this.state.clearData(), this;
|
|
71
|
+
}
|
|
72
|
+
data(e) {
|
|
73
|
+
return this.state.data(e), this;
|
|
74
|
+
}
|
|
75
|
+
add(e) {
|
|
76
|
+
return this.state.add(e), this;
|
|
77
|
+
}
|
|
78
|
+
update(e) {
|
|
79
|
+
return this.state.update(e), this;
|
|
80
|
+
}
|
|
81
|
+
applyAddedItems(e, t) {
|
|
82
|
+
if (t === 0) return this;
|
|
83
|
+
if (this.shouldDeferMutationCacheUpdates()) return this.invalidateCachedIndexes(), this;
|
|
84
|
+
for (let n of this.indexedFields) {
|
|
85
|
+
let r = this.cache.get(n);
|
|
86
|
+
if (r) {
|
|
87
|
+
if (!this.shouldMaintainIncrementally(r)) {
|
|
88
|
+
this.cache.delete(n);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
this.updateCachedIndexForAddedItems(n, e, t);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
getOriginData() {
|
|
97
|
+
return this.state.getOriginData();
|
|
98
|
+
}
|
|
99
|
+
handleStateMutation(e) {
|
|
100
|
+
switch (e.type) {
|
|
101
|
+
case "add":
|
|
102
|
+
this.applyAddedItems(e.startIndex, e.items.length);
|
|
103
|
+
return;
|
|
104
|
+
case "update":
|
|
105
|
+
this.applyUpdatedItem(e.index, e.previousItem, e.nextItem);
|
|
106
|
+
return;
|
|
107
|
+
case "data":
|
|
108
|
+
this.rebuildConfiguredIndexes();
|
|
109
|
+
return;
|
|
110
|
+
case "clearData":
|
|
111
|
+
this.cache.clear();
|
|
112
|
+
return;
|
|
113
|
+
case "remove":
|
|
114
|
+
this.applyRemovedItem(e.removedIndex, e.movedFromIndex);
|
|
115
|
+
return;
|
|
116
|
+
case "removeMany":
|
|
117
|
+
this.applyRemovedItemsBatch(e.entries);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
sort(e, t, n = !1) {
|
|
122
|
+
let i = t === void 0, a, o;
|
|
123
|
+
if (i) {
|
|
124
|
+
if (!this.dataset.length) throw r.missingDatasetForSort();
|
|
125
|
+
a = this.dataset, o = e;
|
|
126
|
+
} else a = e, o = t;
|
|
127
|
+
if (o.length === 0 || a.length === 0) return a;
|
|
128
|
+
if (o.length === 1) {
|
|
129
|
+
let { field: e, direction: t } = o[0];
|
|
130
|
+
if (i && this.indexedFields.has(e)) {
|
|
131
|
+
let n = this.cache.get(e), r = this.state.getMutationVersion();
|
|
132
|
+
return (!n || n.version !== r) && (this.buildIndexForDataset(e), n = this.cache.get(e)), this.getCachedSortedItems(n, t);
|
|
133
|
+
}
|
|
134
|
+
return this.sortNumericFastPath(a, e, t, n);
|
|
135
|
+
}
|
|
136
|
+
return this.sortMultiField(a, o, n, i);
|
|
137
|
+
}
|
|
138
|
+
sortNumericFastPath(e, t, n, r) {
|
|
139
|
+
if (e.length === 0 || typeof e[0][t] != "number") {
|
|
140
|
+
let i = r ? e : e.slice();
|
|
141
|
+
return i.sort((e, r) => {
|
|
142
|
+
let i = e[t], a = r[t], o = i < a ? -1 : i > a ? 1 : 0;
|
|
143
|
+
return n === "asc" ? o : -o;
|
|
144
|
+
}), i;
|
|
145
|
+
}
|
|
146
|
+
let a = e.length, s = new Float64Array(a);
|
|
147
|
+
for (let n = 0; n < a; n++) s[n] = e[n][t];
|
|
148
|
+
let c = new Uint32Array(a);
|
|
149
|
+
for (let e = 0; e < a; e++) c[e] = e;
|
|
150
|
+
return i(s, a) ? o(c, s, a) : c.sort((e, t) => s[e] - s[t]), this.materializeItemsFromIndexes(e, c, n);
|
|
151
|
+
}
|
|
152
|
+
sortMultiField(e, t, n, r) {
|
|
153
|
+
let [i, ...a] = t;
|
|
154
|
+
if (r && this.indexedFields.has(i.field)) {
|
|
155
|
+
let e = this.cache.get(i.field), t = this.state.getMutationVersion();
|
|
156
|
+
(!e || e.version !== t) && (this.buildIndexForDataset(i.field), e = this.cache.get(i.field));
|
|
157
|
+
let n = e.hasDuplicateValues ? this.getCachedSortedItems(e, i.direction).slice() : this.getCachedSortedItems(e, i.direction);
|
|
158
|
+
return e.hasDuplicateValues ? this.sortTieGroups(n, i.field, a) : n;
|
|
159
|
+
}
|
|
160
|
+
let o = n ? e : e.slice(), s = this.buildComparator(t);
|
|
161
|
+
return o.sort(s), o;
|
|
162
|
+
}
|
|
163
|
+
sortTieGroups(e, t, n) {
|
|
164
|
+
if (n.length === 0) return e;
|
|
165
|
+
let r = this.buildComparator(n), i = e.length, a = 0;
|
|
166
|
+
for (; a < i;) {
|
|
167
|
+
let n = a + 1, o = e[a][t];
|
|
168
|
+
for (; n < i && e[n][t] === o;) n++;
|
|
169
|
+
if (n - a > 1) {
|
|
170
|
+
let t = e.slice(a, n);
|
|
171
|
+
t.sort(r);
|
|
172
|
+
for (let r = a; r < n; r++) e[r] = t[r - a];
|
|
173
|
+
}
|
|
174
|
+
a = n;
|
|
175
|
+
}
|
|
176
|
+
return e;
|
|
177
|
+
}
|
|
178
|
+
materializeItemsFromIndexes(e, t, n) {
|
|
179
|
+
let r = t.length, i = Array(r);
|
|
180
|
+
if (n === "asc") {
|
|
181
|
+
for (let n = 0; n < r; n++) i[n] = e[t[n]];
|
|
182
|
+
return i;
|
|
183
|
+
}
|
|
184
|
+
for (let n = 0; n < r; n++) i[n] = e[t[r - 1 - n]];
|
|
185
|
+
return i;
|
|
186
|
+
}
|
|
187
|
+
getCachedSortedItems(e, t) {
|
|
188
|
+
return t === "asc" ? (e.ascItems === null && (e.ascItems = this.materializeItemsFromIndexes(this.dataset, e.indexes, "asc")), e.ascItems) : (e.descItems === null && (e.descItems = this.getCachedSortedItems(e, "asc").slice().reverse()), e.descItems);
|
|
189
|
+
}
|
|
190
|
+
shouldMaintainIncrementally(e) {
|
|
191
|
+
return e.ascItems !== null || e.descItems !== null;
|
|
192
|
+
}
|
|
193
|
+
hasDuplicateValuesForIndexes(e, t, n) {
|
|
194
|
+
for (let r = 1; r < t.length; r++) if (e[t[r - 1]][n] === e[t[r]][n]) return !0;
|
|
195
|
+
return !1;
|
|
196
|
+
}
|
|
197
|
+
compareIndexesByField(e, t, n) {
|
|
198
|
+
let r = this.dataset[t][e], i = this.dataset[n][e];
|
|
199
|
+
if (typeof r == "number" && typeof i == "number") {
|
|
200
|
+
let e = r - i;
|
|
201
|
+
if (e !== 0) return e;
|
|
202
|
+
} else {
|
|
203
|
+
if (r < i) return -1;
|
|
204
|
+
if (r > i) return 1;
|
|
205
|
+
}
|
|
206
|
+
return t - n;
|
|
207
|
+
}
|
|
208
|
+
applyUpdatedItem(e, t, n) {
|
|
209
|
+
if (this.shouldDeferMutationCacheUpdates()) {
|
|
210
|
+
this.invalidateCachedIndexes();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
for (let r of this.indexedFields) {
|
|
214
|
+
if (t[r] === n[r]) continue;
|
|
215
|
+
let i = this.cache.get(r);
|
|
216
|
+
if (i) {
|
|
217
|
+
if (!this.shouldMaintainIncrementally(i)) {
|
|
218
|
+
this.cache.delete(r);
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
this.updateCachedIndexForUpdatedItem(r, e);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
updateCachedIndexForUpdatedItem(e, t) {
|
|
226
|
+
let n = this.cache.get(e);
|
|
227
|
+
if (!n) return;
|
|
228
|
+
let { indexes: r, reverseIndex: i } = n, a = r.length, o = i[t];
|
|
229
|
+
if (o >= a || r[o] !== t) {
|
|
230
|
+
this.cache.delete(e);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
r.copyWithin(o, o + 1);
|
|
234
|
+
let s = a - 1, c = 0, l = s;
|
|
235
|
+
for (; c < l;) {
|
|
236
|
+
let n = c + l >> 1;
|
|
237
|
+
this.compareIndexesByField(e, r[n], t) <= 0 ? c = n + 1 : l = n;
|
|
238
|
+
}
|
|
239
|
+
let u = c;
|
|
240
|
+
r.copyWithin(u + 1, u, s), r[u] = t, n.ascItems !== null && (n.ascItems.copyWithin(o, o + 1), n.ascItems.copyWithin(u + 1, u, s), n.ascItems[u] = this.dataset[t]);
|
|
241
|
+
let d = Math.min(o, u), f = Math.max(o, u);
|
|
242
|
+
for (let e = d; e <= f; e++) i[r[e]] = e;
|
|
243
|
+
if (n.descItems = null, !n.hasDuplicateValues) {
|
|
244
|
+
let i = u > 0 ? r[u - 1] : -1, o = u + 1 < a ? r[u + 1] : -1;
|
|
245
|
+
n.hasDuplicateValues = i !== -1 && this.dataset[i][e] === this.dataset[t][e] || o !== -1 && this.dataset[o][e] === this.dataset[t][e];
|
|
246
|
+
}
|
|
247
|
+
n.version = this.state.getMutationVersion();
|
|
248
|
+
}
|
|
249
|
+
updateCachedIndexForAddedItems(e, t, n) {
|
|
250
|
+
let r = this.cache.get(e);
|
|
251
|
+
if (!r) return;
|
|
252
|
+
let i = Array(n);
|
|
253
|
+
for (let e = 0; e < n; e++) i[e] = t + e;
|
|
254
|
+
i.sort((t, n) => this.compareIndexesByField(e, t, n));
|
|
255
|
+
let a = new Uint32Array(r.indexes.length + n), o = -1, s = r.hasDuplicateValues, c = 0, l = 0, u = 0;
|
|
256
|
+
for (; c < r.indexes.length && l < i.length;) {
|
|
257
|
+
let t = this.compareIndexesByField(e, r.indexes[c], i[l]) <= 0 ? r.indexes[c++] : i[l++];
|
|
258
|
+
a[u] = t, !s && o !== -1 && this.dataset[o][e] === this.dataset[t][e] && (s = !0), o = t, u += 1;
|
|
259
|
+
}
|
|
260
|
+
for (; c < r.indexes.length;) {
|
|
261
|
+
let t = r.indexes[c++];
|
|
262
|
+
a[u] = t, !s && o !== -1 && this.dataset[o][e] === this.dataset[t][e] && (s = !0), o = t, u += 1;
|
|
263
|
+
}
|
|
264
|
+
for (; l < i.length;) {
|
|
265
|
+
let t = i[l++];
|
|
266
|
+
a[u] = t, !s && o !== -1 && this.dataset[o][e] === this.dataset[t][e] && (s = !0), o = t, u += 1;
|
|
267
|
+
}
|
|
268
|
+
let d = new Uint32Array(a.length);
|
|
269
|
+
for (let e = 0; e < a.length; e++) d[a[e]] = e;
|
|
270
|
+
r.indexes = a, r.reverseIndex = d, r.ascItems = r.ascItems ? this.materializeItemsFromIndexes(this.dataset, a, "asc") : null, r.descItems = null, r.hasDuplicateValues = s, r.version = this.state.getMutationVersion();
|
|
271
|
+
}
|
|
272
|
+
applyRemovedItem(e, t) {
|
|
273
|
+
if (this.shouldDeferMutationCacheUpdates()) {
|
|
274
|
+
this.invalidateCachedIndexes();
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
for (let n of this.indexedFields) {
|
|
278
|
+
let r = this.cache.get(n);
|
|
279
|
+
if (r) {
|
|
280
|
+
if (!this.shouldMaintainIncrementally(r)) {
|
|
281
|
+
this.cache.delete(n);
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
this.updateCachedIndexForRemovedItem(n, e, t);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
applyRemovedItemsBatch(e) {
|
|
289
|
+
if (this.shouldDeferMutationCacheUpdates()) {
|
|
290
|
+
this.invalidateCachedIndexes();
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
for (let t of this.indexedFields) {
|
|
294
|
+
let n = this.cache.get(t);
|
|
295
|
+
if (n) {
|
|
296
|
+
if (!this.shouldMaintainIncrementally(n)) {
|
|
297
|
+
this.cache.delete(t);
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
if (!n.hasDuplicateValues) {
|
|
301
|
+
this.updateUniqueCachedIndexForRemovedItems(n, e), n.version = this.state.getMutationVersion();
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
this.cache.delete(t);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
updateCachedIndexForRemovedItem(e, t, n) {
|
|
309
|
+
let r = this.cache.get(e);
|
|
310
|
+
if (!r) return;
|
|
311
|
+
if (!r.hasDuplicateValues) {
|
|
312
|
+
this.updateUniqueCachedIndexForRemovedItem(r, t, n), r.version = this.state.getMutationVersion();
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
let i = [];
|
|
316
|
+
for (let e = 0; e < r.indexes.length; e++) {
|
|
317
|
+
let a = r.indexes[e];
|
|
318
|
+
a === t || a === n || i.push(a);
|
|
319
|
+
}
|
|
320
|
+
if (n !== null && n !== t) {
|
|
321
|
+
let n = 0, r = i.length;
|
|
322
|
+
for (; n < r;) {
|
|
323
|
+
let a = n + r >> 1;
|
|
324
|
+
this.compareIndexesByField(e, i[a], t) <= 0 ? n = a + 1 : r = a;
|
|
325
|
+
}
|
|
326
|
+
i.splice(n, 0, t);
|
|
327
|
+
}
|
|
328
|
+
let a = Uint32Array.from(i), o = new Uint32Array(this.dataset.length);
|
|
329
|
+
for (let e = 0; e < a.length; e++) {
|
|
330
|
+
let t = a[e];
|
|
331
|
+
o[t] = e;
|
|
332
|
+
}
|
|
333
|
+
r.indexes = a, r.reverseIndex = o, r.ascItems = r.ascItems ? this.materializeItemsFromIndexes(this.dataset, a, "asc") : null, r.descItems = null, r.hasDuplicateValues = r.hasDuplicateValues ? this.hasDuplicateValuesForIndexes(this.dataset, a, e) : !1, r.version = this.state.getMutationVersion();
|
|
334
|
+
}
|
|
335
|
+
updateUniqueCachedIndexForRemovedItem(e, t, n) {
|
|
336
|
+
let r = e.indexes.length - 1, i = new Uint32Array(r), a = new Uint32Array(this.dataset.length), o = e.ascItems === null ? null : Array(r), s = 0;
|
|
337
|
+
for (let r = 0; r < e.indexes.length; r++) {
|
|
338
|
+
let c = e.indexes[r];
|
|
339
|
+
if (c === t) continue;
|
|
340
|
+
let l = n !== null && c === n ? t : c;
|
|
341
|
+
i[s] = l, a[l] = s, o !== null && (o[s] = this.dataset[l]), s += 1;
|
|
342
|
+
}
|
|
343
|
+
e.indexes = i, e.reverseIndex = a, e.ascItems = o, e.descItems = null;
|
|
344
|
+
}
|
|
345
|
+
updateUniqueCachedIndexForRemovedItems(e, t) {
|
|
346
|
+
let n = e.indexes.length, r = new Uint32Array(n), i = new Int32Array(n);
|
|
347
|
+
for (let e = 0; e < n; e++) r[e] = e, i[e] = -1;
|
|
348
|
+
let a = n;
|
|
349
|
+
for (let e = 0; e < t.length; e++) {
|
|
350
|
+
let n = t[e];
|
|
351
|
+
n.movedFromIndex !== null && (r[n.removedIndex] = r[n.movedFromIndex]), --a;
|
|
352
|
+
}
|
|
353
|
+
let o = new Uint32Array(a), s = new Uint32Array(a), c = e.ascItems === null ? null : Array(a);
|
|
354
|
+
for (let e = 0; e < a; e++) i[r[e]] = e;
|
|
355
|
+
let l = 0;
|
|
356
|
+
for (let t = 0; t < e.indexes.length; t++) {
|
|
357
|
+
let n = i[e.indexes[t]];
|
|
358
|
+
n !== -1 && (o[l] = n, s[n] = l, c !== null && (c[l] = this.dataset[n]), l += 1);
|
|
359
|
+
}
|
|
360
|
+
e.indexes = o, e.reverseIndex = s, e.ascItems = c, e.descItems = null;
|
|
361
|
+
}
|
|
362
|
+
buildComparator(e) {
|
|
363
|
+
let t = e.map(({ field: e }) => e), n = e.map(({ direction: e }) => e === "asc" ? 1 : -1), r = t.length;
|
|
364
|
+
return (e, i) => {
|
|
365
|
+
for (let a = 0; a < r; a++) {
|
|
366
|
+
let r = t[a], o = e[r], s = i[r];
|
|
367
|
+
if (o < s) return -n[a];
|
|
368
|
+
if (o > s) return n[a];
|
|
369
|
+
}
|
|
370
|
+
return 0;
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
//#endregion
|
|
375
|
+
export { s as SortEngine };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CollectionItem } from "../types";
|
|
2
|
+
export interface SortIndex<T extends CollectionItem = CollectionItem> {
|
|
3
|
+
indexes: Uint32Array;
|
|
4
|
+
reverseIndex: Uint32Array;
|
|
5
|
+
ascItems: T[] | null;
|
|
6
|
+
descItems: T[] | null;
|
|
7
|
+
hasDuplicateValues: boolean;
|
|
8
|
+
version: number;
|
|
9
|
+
}
|
|
10
|
+
export interface SortEngineOptions<T extends CollectionItem = CollectionItem> {
|
|
11
|
+
data?: T[];
|
|
12
|
+
fields?: (keyof T & string)[];
|
|
13
|
+
}
|
|
14
|
+
export type SortRuntime<T extends CollectionItem> = {
|
|
15
|
+
indexedFields: Set<keyof T & string>;
|
|
16
|
+
cache: Map<string, SortIndex<T>>;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CollectionItem } from "../types";
|
|
2
|
+
import type { SortRuntime } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if every value in `values` is a non-negative 32-bit integer,
|
|
5
|
+
* i.e. it can be treated as a Uint32 without precision loss.
|
|
6
|
+
*/
|
|
7
|
+
export declare function canUseUint32Radix(values: Float64Array, length: number): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* 2-pass LSD radix sort — sorts `indexes` so that `values[indexes[i]]` is
|
|
10
|
+
* non-decreasing. Requires all values to be in [0, 2^32-1] integers.
|
|
11
|
+
*
|
|
12
|
+
* Time O(2n + 2·65536) ≈ O(n)
|
|
13
|
+
* Space O(n + 65536) for temp buffer + count array
|
|
14
|
+
*/
|
|
15
|
+
export declare function radixSortUint32(indexes: Uint32Array, values: Float64Array, length: number): void;
|
|
16
|
+
export declare const createSortRuntime: <T extends CollectionItem>() => SortRuntime<T>;
|
|
17
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/sort/utils.ts
|
|
2
|
+
function e(e, t) {
|
|
3
|
+
for (let n = 0; n < t; n++) {
|
|
4
|
+
let t = e[n];
|
|
5
|
+
if (t !== t >>> 0) return !1;
|
|
6
|
+
}
|
|
7
|
+
return !0;
|
|
8
|
+
}
|
|
9
|
+
function t(e, t, n) {
|
|
10
|
+
let r = new Uint32Array(n), i = new Uint32Array(65536);
|
|
11
|
+
for (let r = 0; r < n; r++) i[t[e[r]] & 65535]++;
|
|
12
|
+
let a = 0;
|
|
13
|
+
for (let e = 0; e < 65536; e++) {
|
|
14
|
+
let t = i[e];
|
|
15
|
+
i[e] = a, a += t;
|
|
16
|
+
}
|
|
17
|
+
for (let a = 0; a < n; a++) {
|
|
18
|
+
let n = t[e[a]] & 65535;
|
|
19
|
+
r[i[n]++] = e[a];
|
|
20
|
+
}
|
|
21
|
+
i.fill(0);
|
|
22
|
+
for (let e = 0; e < n; e++) i[t[r[e]] >>> 16 & 65535]++;
|
|
23
|
+
a = 0;
|
|
24
|
+
for (let e = 0; e < 65536; e++) {
|
|
25
|
+
let t = i[e];
|
|
26
|
+
i[e] = a, a += t;
|
|
27
|
+
}
|
|
28
|
+
for (let a = 0; a < n; a++) {
|
|
29
|
+
let n = t[r[a]] >>> 16 & 65535;
|
|
30
|
+
e[i[n]++] = r[a];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
var n = () => ({
|
|
34
|
+
indexedFields: /* @__PURE__ */ new Set(),
|
|
35
|
+
cache: /* @__PURE__ */ new Map()
|
|
36
|
+
});
|
|
37
|
+
//#endregion
|
|
38
|
+
export { e as canUseUint32Radix, n as createSortRuntime, t as radixSortUint32 };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export type CollectionItem = Record<string, any>;
|
|
2
|
+
export type IndexableKey<T> = {
|
|
3
|
+
[K in keyof T]: T[K] extends string | number ? K : never;
|
|
4
|
+
}[keyof T];
|
|
5
|
+
export interface UpdateDescriptor<T extends CollectionItem> {
|
|
6
|
+
field: IndexableKey<T> & string;
|
|
7
|
+
data: T;
|
|
8
|
+
}
|
|
9
|
+
export interface FilterCriterion<T extends CollectionItem> {
|
|
10
|
+
field: (keyof T & string) | (string & {});
|
|
11
|
+
values?: any[];
|
|
12
|
+
exclude?: any[];
|
|
13
|
+
}
|
|
14
|
+
export type SortDirection = "asc" | "desc";
|
|
15
|
+
export interface SortDescriptor<T extends CollectionItem> {
|
|
16
|
+
field: keyof T & string;
|
|
17
|
+
direction: SortDirection;
|
|
18
|
+
}
|
|
19
|
+
export type StateListener<T extends CollectionItem> = (mutation: StateMutation<T>) => void;
|
|
20
|
+
export interface StateRegistryFactory<TValue> {
|
|
21
|
+
(): TValue;
|
|
22
|
+
}
|
|
23
|
+
export interface StateOptions {
|
|
24
|
+
filterByPreviousResult?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface StatePreviousResult<T extends CollectionItem> {
|
|
27
|
+
result: T[];
|
|
28
|
+
sourceData: T[];
|
|
29
|
+
version: number;
|
|
30
|
+
}
|
|
31
|
+
export type StateAddMutation<T extends CollectionItem> = {
|
|
32
|
+
type: "add";
|
|
33
|
+
items: T[];
|
|
34
|
+
startIndex: number;
|
|
35
|
+
};
|
|
36
|
+
export type StateUpdateMutation<T extends CollectionItem> = {
|
|
37
|
+
type: "update";
|
|
38
|
+
field: IndexableKey<T> & string;
|
|
39
|
+
index: number;
|
|
40
|
+
previousItem: T;
|
|
41
|
+
nextItem: T;
|
|
42
|
+
};
|
|
43
|
+
export type StateDataMutation<T extends CollectionItem> = {
|
|
44
|
+
type: "data";
|
|
45
|
+
data: T[];
|
|
46
|
+
};
|
|
47
|
+
export type StateClearMutation<T extends CollectionItem> = {
|
|
48
|
+
type: "clearData";
|
|
49
|
+
data: T[];
|
|
50
|
+
};
|
|
51
|
+
export type StateRemoveMutation<T extends CollectionItem> = {
|
|
52
|
+
type: "remove";
|
|
53
|
+
field: IndexableKey<T> & string;
|
|
54
|
+
value: T[IndexableKey<T> & string];
|
|
55
|
+
removedItem: T;
|
|
56
|
+
removedIndex: number;
|
|
57
|
+
movedItem: T | null;
|
|
58
|
+
movedFromIndex: number | null;
|
|
59
|
+
};
|
|
60
|
+
export type StateRemoveManyEntry<T extends CollectionItem> = {
|
|
61
|
+
value: T[IndexableKey<T> & string];
|
|
62
|
+
removedItem: T;
|
|
63
|
+
removedIndex: number;
|
|
64
|
+
movedItem: T | null;
|
|
65
|
+
movedFromIndex: number | null;
|
|
66
|
+
};
|
|
67
|
+
export type StateRemoveManyMutation<T extends CollectionItem> = {
|
|
68
|
+
type: "removeMany";
|
|
69
|
+
field: IndexableKey<T> & string;
|
|
70
|
+
entries: StateRemoveManyEntry<T>[];
|
|
71
|
+
};
|
|
72
|
+
export type StateMutation<T extends CollectionItem> = StateAddMutation<T> | StateUpdateMutation<T> | StateDataMutation<T> | StateClearMutation<T> | StateRemoveMutation<T> | StateRemoveManyMutation<T>;
|
|
73
|
+
//# sourceMappingURL=types.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,62 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devisfuture/mega-collection",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.7",
|
|
4
4
|
"description": "High-performance search, filter & sort engine for 100K+ item collections in JavaScript/TypeScript",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
5
6
|
"exports": {
|
|
6
7
|
".": {
|
|
7
|
-
"types": "./dist/index.d.
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
8
9
|
"default": "./dist/index.mjs"
|
|
9
10
|
},
|
|
10
11
|
"./search": {
|
|
11
|
-
"types": "./dist/search/index.d.
|
|
12
|
+
"types": "./dist/search/index.d.ts",
|
|
12
13
|
"default": "./dist/search/index.mjs"
|
|
13
14
|
},
|
|
14
15
|
"./filter": {
|
|
15
|
-
"types": "./dist/filter/index.d.
|
|
16
|
+
"types": "./dist/filter/index.d.ts",
|
|
16
17
|
"default": "./dist/filter/index.mjs"
|
|
17
18
|
},
|
|
18
19
|
"./sort": {
|
|
19
|
-
"types": "./dist/sort/index.d.
|
|
20
|
+
"types": "./dist/sort/index.d.ts",
|
|
20
21
|
"default": "./dist/sort/index.mjs"
|
|
21
22
|
},
|
|
22
23
|
"./merge": {
|
|
23
|
-
"types": "./dist/merge/index.d.
|
|
24
|
+
"types": "./dist/merge/index.d.ts",
|
|
24
25
|
"default": "./dist/merge/index.mjs"
|
|
25
26
|
},
|
|
26
27
|
"./package.json": "./package.json"
|
|
27
28
|
},
|
|
28
|
-
"typesVersions": {
|
|
29
|
-
"*": {
|
|
30
|
-
"search": [
|
|
31
|
-
"./dist/search/index.d.mts"
|
|
32
|
-
],
|
|
33
|
-
"filter": [
|
|
34
|
-
"./dist/filter/index.d.mts"
|
|
35
|
-
],
|
|
36
|
-
"sort": [
|
|
37
|
-
"./dist/sort/index.d.mts"
|
|
38
|
-
],
|
|
39
|
-
"merge": [
|
|
40
|
-
"./dist/merge/index.d.mts"
|
|
41
|
-
]
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
29
|
"files": [
|
|
45
|
-
"dist
|
|
46
|
-
"dist
|
|
47
|
-
"dist/
|
|
48
|
-
"dist/search/index.mjs",
|
|
49
|
-
"dist/search/index.d.mts",
|
|
50
|
-
"dist/filter/index.mjs",
|
|
51
|
-
"dist/filter/index.d.mts",
|
|
52
|
-
"dist/sort/index.mjs",
|
|
53
|
-
"dist/sort/index.d.mts",
|
|
54
|
-
"dist/merge/index.mjs",
|
|
55
|
-
"dist/merge/index.d.mts"
|
|
30
|
+
"dist/**/*.mjs",
|
|
31
|
+
"dist/**/*.d.ts",
|
|
32
|
+
"dist/index.d.ts"
|
|
56
33
|
],
|
|
57
34
|
"sideEffects": false,
|
|
58
35
|
"scripts": {
|
|
59
|
-
"build:types": "tsc --emitDeclarationOnly
|
|
36
|
+
"build:types": "tsc --emitDeclarationOnly",
|
|
60
37
|
"build": "vite build && npm run build:types",
|
|
61
38
|
"build:watch": "vite build --watch",
|
|
62
39
|
"dev": "vite build --watch",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|