@zengrid/shared 1.0.3 → 1.0.4
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/README.md +44 -0
- package/dist/index.cjs.default.js +1 -0
- package/dist/index.cjs.js +7394 -0
- package/dist/index.cjs.mjs +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +7343 -0
- package/dist/package.json +54 -0
- package/dist/src/algorithms/filter/bloom-filter.d.ts +120 -0
- package/dist/src/algorithms/filter/bloom-filter.d.ts.map +1 -0
- package/dist/src/algorithms/filter/index.d.ts +7 -0
- package/dist/src/algorithms/filter/index.d.ts.map +1 -0
- package/dist/src/algorithms/graph/bfs.d.ts +71 -0
- package/dist/src/algorithms/graph/bfs.d.ts.map +1 -0
- package/dist/src/algorithms/graph/dfs.d.ts +62 -0
- package/dist/src/algorithms/graph/dfs.d.ts.map +1 -0
- package/dist/src/algorithms/graph/graph.interface.d.ts +63 -0
- package/dist/src/algorithms/graph/graph.interface.d.ts.map +1 -0
- package/dist/src/algorithms/graph/index.d.ts +9 -0
- package/dist/src/algorithms/graph/index.d.ts.map +1 -0
- package/dist/src/algorithms/index.d.ts +11 -0
- package/dist/src/algorithms/index.d.ts.map +1 -0
- package/dist/src/algorithms/pattern/index.d.ts +8 -0
- package/dist/src/algorithms/pattern/index.d.ts.map +1 -0
- package/dist/src/algorithms/pattern/sequence-detector.d.ts +62 -0
- package/dist/src/algorithms/pattern/sequence-detector.d.ts.map +1 -0
- package/dist/src/algorithms/search/binary-search.d.ts +86 -0
- package/dist/src/algorithms/search/binary-search.d.ts.map +1 -0
- package/dist/src/algorithms/search/index.d.ts +6 -0
- package/dist/src/algorithms/search/index.d.ts.map +1 -0
- package/dist/src/algorithms/sorting/comparators.d.ts +126 -0
- package/dist/src/algorithms/sorting/comparators.d.ts.map +1 -0
- package/dist/src/algorithms/sorting/index.d.ts +9 -0
- package/dist/src/algorithms/sorting/index.d.ts.map +1 -0
- package/dist/src/algorithms/sorting/sorting.interface.d.ts +38 -0
- package/dist/src/algorithms/sorting/sorting.interface.d.ts.map +1 -0
- package/dist/src/algorithms/sorting/timsort.d.ts +55 -0
- package/dist/src/algorithms/sorting/timsort.d.ts.map +1 -0
- package/dist/src/data-structures/column-store/column-store.d.ts +52 -0
- package/dist/src/data-structures/column-store/column-store.d.ts.map +1 -0
- package/dist/src/data-structures/column-store/column-store.interface.d.ts +155 -0
- package/dist/src/data-structures/column-store/column-store.interface.d.ts.map +1 -0
- package/dist/src/data-structures/column-store/index.d.ts +6 -0
- package/dist/src/data-structures/column-store/index.d.ts.map +1 -0
- package/dist/src/data-structures/command-stack/command-stack.d.ts +61 -0
- package/dist/src/data-structures/command-stack/command-stack.d.ts.map +1 -0
- package/dist/src/data-structures/command-stack/command-stack.interface.d.ts +80 -0
- package/dist/src/data-structures/command-stack/command-stack.interface.d.ts.map +1 -0
- package/dist/src/data-structures/command-stack/index.d.ts +3 -0
- package/dist/src/data-structures/command-stack/index.d.ts.map +1 -0
- package/dist/src/data-structures/dependency-graph/dependency-graph.d.ts +147 -0
- package/dist/src/data-structures/dependency-graph/dependency-graph.d.ts.map +1 -0
- package/dist/src/data-structures/dependency-graph/dependency-graph.interface.d.ts +161 -0
- package/dist/src/data-structures/dependency-graph/dependency-graph.interface.d.ts.map +1 -0
- package/dist/src/data-structures/dependency-graph/index.d.ts +8 -0
- package/dist/src/data-structures/dependency-graph/index.d.ts.map +1 -0
- package/dist/src/data-structures/disjoint-set/disjoint-set.d.ts +84 -0
- package/dist/src/data-structures/disjoint-set/disjoint-set.d.ts.map +1 -0
- package/dist/src/data-structures/disjoint-set/disjoint-set.interface.d.ts +185 -0
- package/dist/src/data-structures/disjoint-set/disjoint-set.interface.d.ts.map +1 -0
- package/dist/src/data-structures/disjoint-set/index.d.ts +7 -0
- package/dist/src/data-structures/disjoint-set/index.d.ts.map +1 -0
- package/dist/src/data-structures/index-map/index-map.d.ts +150 -0
- package/dist/src/data-structures/index-map/index-map.d.ts.map +1 -0
- package/dist/src/data-structures/index-map/index-map.interface.d.ts +186 -0
- package/dist/src/data-structures/index-map/index-map.interface.d.ts.map +1 -0
- package/dist/src/data-structures/index-map/index.d.ts +6 -0
- package/dist/src/data-structures/index-map/index.d.ts.map +1 -0
- package/dist/src/data-structures/index.d.ts +36 -0
- package/dist/src/data-structures/index.d.ts.map +1 -0
- package/dist/src/data-structures/interval-tree/index.d.ts +7 -0
- package/dist/src/data-structures/interval-tree/index.d.ts.map +1 -0
- package/dist/src/data-structures/interval-tree/interval-tree.d.ts +141 -0
- package/dist/src/data-structures/interval-tree/interval-tree.d.ts.map +1 -0
- package/dist/src/data-structures/interval-tree/interval-tree.interface.d.ts +212 -0
- package/dist/src/data-structures/interval-tree/interval-tree.interface.d.ts.map +1 -0
- package/dist/src/data-structures/lru-cache/index.d.ts +3 -0
- package/dist/src/data-structures/lru-cache/index.d.ts.map +1 -0
- package/dist/src/data-structures/lru-cache/lru-cache.d.ts +134 -0
- package/dist/src/data-structures/lru-cache/lru-cache.d.ts.map +1 -0
- package/dist/src/data-structures/lru-cache/lru-cache.interface.d.ts +173 -0
- package/dist/src/data-structures/lru-cache/lru-cache.interface.d.ts.map +1 -0
- package/dist/src/data-structures/prefix-sum-array/index.d.ts +6 -0
- package/dist/src/data-structures/prefix-sum-array/index.d.ts.map +1 -0
- package/dist/src/data-structures/prefix-sum-array/prefix-sum-array.d.ts +63 -0
- package/dist/src/data-structures/prefix-sum-array/prefix-sum-array.d.ts.map +1 -0
- package/dist/src/data-structures/prefix-sum-array/prefix-sum-array.interface.d.ts +80 -0
- package/dist/src/data-structures/prefix-sum-array/prefix-sum-array.interface.d.ts.map +1 -0
- package/dist/src/data-structures/rtree/index.d.ts +8 -0
- package/dist/src/data-structures/rtree/index.d.ts.map +1 -0
- package/dist/src/data-structures/rtree/rtree.d.ts +81 -0
- package/dist/src/data-structures/rtree/rtree.d.ts.map +1 -0
- package/dist/src/data-structures/rtree/rtree.interface.d.ts +143 -0
- package/dist/src/data-structures/rtree/rtree.interface.d.ts.map +1 -0
- package/dist/src/data-structures/segment-tree/index.d.ts +4 -0
- package/dist/src/data-structures/segment-tree/index.d.ts.map +1 -0
- package/dist/src/data-structures/segment-tree/segment-tree.d.ts +134 -0
- package/dist/src/data-structures/segment-tree/segment-tree.d.ts.map +1 -0
- package/dist/src/data-structures/segment-tree/segment-tree.interface.d.ts +202 -0
- package/dist/src/data-structures/segment-tree/segment-tree.interface.d.ts.map +1 -0
- package/dist/src/data-structures/skip-list/index.d.ts +4 -0
- package/dist/src/data-structures/skip-list/index.d.ts.map +1 -0
- package/dist/src/data-structures/skip-list/skip-list.d.ts +137 -0
- package/dist/src/data-structures/skip-list/skip-list.d.ts.map +1 -0
- package/dist/src/data-structures/skip-list/skip-list.interface.d.ts +223 -0
- package/dist/src/data-structures/skip-list/skip-list.interface.d.ts.map +1 -0
- package/dist/src/data-structures/sparse-matrix/index.d.ts +6 -0
- package/dist/src/data-structures/sparse-matrix/index.d.ts.map +1 -0
- package/dist/src/data-structures/sparse-matrix/sparse-matrix.d.ts +44 -0
- package/dist/src/data-structures/sparse-matrix/sparse-matrix.d.ts.map +1 -0
- package/dist/src/data-structures/sparse-matrix/sparse-matrix.interface.d.ts +105 -0
- package/dist/src/data-structures/sparse-matrix/sparse-matrix.interface.d.ts.map +1 -0
- package/dist/src/data-structures/suffix-array/index.d.ts +3 -0
- package/dist/src/data-structures/suffix-array/index.d.ts.map +1 -0
- package/dist/src/data-structures/suffix-array/suffix-array.d.ts +102 -0
- package/dist/src/data-structures/suffix-array/suffix-array.d.ts.map +1 -0
- package/dist/src/data-structures/suffix-array/suffix-array.interface.d.ts +117 -0
- package/dist/src/data-structures/suffix-array/suffix-array.interface.d.ts.map +1 -0
- package/dist/src/data-structures/trie/index.d.ts +8 -0
- package/dist/src/data-structures/trie/index.d.ts.map +1 -0
- package/dist/src/data-structures/trie/trie.d.ts +205 -0
- package/dist/src/data-structures/trie/trie.d.ts.map +1 -0
- package/dist/src/data-structures/trie/trie.interface.d.ts +117 -0
- package/dist/src/data-structures/trie/trie.interface.d.ts.map +1 -0
- package/dist/src/index.d.ts +51 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/patterns/coordinator.d.ts +90 -0
- package/dist/src/patterns/coordinator.d.ts.map +1 -0
- package/dist/src/patterns/event-emitter.d.ts +106 -0
- package/dist/src/patterns/event-emitter.d.ts.map +1 -0
- package/dist/src/patterns/factory.d.ts +120 -0
- package/dist/src/patterns/factory.d.ts.map +1 -0
- package/dist/src/patterns/index.d.ts +21 -0
- package/dist/src/patterns/index.d.ts.map +1 -0
- package/dist/src/patterns/mediator.d.ts +116 -0
- package/dist/src/patterns/mediator.d.ts.map +1 -0
- package/dist/src/patterns/object-pool.d.ts +178 -0
- package/dist/src/patterns/object-pool.d.ts.map +1 -0
- package/dist/src/patterns/observer.d.ts +89 -0
- package/dist/src/patterns/observer.d.ts.map +1 -0
- package/dist/src/patterns/operation-mode.d.ts +75 -0
- package/dist/src/patterns/operation-mode.d.ts.map +1 -0
- package/dist/src/patterns/state-machine.d.ts +122 -0
- package/dist/src/patterns/state-machine.d.ts.map +1 -0
- package/dist/src/types/common.d.ts +56 -0
- package/dist/src/types/common.d.ts.map +1 -0
- package/dist/src/types/index.d.ts +5 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/utils/index.d.ts +7 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/timing.d.ts +104 -0
- package/dist/src/utils/timing.d.ts.map +1 -0
- package/dist/src/utils/timing.interface.d.ts +96 -0
- package/dist/src/utils/timing.interface.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interval Tree interfaces for ZenGrid
|
|
3
|
+
* Efficiently finds all intervals that overlap with a given interval or point
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Represents an interval with a start and end
|
|
7
|
+
*/
|
|
8
|
+
export interface Interval {
|
|
9
|
+
/** Start of the interval (inclusive) */
|
|
10
|
+
start: number;
|
|
11
|
+
/** End of the interval (inclusive) */
|
|
12
|
+
end: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* An interval with associated data
|
|
16
|
+
*/
|
|
17
|
+
export interface IntervalData<T> extends Interval {
|
|
18
|
+
/** User data associated with this interval */
|
|
19
|
+
data: T;
|
|
20
|
+
/** Optional unique identifier */
|
|
21
|
+
id?: string | number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Interval Tree interface
|
|
25
|
+
*
|
|
26
|
+
* An augmented binary search tree for efficient interval queries.
|
|
27
|
+
* Each node stores an interval and the maximum endpoint in its subtree.
|
|
28
|
+
*
|
|
29
|
+
* Use cases:
|
|
30
|
+
* - Finding all overlapping time ranges
|
|
31
|
+
* - Range queries in calendars/schedules
|
|
32
|
+
* - Collision detection (e.g., overlapping cells in a grid)
|
|
33
|
+
* - Finding visible rows/columns in virtual scrolling
|
|
34
|
+
* - Query optimization (index range scans)
|
|
35
|
+
*
|
|
36
|
+
* Performance:
|
|
37
|
+
* - Insert: O(log n) average, O(n) worst case (use Red-Black tree for guaranteed O(log n))
|
|
38
|
+
* - Delete: O(log n) average
|
|
39
|
+
* - Search overlapping: O(log n + k) where k = number of results
|
|
40
|
+
* - Point query: O(log n + k)
|
|
41
|
+
* - Space: O(n)
|
|
42
|
+
*/
|
|
43
|
+
export interface IIntervalTree<T> {
|
|
44
|
+
/**
|
|
45
|
+
* Insert an interval with associated data
|
|
46
|
+
* @param interval - The interval to insert
|
|
47
|
+
* @param data - Data to associate with the interval
|
|
48
|
+
* @returns The inserted interval with data
|
|
49
|
+
* @complexity O(log n) average
|
|
50
|
+
*/
|
|
51
|
+
insert(interval: Interval, data: T): IntervalData<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Delete an interval by reference
|
|
54
|
+
* @param intervalData - The interval to delete
|
|
55
|
+
* @returns true if found and deleted
|
|
56
|
+
* @complexity O(log n)
|
|
57
|
+
*/
|
|
58
|
+
delete(intervalData: IntervalData<T>): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Delete an interval by ID
|
|
61
|
+
* @param id - The ID of the interval to delete
|
|
62
|
+
* @returns true if found and deleted
|
|
63
|
+
* @complexity O(n) - requires linear search
|
|
64
|
+
*/
|
|
65
|
+
deleteById(id: string | number): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Find all intervals that overlap with the given interval
|
|
68
|
+
* @param interval - The query interval
|
|
69
|
+
* @returns Array of overlapping intervals
|
|
70
|
+
* @complexity O(log n + k) where k = number of results
|
|
71
|
+
*/
|
|
72
|
+
search(interval: Interval): IntervalData<T>[];
|
|
73
|
+
/**
|
|
74
|
+
* Find all intervals that contain the given point
|
|
75
|
+
* @param point - The point to query
|
|
76
|
+
* @returns Array of intervals containing the point
|
|
77
|
+
* @complexity O(log n + k) where k = number of results
|
|
78
|
+
*/
|
|
79
|
+
searchPoint(point: number): IntervalData<T>[];
|
|
80
|
+
/**
|
|
81
|
+
* Find all intervals that are completely contained within the given interval
|
|
82
|
+
* @param interval - The containing interval
|
|
83
|
+
* @returns Array of contained intervals
|
|
84
|
+
* @complexity O(n) worst case
|
|
85
|
+
*/
|
|
86
|
+
searchContained(interval: Interval): IntervalData<T>[];
|
|
87
|
+
/**
|
|
88
|
+
* Find all intervals that completely contain the given interval
|
|
89
|
+
* @param interval - The interval to be contained
|
|
90
|
+
* @returns Array of containing intervals
|
|
91
|
+
* @complexity O(n) worst case
|
|
92
|
+
*/
|
|
93
|
+
searchContaining(interval: Interval): IntervalData<T>[];
|
|
94
|
+
/**
|
|
95
|
+
* Find the interval with the earliest start time
|
|
96
|
+
* @returns The interval or undefined if tree is empty
|
|
97
|
+
* @complexity O(log n)
|
|
98
|
+
*/
|
|
99
|
+
findMin(): IntervalData<T> | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* Find the interval with the latest end time
|
|
102
|
+
* @returns The interval or undefined if tree is empty
|
|
103
|
+
* @complexity O(log n)
|
|
104
|
+
*/
|
|
105
|
+
findMax(): IntervalData<T> | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Check if any interval overlaps with the given interval
|
|
108
|
+
* @param interval - The query interval
|
|
109
|
+
* @complexity O(log n)
|
|
110
|
+
*/
|
|
111
|
+
hasOverlap(interval: Interval): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Get all intervals in sorted order (by start time)
|
|
114
|
+
* @returns Array of all intervals sorted by start
|
|
115
|
+
* @complexity O(n)
|
|
116
|
+
*/
|
|
117
|
+
inorder(): IntervalData<T>[];
|
|
118
|
+
/**
|
|
119
|
+
* Iterate over all intervals in sorted order
|
|
120
|
+
* @param callback - Function to call for each interval
|
|
121
|
+
* @complexity O(n)
|
|
122
|
+
*/
|
|
123
|
+
forEach(callback: (interval: IntervalData<T>) => void): void;
|
|
124
|
+
/**
|
|
125
|
+
* Filter intervals by a predicate
|
|
126
|
+
* @param predicate - Test function
|
|
127
|
+
* @returns New interval tree with intervals that pass the test
|
|
128
|
+
* @complexity O(n)
|
|
129
|
+
*/
|
|
130
|
+
filter(predicate: (interval: IntervalData<T>) => boolean): IIntervalTree<T>;
|
|
131
|
+
/**
|
|
132
|
+
* Map intervals to a new interval tree
|
|
133
|
+
* @param mapper - Transform function for the data
|
|
134
|
+
* @returns New interval tree with transformed data
|
|
135
|
+
* @complexity O(n)
|
|
136
|
+
*/
|
|
137
|
+
map<U>(mapper: (data: T, interval: Interval) => U): IIntervalTree<U>;
|
|
138
|
+
/**
|
|
139
|
+
* Clear all intervals
|
|
140
|
+
* @complexity O(1)
|
|
141
|
+
*/
|
|
142
|
+
clear(): void;
|
|
143
|
+
/**
|
|
144
|
+
* Number of intervals in the tree
|
|
145
|
+
*/
|
|
146
|
+
readonly size: number;
|
|
147
|
+
/**
|
|
148
|
+
* Whether the tree is empty
|
|
149
|
+
*/
|
|
150
|
+
readonly isEmpty: boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Height of the tree (for debugging/analysis)
|
|
153
|
+
*/
|
|
154
|
+
readonly height: number;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Options for creating an IntervalTree
|
|
158
|
+
*/
|
|
159
|
+
export interface IntervalTreeOptions {
|
|
160
|
+
/**
|
|
161
|
+
* Whether to use a balanced tree (Red-Black tree)
|
|
162
|
+
* Guarantees O(log n) operations but slightly slower constants
|
|
163
|
+
* @default false (uses simple BST)
|
|
164
|
+
*/
|
|
165
|
+
balanced?: boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Whether to allow duplicate intervals
|
|
168
|
+
* @default true
|
|
169
|
+
*/
|
|
170
|
+
allowDuplicates?: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* Custom comparator for intervals
|
|
173
|
+
* Defaults to comparing by start time, then end time
|
|
174
|
+
*/
|
|
175
|
+
comparator?: (a: Interval, b: Interval) => number;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Helper functions for interval operations
|
|
179
|
+
*/
|
|
180
|
+
export declare const IntervalUtils: {
|
|
181
|
+
/**
|
|
182
|
+
* Check if two intervals overlap
|
|
183
|
+
*/
|
|
184
|
+
overlaps(a: Interval, b: Interval): boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Check if interval contains a point
|
|
187
|
+
*/
|
|
188
|
+
contains(interval: Interval, point: number): boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Check if interval A contains interval B
|
|
191
|
+
*/
|
|
192
|
+
containsInterval(a: Interval, b: Interval): boolean;
|
|
193
|
+
/**
|
|
194
|
+
* Get the intersection of two intervals
|
|
195
|
+
* Returns undefined if they don't overlap
|
|
196
|
+
*/
|
|
197
|
+
intersection(a: Interval, b: Interval): Interval | undefined;
|
|
198
|
+
/**
|
|
199
|
+
* Get the union of two overlapping intervals
|
|
200
|
+
* Returns undefined if they don't overlap
|
|
201
|
+
*/
|
|
202
|
+
union(a: Interval, b: Interval): Interval | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* Merge overlapping intervals
|
|
205
|
+
*/
|
|
206
|
+
mergeOverlapping(intervals: Interval[]): Interval[];
|
|
207
|
+
/**
|
|
208
|
+
* Default comparator: compare by start, then by end
|
|
209
|
+
*/
|
|
210
|
+
defaultComparator(a: Interval, b: Interval): number;
|
|
211
|
+
};
|
|
212
|
+
//# sourceMappingURL=interval-tree.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interval-tree.interface.d.ts","sourceRoot":"","sources":["../../../../src/data-structures/interval-tree/interval-tree.interface.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/data-structures/lru-cache/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EACV,SAAS,EACT,eAAe,EACf,UAAU,EACV,UAAU,GACX,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { ILRUCache, LRUCacheOptions, CacheEntry, CacheStats } from './lru-cache.interface';
|
|
2
|
+
/**
|
|
3
|
+
* LRU Cache - Least Recently Used Cache
|
|
4
|
+
*
|
|
5
|
+
* A cache with automatic eviction of least recently used entries.
|
|
6
|
+
* Uses doubly-linked list + hash map for O(1) operations.
|
|
7
|
+
*
|
|
8
|
+
* **Time Complexity:**
|
|
9
|
+
* - get: O(1)
|
|
10
|
+
* - set: O(1)
|
|
11
|
+
* - delete: O(1)
|
|
12
|
+
* - has: O(1)
|
|
13
|
+
* - clear: O(n)
|
|
14
|
+
*
|
|
15
|
+
* **Space Complexity:** O(n) where n = number of entries
|
|
16
|
+
*
|
|
17
|
+
* **Use Cases in Grid:**
|
|
18
|
+
* - Cache rendered cells: Avoid re-rendering visible cells
|
|
19
|
+
* - Cache formula results: =SUM(A1:A1000) computed once
|
|
20
|
+
* - Cache formatted values: "$1,234.56" cached instead of re-formatting
|
|
21
|
+
* - Cache API responses: Reduce server requests
|
|
22
|
+
*
|
|
23
|
+
* @example Cell Rendering Cache
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const cellCache = new LRUCache<string, HTMLElement>({ capacity: 500 });
|
|
26
|
+
*
|
|
27
|
+
* function renderCell(row: number, col: number): HTMLElement {
|
|
28
|
+
* const key = `${row},${col}`;
|
|
29
|
+
* let element = cellCache.get(key);
|
|
30
|
+
*
|
|
31
|
+
* if (!element) {
|
|
32
|
+
* element = createCellElement(row, col); // Expensive operation
|
|
33
|
+
* cellCache.set(key, element);
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* return element;
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example Formula Cache
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const formulaCache = new LRUCache<string, number>({
|
|
43
|
+
* capacity: 1000,
|
|
44
|
+
* ttl: 5000, // 5 seconds
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* function evaluateFormula(formula: string): number {
|
|
48
|
+
* return formulaCache.get(formula) ?? computeFormula(formula);
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare class LRUCache<K, V> implements ILRUCache<K, V> {
|
|
53
|
+
private capacity;
|
|
54
|
+
private ttl;
|
|
55
|
+
private cache;
|
|
56
|
+
private head;
|
|
57
|
+
private tail;
|
|
58
|
+
private onEvict?;
|
|
59
|
+
private trackStats;
|
|
60
|
+
private hits;
|
|
61
|
+
private misses;
|
|
62
|
+
private evictions;
|
|
63
|
+
private sets;
|
|
64
|
+
constructor(options?: LRUCacheOptions);
|
|
65
|
+
/**
|
|
66
|
+
* Get a value from the cache
|
|
67
|
+
*/
|
|
68
|
+
get(key: K): V | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Set a value in the cache
|
|
71
|
+
*/
|
|
72
|
+
set(key: K, value: V): void;
|
|
73
|
+
/**
|
|
74
|
+
* Check if a key exists
|
|
75
|
+
*/
|
|
76
|
+
has(key: K): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Delete a specific entry
|
|
79
|
+
*/
|
|
80
|
+
delete(key: K): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Clear all entries
|
|
83
|
+
*/
|
|
84
|
+
clear(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Get current size
|
|
87
|
+
*/
|
|
88
|
+
size(): number;
|
|
89
|
+
/**
|
|
90
|
+
* Get statistics
|
|
91
|
+
*/
|
|
92
|
+
getStats(): CacheStats;
|
|
93
|
+
/**
|
|
94
|
+
* Get all keys (oldest to newest)
|
|
95
|
+
*/
|
|
96
|
+
keys(): K[];
|
|
97
|
+
/**
|
|
98
|
+
* Get all values (oldest to newest)
|
|
99
|
+
*/
|
|
100
|
+
values(): V[];
|
|
101
|
+
/**
|
|
102
|
+
* Get all entries with metadata
|
|
103
|
+
*/
|
|
104
|
+
entries(): Array<[K, CacheEntry<V>]>;
|
|
105
|
+
/**
|
|
106
|
+
* Peek without updating LRU order
|
|
107
|
+
*/
|
|
108
|
+
peek(key: K): V | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Resize cache capacity
|
|
111
|
+
*/
|
|
112
|
+
resize(newCapacity: number): void;
|
|
113
|
+
/**
|
|
114
|
+
* Check if a node is expired
|
|
115
|
+
*/
|
|
116
|
+
private isExpired;
|
|
117
|
+
/**
|
|
118
|
+
* Move node to head (most recently used)
|
|
119
|
+
*/
|
|
120
|
+
private moveToHead;
|
|
121
|
+
/**
|
|
122
|
+
* Add node to head
|
|
123
|
+
*/
|
|
124
|
+
private addToHead;
|
|
125
|
+
/**
|
|
126
|
+
* Remove node from list
|
|
127
|
+
*/
|
|
128
|
+
private removeNode;
|
|
129
|
+
/**
|
|
130
|
+
* Evict least recently used entry
|
|
131
|
+
*/
|
|
132
|
+
private evictLRU;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=lru-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lru-cache.d.ts","sourceRoot":"","sources":["../../../../src/data-structures/lru-cache/lru-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,eAAe,EACf,UAAU,EACV,UAAU,EACX,MAAM,uBAAuB,CAAC;AAiB/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,qBAAa,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAE,YAAW,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC;IACpD,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,KAAK,CAAwB;IACrC,OAAO,CAAC,IAAI,CAA8B;IAC1C,OAAO,CAAC,IAAI,CAA8B;IAC1C,OAAO,CAAC,OAAO,CAAC,CAA6B;IAC7C,OAAO,CAAC,UAAU,CAAU;IAG5B,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,IAAI,CAAa;gBAEb,OAAO,GAAE,eAAoB;IAYzC;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IA0B1B;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAyB3B;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAYpB;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAUvB;;OAEG;IACH,KAAK,IAAI,IAAI;IAab;;OAEG;IACH,IAAI,IAAI,MAAM;IAId;;OAEG;IACH,QAAQ,IAAI,UAAU;IAsBtB;;OAEG;IACH,IAAI,IAAI,CAAC,EAAE;IAYX;;OAEG;IACH,MAAM,IAAI,CAAC,EAAE;IAYb;;OAEG;IACH,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAoBpC;;OAEG;IACH,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAa3B;;OAEG;IACH,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAejC;;OAEG;IACH,OAAO,CAAC,SAAS;IAKjB;;OAEG;IACH,OAAO,CAAC,UAAU;IAOlB;;OAEG;IACH,OAAO,CAAC,SAAS;IAejB;;OAEG;IACH,OAAO,CAAC,UAAU;IAclB;;OAEG;IACH,OAAO,CAAC,QAAQ;CAcjB"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LRU Cache Interface
|
|
3
|
+
*
|
|
4
|
+
* Used for:
|
|
5
|
+
* - Caching rendered cells to avoid re-rendering
|
|
6
|
+
* - Caching formula evaluation results
|
|
7
|
+
* - Caching formatted values (numbers, dates)
|
|
8
|
+
* - Caching API responses
|
|
9
|
+
* - Memory-bounded caches with automatic eviction
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Cache entry metadata
|
|
13
|
+
*/
|
|
14
|
+
export interface CacheEntry<V> {
|
|
15
|
+
/**
|
|
16
|
+
* The cached value
|
|
17
|
+
*/
|
|
18
|
+
value: V;
|
|
19
|
+
/**
|
|
20
|
+
* Timestamp when entry was created
|
|
21
|
+
*/
|
|
22
|
+
createdAt: number;
|
|
23
|
+
/**
|
|
24
|
+
* Timestamp when entry was last accessed
|
|
25
|
+
*/
|
|
26
|
+
lastAccessedAt: number;
|
|
27
|
+
/**
|
|
28
|
+
* Number of times this entry has been accessed
|
|
29
|
+
*/
|
|
30
|
+
accessCount: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Cache statistics
|
|
34
|
+
*/
|
|
35
|
+
export interface CacheStats {
|
|
36
|
+
/**
|
|
37
|
+
* Current number of entries
|
|
38
|
+
*/
|
|
39
|
+
size: number;
|
|
40
|
+
/**
|
|
41
|
+
* Maximum capacity
|
|
42
|
+
*/
|
|
43
|
+
capacity: number;
|
|
44
|
+
/**
|
|
45
|
+
* Total number of get operations
|
|
46
|
+
*/
|
|
47
|
+
hits: number;
|
|
48
|
+
/**
|
|
49
|
+
* Total number of failed get operations
|
|
50
|
+
*/
|
|
51
|
+
misses: number;
|
|
52
|
+
/**
|
|
53
|
+
* Hit rate (hits / (hits + misses))
|
|
54
|
+
*/
|
|
55
|
+
hitRate: number;
|
|
56
|
+
/**
|
|
57
|
+
* Total number of evictions
|
|
58
|
+
*/
|
|
59
|
+
evictions: number;
|
|
60
|
+
/**
|
|
61
|
+
* Total number of set operations
|
|
62
|
+
*/
|
|
63
|
+
sets: number;
|
|
64
|
+
/**
|
|
65
|
+
* Memory usage in bytes (approximate)
|
|
66
|
+
*/
|
|
67
|
+
memoryBytes: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* LRU Cache options
|
|
71
|
+
*/
|
|
72
|
+
export interface LRUCacheOptions {
|
|
73
|
+
/**
|
|
74
|
+
* Maximum number of entries
|
|
75
|
+
* @default 1000
|
|
76
|
+
*/
|
|
77
|
+
capacity?: number;
|
|
78
|
+
/**
|
|
79
|
+
* Time-to-live in milliseconds (0 = infinite)
|
|
80
|
+
* @default 0
|
|
81
|
+
*/
|
|
82
|
+
ttl?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Callback when an entry is evicted
|
|
85
|
+
*/
|
|
86
|
+
onEvict?: <K, V>(key: K, value: V) => void;
|
|
87
|
+
/**
|
|
88
|
+
* Track access statistics
|
|
89
|
+
* @default false
|
|
90
|
+
*/
|
|
91
|
+
trackStats?: boolean;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* LRU Cache interface
|
|
95
|
+
*/
|
|
96
|
+
export interface ILRUCache<K, V> {
|
|
97
|
+
/**
|
|
98
|
+
* Get a value from the cache
|
|
99
|
+
*
|
|
100
|
+
* @param key - The key to look up
|
|
101
|
+
* @returns The cached value or undefined if not found or expired
|
|
102
|
+
*/
|
|
103
|
+
get(key: K): V | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Set a value in the cache
|
|
106
|
+
*
|
|
107
|
+
* @param key - The key to store
|
|
108
|
+
* @param value - The value to cache
|
|
109
|
+
*/
|
|
110
|
+
set(key: K, value: V): void;
|
|
111
|
+
/**
|
|
112
|
+
* Check if a key exists in the cache
|
|
113
|
+
*
|
|
114
|
+
* @param key - The key to check
|
|
115
|
+
* @returns True if the key exists and is not expired
|
|
116
|
+
*/
|
|
117
|
+
has(key: K): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Delete a specific entry
|
|
120
|
+
*
|
|
121
|
+
* @param key - The key to delete
|
|
122
|
+
* @returns True if the entry existed and was deleted
|
|
123
|
+
*/
|
|
124
|
+
delete(key: K): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Clear all entries from the cache
|
|
127
|
+
*/
|
|
128
|
+
clear(): void;
|
|
129
|
+
/**
|
|
130
|
+
* Get the current size of the cache
|
|
131
|
+
*
|
|
132
|
+
* @returns Number of entries
|
|
133
|
+
*/
|
|
134
|
+
size(): number;
|
|
135
|
+
/**
|
|
136
|
+
* Get cache statistics
|
|
137
|
+
*
|
|
138
|
+
* @returns Statistics object
|
|
139
|
+
*/
|
|
140
|
+
getStats(): CacheStats;
|
|
141
|
+
/**
|
|
142
|
+
* Get all keys in the cache (in LRU order)
|
|
143
|
+
*
|
|
144
|
+
* @returns Array of keys, oldest first
|
|
145
|
+
*/
|
|
146
|
+
keys(): K[];
|
|
147
|
+
/**
|
|
148
|
+
* Get all values in the cache (in LRU order)
|
|
149
|
+
*
|
|
150
|
+
* @returns Array of values, oldest first
|
|
151
|
+
*/
|
|
152
|
+
values(): V[];
|
|
153
|
+
/**
|
|
154
|
+
* Get all entries with metadata
|
|
155
|
+
*
|
|
156
|
+
* @returns Array of entries with metadata
|
|
157
|
+
*/
|
|
158
|
+
entries(): Array<[K, CacheEntry<V>]>;
|
|
159
|
+
/**
|
|
160
|
+
* Peek at a value without updating LRU order
|
|
161
|
+
*
|
|
162
|
+
* @param key - The key to peek at
|
|
163
|
+
* @returns The cached value or undefined
|
|
164
|
+
*/
|
|
165
|
+
peek(key: K): V | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* Resize the cache capacity
|
|
168
|
+
*
|
|
169
|
+
* @param newCapacity - New maximum capacity
|
|
170
|
+
*/
|
|
171
|
+
resize(newCapacity: number): void;
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=lru-cache.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lru-cache.interface.d.ts","sourceRoot":"","sources":["../../../../src/data-structures/lru-cache/lru-cache.interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B;;OAEG;IACH,KAAK,EAAE,CAAC,CAAC;IAET;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAE3C;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,EAAE,CAAC;IAC7B;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAE3B;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IAE5B;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC;IAErB;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC;IAExB;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;IAEd;;;;OAIG;IACH,IAAI,IAAI,MAAM,CAAC;IAEf;;;;OAIG;IACH,QAAQ,IAAI,UAAU,CAAC;IAEvB;;;;OAIG;IACH,IAAI,IAAI,CAAC,EAAE,CAAC;IAEZ;;;;OAIG;IACH,MAAM,IAAI,CAAC,EAAE,CAAC;IAEd;;;;OAIG;IACH,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAErC;;;;;OAKG;IACH,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAE5B;;;;OAIG;IACH,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prefix Sum Array - Efficient range queries and offset calculations
|
|
3
|
+
*/
|
|
4
|
+
export { PrefixSumArray } from './prefix-sum-array';
|
|
5
|
+
export type { PrefixSumArray as IPrefixSumArray, PrefixSumArrayOptions, } from './prefix-sum-array.interface';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/data-structures/prefix-sum-array/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,YAAY,EACV,cAAc,IAAI,eAAe,EACjC,qBAAqB,GACtB,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { PrefixSumArray as IPrefixSumArray, PrefixSumArrayOptions } from './prefix-sum-array.interface';
|
|
2
|
+
/**
|
|
3
|
+
* PrefixSumArray implementation
|
|
4
|
+
*
|
|
5
|
+
* Stores cumulative sums for efficient range queries and offset lookups.
|
|
6
|
+
* Essential for virtual scrolling with variable row heights.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Row heights: [30, 40, 50, 30, 60]
|
|
11
|
+
* const heights = new PrefixSumArray({ values: [30, 40, 50, 30, 60] });
|
|
12
|
+
*
|
|
13
|
+
* // Get offset to row 2 (sum of rows 0 and 1)
|
|
14
|
+
* heights.getOffset(2); // 70 (30 + 40)
|
|
15
|
+
*
|
|
16
|
+
* // Find which row is at scroll offset 100
|
|
17
|
+
* heights.findIndexAtOffset(100); // 2 (rows 0,1,2 total 120, row 2 starts at 70)
|
|
18
|
+
*
|
|
19
|
+
* // Get range sum (rows 1-3)
|
|
20
|
+
* heights.getRangeSum(1, 4); // 120 (40 + 50 + 30)
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare class PrefixSumArray implements IPrefixSumArray {
|
|
24
|
+
private values;
|
|
25
|
+
private sums;
|
|
26
|
+
constructor(options?: PrefixSumArrayOptions);
|
|
27
|
+
/**
|
|
28
|
+
* Build prefix sum array from values
|
|
29
|
+
* sums[i] = sum of values[0...i-1]
|
|
30
|
+
* sums[0] = 0 (no elements before index 0)
|
|
31
|
+
*/
|
|
32
|
+
private build;
|
|
33
|
+
getOffset(index: number): number;
|
|
34
|
+
getSumUpTo(index: number): number;
|
|
35
|
+
getRangeSum(start: number, end: number): number;
|
|
36
|
+
findIndexAtOffset(offset: number): number;
|
|
37
|
+
update(index: number, newValue: number): void;
|
|
38
|
+
getValue(index: number): number;
|
|
39
|
+
get length(): number;
|
|
40
|
+
get total(): number;
|
|
41
|
+
get prefixSums(): ReadonlyArray<number>;
|
|
42
|
+
/**
|
|
43
|
+
* Add a new value to the end
|
|
44
|
+
* @param value - Value to append
|
|
45
|
+
*/
|
|
46
|
+
push(value: number): void;
|
|
47
|
+
/**
|
|
48
|
+
* Remove and return the last value
|
|
49
|
+
* @returns Removed value or undefined if empty
|
|
50
|
+
*/
|
|
51
|
+
pop(): number | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Clear all values
|
|
54
|
+
*/
|
|
55
|
+
clear(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Create from array of values
|
|
58
|
+
* @param values - Array of non-negative numbers
|
|
59
|
+
* @returns New PrefixSumArray instance
|
|
60
|
+
*/
|
|
61
|
+
static from(values: number[]): PrefixSumArray;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=prefix-sum-array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefix-sum-array.d.ts","sourceRoot":"","sources":["../../../../src/data-structures/prefix-sum-array/prefix-sum-array.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,IAAI,eAAe,EACjC,qBAAqB,EACtB,MAAM,8BAA8B,CAAC;AAGtC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,cAAe,YAAW,eAAe;IACpD,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,IAAI,CAAW;gBAEX,OAAO,GAAE,qBAA0B;IAM/C;;;;OAIG;IACH,OAAO,CAAC,KAAK;IASb,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAShC,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IASjC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAS/C,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IA6BzC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAoB7C,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAS/B,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,IAAI,UAAU,IAAI,aAAa,CAAC,MAAM,CAAC,CAEtC;IAED;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IASzB;;;OAGG;IACH,GAAG,IAAI,MAAM,GAAG,SAAS;IASzB;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc;CAG9C"}
|