binary-tree-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 +0 -84
- package/dist/cjs/index.cjs +1476 -404
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +1473 -401
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +1476 -404
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +1473 -401
- 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/binary-tree-typed.js +1469 -397
- package/dist/umd/binary-tree-typed.js.map +1 -1
- package/dist/umd/binary-tree-typed.min.js +5 -5
- package/dist/umd/binary-tree-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
|
@@ -1,174 +1,514 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Binary Indexed Tree (Fenwick Tree).
|
|
2
3
|
*
|
|
4
|
+
* Efficient prefix sums and point updates in O(log n).
|
|
5
|
+
* Standard array-based implementation per C++ competitive programming conventions.
|
|
6
|
+
*
|
|
7
|
+
* All indices are 0-based externally; internally converted to 1-based for BIT arithmetic.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const bit = new BinaryIndexedTree(6);
|
|
12
|
+
* bit.update(0, 3); // index 0 += 3
|
|
13
|
+
* bit.update(1, 2); // index 1 += 2
|
|
14
|
+
* bit.update(2, 7); // index 2 += 7
|
|
15
|
+
*
|
|
16
|
+
* bit.query(2); // prefix sum [0..2] = 12
|
|
17
|
+
* bit.queryRange(1, 2); // range sum [1..2] = 9
|
|
18
|
+
* bit.get(1); // point value at index 1 = 2
|
|
19
|
+
* ```
|
|
3
20
|
*/
|
|
4
|
-
export declare class BinaryIndexedTree {
|
|
5
|
-
protected readonly
|
|
6
|
-
protected
|
|
7
|
-
/**
|
|
8
|
-
* The constructor initializes the properties of an object, including default frequency, maximum
|
|
9
|
-
* value, a freqMap data structure, the most significant bit, and the count of negative frequencies.
|
|
10
|
-
* @param - - `frequency`: The default frequency value. It is optional and has a default
|
|
11
|
-
* value of 0.
|
|
12
|
-
*/
|
|
13
|
-
constructor({ frequency, max }: {
|
|
14
|
-
frequency?: number;
|
|
15
|
-
max: number;
|
|
16
|
-
});
|
|
17
|
-
protected _freqMap: Record<number, number>;
|
|
18
|
-
/**
|
|
19
|
-
* The function returns the frequency map of numbers.
|
|
20
|
-
* @returns The `_freqMap` property, which is a record with number keys and number values, is being
|
|
21
|
-
* returned.
|
|
22
|
-
*/
|
|
23
|
-
get freqMap(): Record<number, number>;
|
|
24
|
-
protected _msb: number;
|
|
21
|
+
export declare class BinaryIndexedTree implements Iterable<number> {
|
|
22
|
+
protected readonly _size: number;
|
|
23
|
+
protected _tree: number[];
|
|
25
24
|
/**
|
|
26
|
-
*
|
|
27
|
-
* @
|
|
25
|
+
* Construct a BIT of given size (all zeros), or from an initial values array.
|
|
26
|
+
* @param sizeOrElements - number of elements, or an array of initial values
|
|
28
27
|
*/
|
|
29
|
-
|
|
30
|
-
protected _negativeCount: number;
|
|
28
|
+
constructor(sizeOrElements: number | number[]);
|
|
31
29
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
|
|
30
|
+
* Point update: add delta to the value at index (0-based).
|
|
31
|
+
* Time: O(log n)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
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
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
* @example
|
|
89
|
+
* // Add delta at index
|
|
90
|
+
* const bit = new BinaryIndexedTree([1, 2, 3, 4, 5]);
|
|
91
|
+
* bit.update(2, 7);
|
|
92
|
+
* console.log(bit.get(2)); // 10;
|
|
35
93
|
*/
|
|
36
|
-
|
|
94
|
+
update(index: number, delta: number): void;
|
|
37
95
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
96
|
+
* Point set: set the value at index to an absolute value (0-based).
|
|
97
|
+
* Time: O(log n)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
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
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
* @example
|
|
156
|
+
* // Set value at index
|
|
157
|
+
* const bit = new BinaryIndexedTree([1, 2, 3]);
|
|
158
|
+
* bit.set(1, 10);
|
|
159
|
+
* console.log(bit.get(1)); // 10;
|
|
40
160
|
*/
|
|
41
|
-
|
|
161
|
+
set(index: number, value: number): void;
|
|
42
162
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
163
|
+
* Get the point value at index (0-based).
|
|
164
|
+
* Time: O(log n)
|
|
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
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
* @example
|
|
222
|
+
* // Get value at index
|
|
223
|
+
* const bit = new BinaryIndexedTree([1, 2, 3]);
|
|
224
|
+
* console.log(bit.get(0)); // 1;
|
|
225
|
+
* console.log(bit.get(2)); // 3;
|
|
45
226
|
*/
|
|
46
|
-
get
|
|
227
|
+
get(index: number): number;
|
|
47
228
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
|
|
51
|
-
|
|
229
|
+
* Prefix sum query: returns sum of elements [0..index] (inclusive, 0-based).
|
|
230
|
+
* Time: O(log n)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
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
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
* @example
|
|
289
|
+
* // Prefix sum
|
|
290
|
+
* const bit = new BinaryIndexedTree([1, 2, 3, 4]);
|
|
291
|
+
* console.log(bit.query(2)); // 6;
|
|
52
292
|
*/
|
|
53
|
-
|
|
293
|
+
query(index: number): number;
|
|
54
294
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
295
|
+
* Range sum query: returns sum of elements [start..end] (inclusive, 0-based).
|
|
296
|
+
* Time: O(log n)
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
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
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
* @example
|
|
354
|
+
* // Range sum
|
|
355
|
+
* const bit = new BinaryIndexedTree([1, 2, 3, 4]);
|
|
356
|
+
* console.log(bit.queryRange(1, 2)); // 5;
|
|
61
357
|
*/
|
|
62
|
-
|
|
358
|
+
queryRange(start: number, end: number): number;
|
|
63
359
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
360
|
+
* Find the smallest index i such that prefix sum [0..i] >= sum.
|
|
361
|
+
* Requires all values to be non-negative (behavior undefined otherwise).
|
|
362
|
+
* Returns size if no such index exists.
|
|
363
|
+
* Time: O(log n)
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
* @example
|
|
422
|
+
* // Find index with prefix sum ≥ target
|
|
423
|
+
* const bit = new BinaryIndexedTree([1, 2, 3, 4]);
|
|
424
|
+
* const idx = bit.lowerBound(4);
|
|
425
|
+
* console.log(idx); // >= 0;
|
|
84
426
|
*/
|
|
85
427
|
lowerBound(sum: number): number;
|
|
86
428
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
|
|
429
|
+
* Find the smallest index i such that prefix sum [0..i] > sum.
|
|
430
|
+
* Requires all values to be non-negative (behavior undefined otherwise).
|
|
431
|
+
* Returns size if no such index exists.
|
|
432
|
+
* Time: O(log n)
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
* @example
|
|
457
|
+
* // Find index with prefix sum > target
|
|
458
|
+
* const bit = new BinaryIndexedTree([1, 2, 3, 4]);
|
|
459
|
+
* const idx = bit.upperBound(4);
|
|
460
|
+
* console.log(idx); // >= 0;
|
|
92
461
|
*/
|
|
93
462
|
upperBound(sum: number): number;
|
|
463
|
+
get size(): number;
|
|
464
|
+
isEmpty(): boolean;
|
|
465
|
+
clear(): void;
|
|
466
|
+
clone(): BinaryIndexedTree;
|
|
94
467
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
468
|
+
* Returns the point values as a plain array.
|
|
469
|
+
* Time: O(n log n)
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
* @example
|
|
494
|
+
* // Convert to array
|
|
495
|
+
* const bit = new BinaryIndexedTree([1, 2, 3]);
|
|
496
|
+
* console.log(bit.toArray()); // [1, 2, 3];
|
|
100
497
|
*/
|
|
101
|
-
|
|
498
|
+
toArray(): number[];
|
|
102
499
|
/**
|
|
103
|
-
*
|
|
104
|
-
* the index is not found.
|
|
105
|
-
* @param {number} index - The `index` parameter is a number that represents the index of a node in a
|
|
106
|
-
* freqMap data structure.
|
|
107
|
-
* @returns a number.
|
|
108
|
-
*/
|
|
109
|
-
protected _getFrequency(index: number): number;
|
|
110
|
-
/**
|
|
111
|
-
* The function _updateFrequency adds a delta value to the element at the specified index in the freqMap array.
|
|
112
|
-
* @param {number} index - The index parameter is a number that represents the index of the freqMap
|
|
113
|
-
* element that needs to be updated.
|
|
114
|
-
* @param {number} delta - The `delta` parameter represents the change in value that needs to be
|
|
115
|
-
* added to the freqMap at the specified `index`.
|
|
116
|
-
*/
|
|
117
|
-
protected _updateFrequency(index: number, delta: number): void;
|
|
118
|
-
/**
|
|
119
|
-
* The function checks if the given index is valid and within the range.
|
|
120
|
-
* @param {number} index - The parameter "index" is of type number and represents the index value
|
|
121
|
-
* that needs to be checked.
|
|
500
|
+
* Iterate over point values in index order.
|
|
122
501
|
*/
|
|
502
|
+
[Symbol.iterator](): IterableIterator<number>;
|
|
503
|
+
forEach(callback: (value: number, index: number) => void): void;
|
|
504
|
+
print(): void;
|
|
505
|
+
/** 1-based prefix sum up to pos (inclusive). */
|
|
506
|
+
protected _prefixSum(pos: number): number;
|
|
507
|
+
/** 1-based point update: add delta to position pos. */
|
|
508
|
+
protected _pointUpdate(pos: number, delta: number): void;
|
|
509
|
+
/** 1-based point query: get exact value at pos. */
|
|
510
|
+
protected _pointQuery(pos: number): number;
|
|
123
511
|
protected _checkIndex(index: number): void;
|
|
124
|
-
/**
|
|
125
|
-
|
|
126
|
-
* freqMap.
|
|
127
|
-
* @param {number} index - The `index` parameter is a number that represents the index of an element in a
|
|
128
|
-
* data structure.
|
|
129
|
-
* @returns a number.
|
|
130
|
-
*/
|
|
131
|
-
protected _readSingle(index: number): number;
|
|
132
|
-
/**
|
|
133
|
-
* The function `_updateNegativeCount` updates a counter based on changes in frequency values.
|
|
134
|
-
* @param {number} freqCur - The current frequency value.
|
|
135
|
-
* @param {number} freqNew - The freqNew parameter represents the new frequency value.
|
|
136
|
-
*/
|
|
137
|
-
protected _updateNegativeCount(freqCur: number, freqNew: number): void;
|
|
138
|
-
/**
|
|
139
|
-
* The `_update` function updates the values in a binary indexed freqMap starting from a given index and
|
|
140
|
-
* propagating the changes to its parent nodes.
|
|
141
|
-
* @param {number} index - The `index` parameter is a number that represents the index of the element in
|
|
142
|
-
* the data structure that needs to be updated.
|
|
143
|
-
* @param {number} delta - The `delta` parameter represents the change in value that needs to be
|
|
144
|
-
* applied to the elements in the data structure.
|
|
145
|
-
*/
|
|
146
|
-
protected _update(index: number, delta: number): void;
|
|
147
|
-
/**
|
|
148
|
-
* The `_writeSingle` function updates the frequency at a specific index and triggers a callback if
|
|
149
|
-
* the frequency has changed.
|
|
150
|
-
* @param {number} index - The `index` parameter is a number that represents the index of the element
|
|
151
|
-
* being modified or accessed.
|
|
152
|
-
* @param {number} freq - The `freq` parameter represents the new frequency value that needs to be
|
|
153
|
-
* written to the specified index `index`.
|
|
154
|
-
*/
|
|
155
|
-
protected _writeSingle(index: number, freq: number): void;
|
|
156
|
-
/**
|
|
157
|
-
* The `_read` function calculates the sum of values in a binary freqMap up to a given count.
|
|
158
|
-
* @param {number} count - The `count` parameter is a number that represents the number of elements
|
|
159
|
-
* to read from the freqMap.
|
|
160
|
-
* @returns the sum of the values obtained from calling the `_getFrequency` method for each index in the
|
|
161
|
-
* range from `count` to 1.
|
|
162
|
-
*/
|
|
163
|
-
protected _read(count: number): number;
|
|
164
|
-
/**
|
|
165
|
-
* The function `_binarySearch` performs a binary search to find the largest number that satisfies a given
|
|
166
|
-
* condition.
|
|
167
|
-
* @param {number} sum - The sum parameter is a number that represents the target sum value.
|
|
168
|
-
* @param before - The `before` parameter is a function that takes two numbers `x` and `y` as
|
|
169
|
-
* arguments and returns a boolean value. It is used to determine if `x` is less than or equal to
|
|
170
|
-
* `y`. The purpose of this function is to compare two numbers and determine their order.
|
|
171
|
-
* @returns the value of the variable "left".
|
|
172
|
-
*/
|
|
173
|
-
protected _binarySearch(sum: number, before: (x: number, y: number) => boolean): number;
|
|
512
|
+
/** Returns highest power of 2 <= n. */
|
|
513
|
+
protected _highBit(n: number): number;
|
|
174
514
|
}
|