@devisfuture/mega-collection 2.4.7 → 2.5.0
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 +93 -75
- package/dist/{State.d.ts → State-CYIe-3He.d.ts} +5 -3
- package/dist/chunks/constants-DK9S0Db0.mjs +1 -0
- package/dist/chunks/merge-C6intZSe.mjs +1 -0
- package/dist/filter/index.d.ts +114 -4
- package/dist/filter/index.mjs +1 -2
- package/dist/index.d.ts +2 -4
- package/dist/index.mjs +1 -2
- package/dist/merge/index.d.ts +131 -4
- package/dist/merge/index.mjs +1 -2
- package/dist/search/index.d.ts +191 -4
- package/dist/search/index.mjs +1 -2
- package/dist/sort/index.d.ts +57 -4
- package/dist/sort/index.mjs +1 -2
- package/dist/types-DONld7xY.d.ts +74 -0
- package/package.json +6 -2
- package/dist/State.mjs +0 -183
- package/dist/constants.d.ts +0 -5
- package/dist/constants.mjs +0 -4
- package/dist/filter/chain.d.ts +0 -9
- package/dist/filter/chain.mjs +0 -22
- package/dist/filter/constants.d.ts +0 -2
- package/dist/filter/criterion.d.ts +0 -6
- package/dist/filter/criterion.mjs +0 -64
- package/dist/filter/errors.d.ts +0 -7
- package/dist/filter/errors.mjs +0 -17
- package/dist/filter/filter.d.ts +0 -89
- package/dist/filter/filter.mjs +0 -439
- package/dist/filter/nested.d.ts +0 -32
- package/dist/filter/nested.mjs +0 -246
- package/dist/filter/types.d.ts +0 -74
- package/dist/filter/utils.d.ts +0 -4
- package/dist/filter/utils.mjs +0 -29
- package/dist/indexer.d.ts +0 -41
- package/dist/indexer.mjs +0 -101
- package/dist/internal.d.ts +0 -6
- package/dist/internal.mjs +0 -18
- package/dist/merge/chain.d.ts +0 -9
- package/dist/merge/chain.mjs +0 -23
- package/dist/merge/constants.d.ts +0 -6
- package/dist/merge/constants.mjs +0 -8
- package/dist/merge/errors.d.ts +0 -8
- package/dist/merge/errors.mjs +0 -19
- package/dist/merge/merge-engines.d.ts +0 -75
- package/dist/merge/merge-engines.mjs +0 -432
- package/dist/merge/module-adapters.d.ts +0 -7
- package/dist/merge/module-adapters.mjs +0 -41
- package/dist/merge/types.d.ts +0 -125
- package/dist/search/constants.d.ts +0 -5
- package/dist/search/nested.d.ts +0 -41
- package/dist/search/nested.mjs +0 -210
- package/dist/search/ngram.d.ts +0 -23
- package/dist/search/ngram.mjs +0 -96
- package/dist/search/text-search.d.ts +0 -146
- package/dist/search/text-search.mjs +0 -696
- package/dist/search/types.d.ts +0 -93
- package/dist/search/utils.d.ts +0 -4
- package/dist/search/utils.mjs +0 -22
- package/dist/sort/errors.d.ts +0 -5
- package/dist/sort/errors.mjs +0 -11
- package/dist/sort/sorter.d.ts +0 -47
- package/dist/sort/sorter.mjs +0 -375
- package/dist/sort/types.d.ts +0 -18
- package/dist/sort/utils.d.ts +0 -17
- package/dist/sort/utils.mjs +0 -38
- package/dist/types.d.ts +0 -73
package/dist/search/types.d.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import type { CollectionItem } from "../types";
|
|
2
|
-
export interface TextSearchEngineOptions<T extends CollectionItem = CollectionItem> {
|
|
3
|
-
data?: T[];
|
|
4
|
-
fields?: (keyof T & string)[];
|
|
5
|
-
nestedFields?: string[];
|
|
6
|
-
/**
|
|
7
|
-
* Minimum query length required to trigger a search. Defaults to `1`.
|
|
8
|
-
*
|
|
9
|
-
* Queries shorter than the trigram length (3) always use a linear scan even
|
|
10
|
-
* when an index is configured, because the index only stores trigrams. Set
|
|
11
|
-
* `minQueryLength` to `3` or higher to skip sub-trigram queries entirely and
|
|
12
|
-
* guarantee that every accepted query hits the index.
|
|
13
|
-
*/
|
|
14
|
-
minQueryLength?: number;
|
|
15
|
-
/**
|
|
16
|
-
* When `true`, each search narrows its source to the previous result if the
|
|
17
|
-
* new query includes the previous query as a prefix/substring. Useful for
|
|
18
|
-
* search-as-you-type scenarios where the user incrementally refines the query.
|
|
19
|
-
*
|
|
20
|
-
* Call {@link TextSearchEngine.resetSearchState} to discard the saved result
|
|
21
|
-
* and force the next search to scan the full dataset.
|
|
22
|
-
*/
|
|
23
|
-
filterByPreviousResult?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Suppresses non-production fallback warnings.
|
|
26
|
-
* Diagnostic warnings also stop accumulating in {@link TextSearchEngine.getWarnings}.
|
|
27
|
-
*/
|
|
28
|
-
silent?: boolean;
|
|
29
|
-
}
|
|
30
|
-
export interface SearchQueryOptions {
|
|
31
|
-
limit?: number;
|
|
32
|
-
offset?: number;
|
|
33
|
-
}
|
|
34
|
-
export interface TextSearchEngineStats {
|
|
35
|
-
totalQueries: number;
|
|
36
|
-
indexedQueries: number;
|
|
37
|
-
fallbackQueries: number;
|
|
38
|
-
fallbackRate: number;
|
|
39
|
-
fallbackFields: Record<string, number>;
|
|
40
|
-
}
|
|
41
|
-
export type NestedFieldDescriptor = {
|
|
42
|
-
collectionKey: string;
|
|
43
|
-
nestedKey: string;
|
|
44
|
-
};
|
|
45
|
-
export type SearchIndex = {
|
|
46
|
-
ngramMap: Map<string, Set<number>>;
|
|
47
|
-
normalizedValues: string[];
|
|
48
|
-
version: number;
|
|
49
|
-
};
|
|
50
|
-
export interface SearchNestedCollectionStorage {
|
|
51
|
-
ngramIndexes: Map<string, Map<string, Set<number>>>;
|
|
52
|
-
normalizedFieldValues: Map<string, string[]>;
|
|
53
|
-
}
|
|
54
|
-
export type SearchRuntime<T extends CollectionItem> = {
|
|
55
|
-
indexedFields: Set<keyof T & string>;
|
|
56
|
-
flatIndexes: Map<string, SearchIndex>;
|
|
57
|
-
nestedStorage: SearchNestedCollectionStorage;
|
|
58
|
-
deferredMutationVersion: number | null;
|
|
59
|
-
filterByPreviousResult: boolean;
|
|
60
|
-
previousResultIndices: number[] | null;
|
|
61
|
-
previousResultLookup: Uint8Array | null;
|
|
62
|
-
previousQuery: string | null;
|
|
63
|
-
stats: {
|
|
64
|
-
totalQueries: number;
|
|
65
|
-
indexedQueries: number;
|
|
66
|
-
fallbackQueries: number;
|
|
67
|
-
fallbackFields: Map<string, number>;
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
export type SearchResult<T extends CollectionItem> = {
|
|
71
|
-
items: T[];
|
|
72
|
-
indices: number[];
|
|
73
|
-
};
|
|
74
|
-
export type SearchWindow = {
|
|
75
|
-
offset: number;
|
|
76
|
-
limit: number;
|
|
77
|
-
take: number;
|
|
78
|
-
hasWindow: boolean;
|
|
79
|
-
};
|
|
80
|
-
export type SearchSource = {
|
|
81
|
-
indices: number[] | null;
|
|
82
|
-
lookup: Uint8Array | null;
|
|
83
|
-
};
|
|
84
|
-
export type IntersectPostingListsOptions = {
|
|
85
|
-
restrictionLookup?: Uint8Array | null;
|
|
86
|
-
take?: number;
|
|
87
|
-
};
|
|
88
|
-
export type IntersectPostingListsInCandidatesOptions = {
|
|
89
|
-
candidateIndices: readonly number[];
|
|
90
|
-
restrictionLookup?: Uint8Array | null;
|
|
91
|
-
take?: number;
|
|
92
|
-
};
|
|
93
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/search/utils.d.ts
DELETED
package/dist/search/utils.mjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//#region src/search/utils.ts
|
|
2
|
-
var e = () => ({
|
|
3
|
-
indexedFields: /* @__PURE__ */ new Set(),
|
|
4
|
-
flatIndexes: /* @__PURE__ */ new Map(),
|
|
5
|
-
nestedStorage: {
|
|
6
|
-
ngramIndexes: /* @__PURE__ */ new Map(),
|
|
7
|
-
normalizedFieldValues: /* @__PURE__ */ new Map()
|
|
8
|
-
},
|
|
9
|
-
deferredMutationVersion: null,
|
|
10
|
-
filterByPreviousResult: !1,
|
|
11
|
-
previousResultIndices: null,
|
|
12
|
-
previousResultLookup: null,
|
|
13
|
-
previousQuery: null,
|
|
14
|
-
stats: {
|
|
15
|
-
totalQueries: 0,
|
|
16
|
-
indexedQueries: 0,
|
|
17
|
-
fallbackQueries: 0,
|
|
18
|
-
fallbackFields: /* @__PURE__ */ new Map()
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
//#endregion
|
|
22
|
-
export { e as createSearchRuntime };
|
package/dist/sort/errors.d.ts
DELETED
package/dist/sort/errors.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
//#region src/sort/errors.ts
|
|
2
|
-
var e = class e extends Error {
|
|
3
|
-
constructor(e) {
|
|
4
|
-
super(e), this.name = "SortEngineError";
|
|
5
|
-
}
|
|
6
|
-
static missingDatasetForSort() {
|
|
7
|
-
return new e("SortEngine: no dataset in memory.");
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
//#endregion
|
|
11
|
-
export { e as SortEngineError };
|
package/dist/sort/sorter.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { State } from "../State";
|
|
2
|
-
import { CollectionItem, SortDescriptor, type UpdateDescriptor } from "../types";
|
|
3
|
-
import type { SortEngineOptions } from "./types";
|
|
4
|
-
export declare class SortEngine<T extends CollectionItem> {
|
|
5
|
-
private readonly state;
|
|
6
|
-
private readonly namespace;
|
|
7
|
-
constructor(options?: SortEngineOptions<T> & {
|
|
8
|
-
state?: State<T>;
|
|
9
|
-
});
|
|
10
|
-
private get dataset();
|
|
11
|
-
private get runtime();
|
|
12
|
-
private get cache();
|
|
13
|
-
private get indexedFields();
|
|
14
|
-
private shouldDeferMutationCacheUpdates;
|
|
15
|
-
private invalidateCachedIndexes;
|
|
16
|
-
private rebuildConfiguredIndexes;
|
|
17
|
-
private buildIndexForDataset;
|
|
18
|
-
private buildIndexFromData;
|
|
19
|
-
clearIndexes(): this;
|
|
20
|
-
clearData(): this;
|
|
21
|
-
data(data: T[]): this;
|
|
22
|
-
add(items: T[]): this;
|
|
23
|
-
update(descriptor: UpdateDescriptor<T>): this;
|
|
24
|
-
private applyAddedItems;
|
|
25
|
-
getOriginData(): T[];
|
|
26
|
-
private handleStateMutation;
|
|
27
|
-
sort(descriptors: SortDescriptor<T>[]): T[];
|
|
28
|
-
sort(data: T[], descriptors: SortDescriptor<T>[], inPlace?: boolean): T[];
|
|
29
|
-
private sortNumericFastPath;
|
|
30
|
-
private sortMultiField;
|
|
31
|
-
private sortTieGroups;
|
|
32
|
-
private materializeItemsFromIndexes;
|
|
33
|
-
private getCachedSortedItems;
|
|
34
|
-
private shouldMaintainIncrementally;
|
|
35
|
-
private hasDuplicateValuesForIndexes;
|
|
36
|
-
private compareIndexesByField;
|
|
37
|
-
private applyUpdatedItem;
|
|
38
|
-
private updateCachedIndexForUpdatedItem;
|
|
39
|
-
private updateCachedIndexForAddedItems;
|
|
40
|
-
private applyRemovedItem;
|
|
41
|
-
private applyRemovedItemsBatch;
|
|
42
|
-
private updateCachedIndexForRemovedItem;
|
|
43
|
-
private updateUniqueCachedIndexForRemovedItem;
|
|
44
|
-
private updateUniqueCachedIndexForRemovedItems;
|
|
45
|
-
private buildComparator;
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=sorter.d.ts.map
|
package/dist/sort/sorter.mjs
DELETED
|
@@ -1,375 +0,0 @@
|
|
|
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 };
|
package/dist/sort/types.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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
|
package/dist/sort/utils.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
|
package/dist/sort/utils.mjs
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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 };
|