max-priority-queue-typed 2.4.5 → 2.5.1
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 +63 -0
- package/dist/cjs/index.cjs +694 -119
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +693 -118
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +694 -119
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +693 -118
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +380 -51
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +487 -147
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +956 -80
- package/dist/types/data-structures/binary-tree/bst.d.ts +816 -29
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +610 -31
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +326 -135
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3781 -6
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3607 -201
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2874 -65
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3528 -6
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +429 -47
- package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +393 -59
- package/dist/types/data-structures/hash/hash-map.d.ts +473 -89
- package/dist/types/data-structures/heap/heap.d.ts +581 -99
- package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +646 -47
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +596 -68
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +793 -12
- package/dist/types/data-structures/matrix/matrix.d.ts +499 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
- package/dist/types/data-structures/queue/deque.d.ts +593 -71
- package/dist/types/data-structures/queue/queue.d.ts +463 -42
- package/dist/types/data-structures/stack/stack.d.ts +384 -32
- package/dist/types/data-structures/trie/trie.d.ts +470 -48
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/max-priority-queue-typed.js +691 -116
- package/dist/umd/max-priority-queue-typed.js.map +1 -1
- package/dist/umd/max-priority-queue-typed.min.js +1 -1
- package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +4 -5
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +386 -51
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +596 -247
- package/src/data-structures/binary-tree/binary-tree.ts +956 -81
- package/src/data-structures/binary-tree/bst.ts +840 -35
- package/src/data-structures/binary-tree/red-black-tree.ts +689 -97
- package/src/data-structures/binary-tree/segment-tree.ts +498 -249
- package/src/data-structures/binary-tree/tree-map.ts +3784 -7
- package/src/data-structures/binary-tree/tree-multi-map.ts +3614 -211
- package/src/data-structures/binary-tree/tree-multi-set.ts +2874 -65
- package/src/data-structures/binary-tree/tree-set.ts +3531 -10
- package/src/data-structures/graph/abstract-graph.ts +4 -4
- package/src/data-structures/graph/directed-graph.ts +429 -47
- package/src/data-structures/graph/map-graph.ts +59 -1
- package/src/data-structures/graph/undirected-graph.ts +393 -59
- package/src/data-structures/hash/hash-map.ts +476 -92
- package/src/data-structures/heap/heap.ts +581 -99
- package/src/data-structures/heap/max-heap.ts +46 -0
- package/src/data-structures/heap/min-heap.ts +59 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +646 -47
- package/src/data-structures/linked-list/singly-linked-list.ts +596 -68
- package/src/data-structures/linked-list/skip-linked-list.ts +1067 -90
- package/src/data-structures/matrix/matrix.ts +584 -12
- package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
- package/src/data-structures/priority-queue/priority-queue.ts +60 -0
- package/src/data-structures/queue/deque.ts +592 -70
- package/src/data-structures/queue/queue.ts +463 -42
- package/src/data-structures/stack/stack.ts +384 -32
- package/src/data-structures/trie/trie.ts +470 -48
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
|
@@ -2,159 +2,350 @@
|
|
|
2
2
|
* data-structure-typed
|
|
3
3
|
*
|
|
4
4
|
* @author Pablo Zeng
|
|
5
|
-
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
5
|
* @license MIT License
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
protected
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
* @returns The value of the protected property `_end`.
|
|
37
|
-
*/
|
|
38
|
-
get end(): number;
|
|
39
|
-
/**
|
|
40
|
-
* The above function sets the value of the "end" property.
|
|
41
|
-
* @param {number} value - The value parameter is a number that represents the new value for the end
|
|
42
|
-
* property.
|
|
43
|
-
*/
|
|
44
|
-
set end(value: number);
|
|
45
|
-
protected _value: SegmentTreeNodeVal | undefined;
|
|
46
|
-
/**
|
|
47
|
-
* The function returns the value of a segment tree node.
|
|
48
|
-
* @returns The value being returned is either a `SegmentTreeNodeVal` object or `undefined`.
|
|
49
|
-
*/
|
|
50
|
-
get value(): SegmentTreeNodeVal | undefined;
|
|
51
|
-
/**
|
|
52
|
-
* The function sets the value of a segment tree node.
|
|
53
|
-
* @param {SegmentTreeNodeVal | undefined} value - The `value` parameter is of type
|
|
54
|
-
* `SegmentTreeNodeVal` or `undefined`.
|
|
55
|
-
*/
|
|
56
|
-
set value(value: SegmentTreeNodeVal | undefined);
|
|
57
|
-
protected _sum: number;
|
|
58
|
-
/**
|
|
59
|
-
* The function returns the value of the sum property.
|
|
60
|
-
* @returns The method is returning the value of the variable `_sum`.
|
|
61
|
-
*/
|
|
62
|
-
get sum(): number;
|
|
63
|
-
/**
|
|
64
|
-
* The above function sets the value of the sum property.
|
|
65
|
-
* @param {number} value - The parameter "value" is of type "number".
|
|
66
|
-
*/
|
|
67
|
-
set sum(value: number);
|
|
68
|
-
protected _left: SegmentTreeNode | undefined;
|
|
69
|
-
/**
|
|
70
|
-
* The function returns the left child of a segment tree node.
|
|
71
|
-
* @returns The `left` property of the `SegmentTreeNode` object is being returned. It is of type
|
|
72
|
-
* `SegmentTreeNode` or `undefined`.
|
|
73
|
-
*/
|
|
74
|
-
get left(): SegmentTreeNode | undefined;
|
|
75
|
-
/**
|
|
76
|
-
* The function sets the value of the left property of a SegmentTreeNode object.
|
|
77
|
-
* @param {SegmentTreeNode | undefined} value - The value parameter is of type SegmentTreeNode or
|
|
78
|
-
* undefined.
|
|
79
|
-
*/
|
|
80
|
-
set left(value: SegmentTreeNode | undefined);
|
|
81
|
-
protected _right: SegmentTreeNode | undefined;
|
|
82
|
-
/**
|
|
83
|
-
* The function returns the right child of a segment tree node.
|
|
84
|
-
* @returns The `getRight()` method is returning a value of type `SegmentTreeNode` or `undefined`.
|
|
85
|
-
*/
|
|
86
|
-
get right(): SegmentTreeNode | undefined;
|
|
7
|
+
export type SegmentTreeOptions<E> = {
|
|
8
|
+
merger: (a: E, b: E) => E;
|
|
9
|
+
identity: E;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Generic Segment Tree with flat array internals.
|
|
13
|
+
*
|
|
14
|
+
* Supports any associative merge operation (sum, min, max, gcd, etc.).
|
|
15
|
+
* Reference: AtCoder Library segtree<S, op, e>.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const sumTree = SegmentTree.sum([1, 2, 3, 4, 5]);
|
|
20
|
+
* sumTree.query(1, 3); // 9 (2+3+4)
|
|
21
|
+
* sumTree.update(2, 10); // [1, 2, 10, 4, 5]
|
|
22
|
+
* sumTree.query(1, 3); // 16 (2+10+4)
|
|
23
|
+
*
|
|
24
|
+
* const minTree = SegmentTree.min([5, 2, 8, 1, 9]);
|
|
25
|
+
* minTree.query(0, 4); // 1
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
29
|
+
protected readonly _merger: (a: E, b: E) => E;
|
|
30
|
+
protected readonly _identity: E;
|
|
31
|
+
protected _n: number;
|
|
32
|
+
protected _tree: E[];
|
|
33
|
+
protected _treeSize: number;
|
|
34
|
+
constructor(elements: E[], options: SegmentTreeOptions<E>);
|
|
87
35
|
/**
|
|
88
|
-
*
|
|
89
|
-
* @
|
|
90
|
-
*
|
|
91
|
-
*
|
|
36
|
+
* Create a sum segment tree.
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const st = SegmentTree.sum([1, 2, 3, 4, 5]);
|
|
40
|
+
* st.query(0, 2); // 6 (1+2+3)
|
|
41
|
+
* st.update(1, 10);
|
|
42
|
+
* st.query(0, 2); // 14 (1+10+3)
|
|
43
|
+
* ```
|
|
92
44
|
*/
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
export declare class SegmentTree {
|
|
45
|
+
static sum(elements: number[]): SegmentTree<number>;
|
|
96
46
|
/**
|
|
97
|
-
*
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
47
|
+
* Create a min segment tree.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
* @example
|
|
81
|
+
* // Temperature monitoring with range queries
|
|
82
|
+
* // Hourly temperatures for a day (24 readings)
|
|
83
|
+
* const temps = [18, 17, 16, 15, 16, 18, 21, 24, 27, 29, 31, 32, 33, 32, 31, 29, 27, 25, 23, 21, 20, 19, 18, 17];
|
|
84
|
+
* const tree = SegmentTree.sum(temps);
|
|
85
|
+
*
|
|
86
|
+
* // Average temperature during work hours (9-17)
|
|
87
|
+
* const workSum = tree.query(9, 17);
|
|
88
|
+
* console.log(workSum / 9); // toBeCloseTo;
|
|
89
|
+
*
|
|
90
|
+
* // Sum of morning temps (6-11)
|
|
91
|
+
* console.log(tree.query(6, 11)); // 164;
|
|
104
92
|
*/
|
|
105
|
-
|
|
106
|
-
protected _values: number[];
|
|
93
|
+
static min(elements: number[]): SegmentTree<number>;
|
|
107
94
|
/**
|
|
108
|
-
*
|
|
109
|
-
* @
|
|
95
|
+
* Create a max segment tree.
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* const st = SegmentTree.max([3, 1, 4, 1, 5]);
|
|
99
|
+
* st.query(1, 4); // 5
|
|
100
|
+
* ```
|
|
110
101
|
*/
|
|
111
|
-
|
|
112
|
-
protected _start: number;
|
|
102
|
+
static max(elements: number[]): SegmentTree<number>;
|
|
113
103
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
104
|
+
* Point update: set element at index to value.
|
|
105
|
+
* Time: O(log n)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
* @example
|
|
139
|
+
* // Dynamic range sum with updates
|
|
140
|
+
* // Monthly revenue data (in thousands)
|
|
141
|
+
* const revenue = [120, 95, 140, 110, 85, 130, 150, 100, 160, 125, 90, 175];
|
|
142
|
+
* const tree = SegmentTree.sum(revenue);
|
|
143
|
+
*
|
|
144
|
+
* // Q1 revenue (Jan-Mar)
|
|
145
|
+
* console.log(tree.query(0, 2)); // 355;
|
|
146
|
+
*
|
|
147
|
+
* // Update March revenue from 140 to 200
|
|
148
|
+
* tree.update(2, 200);
|
|
149
|
+
*
|
|
150
|
+
* // Q1 revenue after update
|
|
151
|
+
* console.log(tree.query(0, 2)); // 415;
|
|
152
|
+
*
|
|
153
|
+
* // H1 revenue (Jan-Jun)
|
|
154
|
+
* console.log(tree.query(0, 5)); // 740;
|
|
116
155
|
*/
|
|
117
|
-
|
|
118
|
-
protected _end: number;
|
|
156
|
+
update(index: number, value: E): void;
|
|
119
157
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
158
|
+
* Range query: returns merger result over [start, end] (inclusive).
|
|
159
|
+
* Time: O(log n)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
* @example
|
|
193
|
+
* // Range sum query on an array
|
|
194
|
+
* const tree = SegmentTree.sum([1, 3, 5, 7, 9, 11]);
|
|
195
|
+
*
|
|
196
|
+
* // Query sum of range [1, 3] → 3 + 5 + 7 = 15
|
|
197
|
+
* console.log(tree.query(1, 3)); // 15;
|
|
198
|
+
*
|
|
199
|
+
* // Query entire range
|
|
200
|
+
* console.log(tree.query(0, 5)); // 36;
|
|
201
|
+
*
|
|
202
|
+
* // Query single element
|
|
203
|
+
* console.log(tree.query(2, 2)); // 5;
|
|
122
204
|
*/
|
|
123
|
-
|
|
124
|
-
protected _root: SegmentTreeNode | undefined;
|
|
205
|
+
query(start: number, end: number): E;
|
|
125
206
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
207
|
+
* Get element at index.
|
|
208
|
+
* Time: O(1)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
* @example
|
|
242
|
+
* // Point access on segment tree
|
|
243
|
+
* const st = SegmentTree.sum([10, 20, 30, 40]);
|
|
244
|
+
* console.log(st.get(0)); // 10;
|
|
245
|
+
* console.log(st.get(2)); // 30;
|
|
128
246
|
*/
|
|
129
|
-
get
|
|
247
|
+
get(index: number): E;
|
|
130
248
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
249
|
+
* Find the largest r such that predicate(query(left, r)) is true.
|
|
250
|
+
* Returns left-1 if predicate(identity) is false.
|
|
251
|
+
* Returns n-1 if predicate holds for the entire range [left, n-1].
|
|
252
|
+
* Time: O(log n)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
* @example
|
|
286
|
+
* // Find rightmost position where predicate holds
|
|
287
|
+
* // Prefix sums: find the rightmost index where prefix sum < 10
|
|
288
|
+
* const st = SegmentTree.sum([3, 1, 4, 1, 5]);
|
|
289
|
+
* // maxRight(0, sum => sum < 10) — prefix [3,4,8,9,14]
|
|
290
|
+
* // sum < 10 holds through index 3 (prefix=9), fails at 4 (prefix=14)
|
|
291
|
+
* const result = st.maxRight(0, sum => sum < 10);
|
|
292
|
+
* console.log(result); // 3;
|
|
138
293
|
*/
|
|
139
|
-
|
|
294
|
+
maxRight(left: number, predicate: (segValue: E) => boolean): number;
|
|
140
295
|
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
296
|
+
* Find the smallest l such that predicate(query(l, right)) is true.
|
|
297
|
+
* Returns right+1 if predicate(identity) is false.
|
|
298
|
+
* Returns 0 if predicate holds for the entire range [0, right].
|
|
299
|
+
* Time: O(log n)
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
* @example
|
|
333
|
+
* // Find leftmost position where predicate holds
|
|
334
|
+
* const st = SegmentTree.sum([3, 1, 4, 1, 5]);
|
|
335
|
+
* // minLeft(5, sum => sum < 7) — suffix sums from right
|
|
336
|
+
* // From right: [5]=5 < 7, [1,5]=6 < 7, [4,1,5]=10 ≥ 7
|
|
337
|
+
* const result = st.minLeft(5, sum => sum < 7);
|
|
338
|
+
* console.log(result); // 3;
|
|
150
339
|
*/
|
|
151
|
-
|
|
340
|
+
minLeft(right: number, predicate: (segValue: E) => boolean): number;
|
|
341
|
+
get size(): number;
|
|
342
|
+
isEmpty(): boolean;
|
|
343
|
+
clone(): SegmentTree<E>;
|
|
344
|
+
toArray(): E[];
|
|
152
345
|
/**
|
|
153
|
-
*
|
|
154
|
-
* @param {number} indexA - The starting index of the range for which you want to calculate the sum.
|
|
155
|
-
* @param {number} indexB - The parameter `indexB` represents the ending index of the range for which you want to
|
|
156
|
-
* calculate the sum.
|
|
157
|
-
* @returns The function `querySumByRange` returns a number.
|
|
346
|
+
* Iterates over leaf values in index order.
|
|
158
347
|
*/
|
|
159
|
-
|
|
348
|
+
[Symbol.iterator](): IterableIterator<E>;
|
|
349
|
+
forEach(callback: (value: E, index: number) => void): void;
|
|
350
|
+
print(): void;
|
|
160
351
|
}
|