@fluidframework/merge-tree 3.1.0 → 3.2.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/index.d.ts +1 -2
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +2 -7
  5. package/dist/index.js.map +1 -1
  6. package/dist/referencePositions.d.ts +0 -10
  7. package/dist/referencePositions.d.ts.map +1 -1
  8. package/dist/referencePositions.js +0 -16
  9. package/dist/referencePositions.js.map +1 -1
  10. package/dist/test/index.d.ts +1 -1
  11. package/dist/test/index.d.ts.map +1 -1
  12. package/dist/test/index.js +2 -5
  13. package/dist/test/index.js.map +1 -1
  14. package/lib/index.d.ts +1 -2
  15. package/lib/index.d.ts.map +1 -1
  16. package/lib/index.js +1 -2
  17. package/lib/index.js.map +1 -1
  18. package/lib/referencePositions.d.ts +0 -10
  19. package/lib/referencePositions.d.ts.map +1 -1
  20. package/lib/referencePositions.js +0 -14
  21. package/lib/referencePositions.js.map +1 -1
  22. package/lib/test/index.d.ts +1 -1
  23. package/lib/test/index.d.ts.map +1 -1
  24. package/lib/test/index.js +1 -1
  25. package/lib/test/index.js.map +1 -1
  26. package/package.json +16 -16
  27. package/src/index.ts +0 -17
  28. package/src/referencePositions.ts +0 -16
  29. package/dist/collections/index.d.ts +0 -6
  30. package/dist/collections/index.d.ts.map +0 -1
  31. package/dist/collections/index.js +0 -11
  32. package/dist/collections/index.js.map +0 -1
  33. package/dist/collections/rbTree.d.ts +0 -160
  34. package/dist/collections/rbTree.d.ts.map +0 -1
  35. package/dist/collections/rbTree.js +0 -496
  36. package/dist/collections/rbTree.js.map +0 -1
  37. package/lib/collections/index.d.ts +0 -6
  38. package/lib/collections/index.d.ts.map +0 -1
  39. package/lib/collections/index.js +0 -6
  40. package/lib/collections/index.js.map +0 -1
  41. package/lib/collections/rbTree.d.ts +0 -160
  42. package/lib/collections/rbTree.d.ts.map +0 -1
  43. package/lib/collections/rbTree.js +0 -492
  44. package/lib/collections/rbTree.js.map +0 -1
  45. package/src/collections/index.ts +0 -20
  46. package/src/collections/rbTree.ts +0 -721
@@ -1,496 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.RedBlackTree = exports.RBColor = void 0;
8
- /**
9
- * @internal
10
- */
11
- exports.RBColor = {
12
- RED: 0,
13
- BLACK: 1,
14
- };
15
- /**
16
- * @internal
17
- */
18
- class RedBlackTree {
19
- compareKeys;
20
- aug;
21
- root;
22
- constructor(compareKeys, aug) {
23
- this.compareKeys = compareKeys;
24
- this.aug = aug;
25
- }
26
- makeNode(key, data, color, size) {
27
- return { key, data, color, size };
28
- }
29
- isRed(node) {
30
- return !!node && node.color === exports.RBColor.RED;
31
- }
32
- nodeSize(node) {
33
- return node ? node.size : 0;
34
- }
35
- size() {
36
- return this.nodeSize(this.root);
37
- }
38
- isEmpty() {
39
- return !this.root;
40
- }
41
- get(key) {
42
- if (key !== undefined) {
43
- return this.nodeGet(this.root, key);
44
- }
45
- }
46
- nodeGet(node, key) {
47
- let _node = node;
48
- while (_node) {
49
- const cmp = this.compareKeys(key, _node.key);
50
- if (cmp < 0) {
51
- _node = _node.left;
52
- }
53
- else if (cmp > 0) {
54
- _node = _node.right;
55
- }
56
- else {
57
- return _node;
58
- }
59
- }
60
- }
61
- contains(key) {
62
- return this.get(key);
63
- }
64
- gather(key, matcher) {
65
- const results = [];
66
- if (key !== undefined) {
67
- this.nodeGather(this.root, results, key, matcher);
68
- }
69
- return results;
70
- }
71
- nodeGather(node, results, key, matcher) {
72
- if (node) {
73
- if (matcher.continueSubtree(node.left, key)) {
74
- this.nodeGather(node.left, results, key, matcher);
75
- }
76
- if (matcher.matchNode(node, key)) {
77
- results.push(node);
78
- }
79
- if (matcher.continueSubtree(node.right, key)) {
80
- this.nodeGather(node.right, results, key, matcher);
81
- }
82
- }
83
- }
84
- walkExactMatchesForward(compareFn, actionFn, continueLeftFn, continueRightFn) {
85
- this.nodeWalkExactMatchesForward(this.root, compareFn, actionFn, continueLeftFn, continueRightFn);
86
- }
87
- nodeWalkExactMatchesForward(node, compareFn, actionFn, continueLeftFn, continueRightFn) {
88
- if (!node) {
89
- return;
90
- }
91
- const result = compareFn(node);
92
- if (continueLeftFn(result)) {
93
- this.nodeWalkExactMatchesForward(node.left, compareFn, actionFn, continueLeftFn, continueRightFn);
94
- }
95
- if (result === 0) {
96
- actionFn(node);
97
- }
98
- if (continueRightFn(result)) {
99
- this.nodeWalkExactMatchesForward(node.right, compareFn, actionFn, continueLeftFn, continueRightFn);
100
- }
101
- }
102
- walkExactMatchesBackward(compareFn, actionFn, continueLeftFn, continueRightFn) {
103
- this.nodeWalkExactMatchesBackward(this.root, compareFn, actionFn, continueLeftFn, continueRightFn);
104
- }
105
- nodeWalkExactMatchesBackward(node, compareFn, actionFn, continueLeftFn, continueRightFn) {
106
- if (!node) {
107
- return;
108
- }
109
- const result = compareFn(node);
110
- if (continueRightFn(result)) {
111
- this.nodeWalkExactMatchesBackward(node.right, compareFn, actionFn, continueLeftFn, continueRightFn);
112
- }
113
- if (result === 0) {
114
- actionFn(node);
115
- }
116
- if (continueLeftFn(result)) {
117
- this.nodeWalkExactMatchesBackward(node.left, compareFn, actionFn, continueLeftFn, continueRightFn);
118
- }
119
- }
120
- put(key, data, conflict) {
121
- if (key !== undefined) {
122
- if (data === undefined) {
123
- this.remove(key);
124
- }
125
- else {
126
- this.root = this.nodePut(this.root, key, data, conflict);
127
- this.root.color = exports.RBColor.BLACK;
128
- }
129
- }
130
- }
131
- nodePut(node, key, data, conflict) {
132
- let _node = node;
133
- if (_node) {
134
- const cmp = this.compareKeys(key, _node.key);
135
- if (cmp < 0) {
136
- _node.left = this.nodePut(_node.left, key, data, conflict);
137
- }
138
- else if (cmp > 0) {
139
- _node.right = this.nodePut(_node.right, key, data, conflict);
140
- }
141
- else {
142
- if (conflict) {
143
- const kd = conflict(key, _node.key, data, _node.data);
144
- if (kd.key) {
145
- _node.key = kd.key;
146
- }
147
- _node.data = kd.data ?? data;
148
- }
149
- else {
150
- _node.data = data;
151
- }
152
- }
153
- if (this.isRed(_node.right) && !this.isRed(_node.left)) {
154
- _node = this.rotateLeft(_node);
155
- }
156
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
157
- if (this.isRed(_node.left) && this.isRed(_node.left.left)) {
158
- _node = this.rotateRight(_node);
159
- }
160
- if (this.isRed(_node.left) && this.isRed(_node.right)) {
161
- this.flipColors(_node);
162
- }
163
- _node.size = this.nodeSize(_node.left) + this.nodeSize(_node.right) + 1;
164
- if (this.aug) {
165
- this.updateLocal(_node);
166
- }
167
- return _node;
168
- }
169
- else {
170
- return this.makeNode(key, data, exports.RBColor.RED, 1);
171
- }
172
- }
173
- updateLocal(node) {
174
- if (this.aug) {
175
- if (this.isRed(node.left)) {
176
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
177
- this.aug.update(node.left);
178
- }
179
- if (this.isRed(node.right)) {
180
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
181
- this.aug.update(node.right);
182
- }
183
- this.aug.update(node);
184
- }
185
- }
186
- nodeRemoveMin(node) {
187
- let _node = node;
188
- if (_node.left) {
189
- if (!this.isRed(_node.left) && !this.isRed(_node.left.left)) {
190
- _node = this.moveRedLeft(_node);
191
- }
192
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
193
- _node.left = this.nodeRemoveMin(_node.left);
194
- return this.balance(_node);
195
- }
196
- }
197
- remove(key) {
198
- if (key !== undefined) {
199
- if (!this.contains(key)) {
200
- return;
201
- }
202
- this.removeExisting(key);
203
- }
204
- // TODO: error on undefined key
205
- }
206
- removeExisting(key) {
207
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
208
- if (!this.isRed(this.root.left) && !this.isRed(this.root.right)) {
209
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
210
- this.root.color = exports.RBColor.RED;
211
- }
212
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
213
- this.root = this.nodeRemove(this.root, key);
214
- }
215
- nodeRemove(node, key) {
216
- let _node = node;
217
- if (this.compareKeys(key, _node.key) < 0) {
218
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
219
- if (!this.isRed(_node.left) && !this.isRed(_node.left.left)) {
220
- _node = this.moveRedLeft(_node);
221
- }
222
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
223
- _node.left = this.nodeRemove(_node.left, key);
224
- }
225
- else {
226
- if (this.isRed(_node.left)) {
227
- _node = this.rotateRight(_node);
228
- }
229
- if (this.compareKeys(key, _node.key) === 0 && !_node.right) {
230
- return undefined;
231
- }
232
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
233
- if (!this.isRed(_node.right) && !this.isRed(_node.right.left)) {
234
- _node = this.moveRedRight(_node);
235
- }
236
- if (this.compareKeys(key, _node.key) === 0) {
237
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
238
- const subtreeMin = this.nodeMin(_node.right);
239
- _node.key = subtreeMin.key;
240
- _node.data = subtreeMin.data;
241
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
242
- _node.right = this.nodeRemoveMin(_node.right);
243
- }
244
- else {
245
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
246
- _node.right = this.nodeRemove(_node.right, key);
247
- }
248
- }
249
- return this.balance(_node);
250
- }
251
- /**
252
- * Finds the largest node that is less than or equal to a given key.
253
- */
254
- floor(key) {
255
- if (!this.isEmpty()) {
256
- return this.nodeFloor(this.root, key);
257
- }
258
- }
259
- nodeFloor(node, key) {
260
- if (node) {
261
- const cmp = this.compareKeys(key, node.key);
262
- if (cmp === 0) {
263
- return node;
264
- }
265
- else if (cmp < 0) {
266
- return this.nodeFloor(node.left, key);
267
- }
268
- else {
269
- const rightFloor = this.nodeFloor(node.right, key);
270
- return rightFloor ?? node;
271
- }
272
- }
273
- }
274
- /**
275
- * Finds the smallest node that is greater than or equal to a given key.
276
- */
277
- ceil(key) {
278
- if (!this.isEmpty()) {
279
- return this.nodeCeil(this.root, key);
280
- }
281
- }
282
- nodeCeil(node, key) {
283
- if (node) {
284
- const cmp = this.compareKeys(key, node.key);
285
- if (cmp === 0) {
286
- return node;
287
- }
288
- else if (cmp > 0) {
289
- return this.nodeCeil(node.right, key);
290
- }
291
- else {
292
- const leftCeil = this.nodeCeil(node.left, key);
293
- return leftCeil ?? node;
294
- }
295
- }
296
- }
297
- min() {
298
- if (this.root) {
299
- return this.nodeMin(this.root);
300
- }
301
- }
302
- nodeMin(node) {
303
- return node.left ? this.nodeMin(node.left) : node;
304
- }
305
- max() {
306
- if (this.root) {
307
- return this.nodeMax(this.root);
308
- }
309
- }
310
- nodeMax(node) {
311
- return node.right ? this.nodeMax(node.right) : node;
312
- }
313
- rotateRight(node) {
314
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
315
- const leftChild = node.left;
316
- node.left = leftChild.right;
317
- leftChild.right = node;
318
- leftChild.color = leftChild.right.color;
319
- leftChild.right.color = exports.RBColor.RED;
320
- leftChild.size = node.size;
321
- node.size = this.nodeSize(node.left) + this.nodeSize(node.right) + 1;
322
- if (this.aug) {
323
- this.updateLocal(node);
324
- this.updateLocal(leftChild);
325
- }
326
- return leftChild;
327
- }
328
- rotateLeft(node) {
329
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
330
- const rightChild = node.right;
331
- node.right = rightChild.left;
332
- rightChild.left = node;
333
- rightChild.color = rightChild.left.color;
334
- rightChild.left.color = exports.RBColor.RED;
335
- rightChild.size = node.size;
336
- node.size = this.nodeSize(node.left) + this.nodeSize(node.right) + 1;
337
- if (this.aug) {
338
- this.updateLocal(node);
339
- this.updateLocal(rightChild);
340
- }
341
- return rightChild;
342
- }
343
- oppositeColor(c) {
344
- return c === exports.RBColor.BLACK ? exports.RBColor.RED : exports.RBColor.BLACK;
345
- }
346
- flipColors(node) {
347
- node.color = this.oppositeColor(node.color);
348
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
349
- node.left.color = this.oppositeColor(node.left.color);
350
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
351
- node.right.color = this.oppositeColor(node.right.color);
352
- }
353
- moveRedLeft(node) {
354
- let _node = node;
355
- this.flipColors(_node);
356
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
357
- if (this.isRed(_node.right.left)) {
358
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
359
- _node.right = this.rotateRight(_node.right);
360
- _node = this.rotateLeft(_node);
361
- this.flipColors(_node);
362
- }
363
- return _node;
364
- }
365
- moveRedRight(node) {
366
- let _node = node;
367
- this.flipColors(_node);
368
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
369
- if (this.isRed(_node.left.left)) {
370
- _node = this.rotateRight(_node);
371
- this.flipColors(_node);
372
- }
373
- return _node;
374
- }
375
- balance(input) {
376
- let node = input;
377
- if (this.isRed(node.right)) {
378
- node = this.rotateLeft(node);
379
- }
380
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
381
- if (this.isRed(node.left) && this.isRed(node.left.left)) {
382
- node = this.rotateRight(node);
383
- }
384
- if (this.isRed(node.left) && this.isRed(node.right)) {
385
- this.flipColors(node);
386
- }
387
- node.size = this.nodeSize(node.left) + this.nodeSize(node.right) + 1;
388
- if (this.aug) {
389
- this.aug.update(node);
390
- }
391
- return node;
392
- }
393
- mapRange(action, accum, start, end) {
394
- this.nodeMap(this.root, action, accum, start, end);
395
- }
396
- map(action, accum) {
397
- // TODO: optimize to avoid comparisons
398
- this.nodeMap(this.root, action, accum);
399
- }
400
- keys() {
401
- const keyList = [];
402
- const actions = {
403
- showStructure: true,
404
- infix: (node) => {
405
- keyList.push(node.key);
406
- return true;
407
- },
408
- };
409
- this.walk(actions);
410
- return keyList;
411
- }
412
- /**
413
- * Depth-first traversal with custom action; if action returns
414
- * false, traversal is halted.
415
- * @param action - action to apply to each node
416
- */
417
- walk(actions) {
418
- this.nodeWalk(this.root, actions);
419
- }
420
- walkBackward(actions) {
421
- this.nodeWalkBackward(this.root, actions);
422
- }
423
- nodeWalk(node, actions) {
424
- let go = true;
425
- if (node) {
426
- if (actions.pre && (!!actions.showStructure || node.color === exports.RBColor.BLACK)) {
427
- go = actions.pre(node);
428
- }
429
- if (node.left) {
430
- go = this.nodeWalk(node.left, actions);
431
- }
432
- if (go && actions.infix && (!!actions.showStructure || node.color === exports.RBColor.BLACK)) {
433
- go = actions.infix(node);
434
- }
435
- if (go) {
436
- go = this.nodeWalk(node.right, actions);
437
- }
438
- if (go && actions.post && (!!actions.showStructure || node.color === exports.RBColor.BLACK)) {
439
- go = actions.post(node);
440
- }
441
- }
442
- return go;
443
- }
444
- nodeWalkBackward(node, actions) {
445
- let go = true;
446
- if (node) {
447
- if (actions.pre && (!!actions.showStructure || node.color === exports.RBColor.BLACK)) {
448
- go = actions.pre(node);
449
- }
450
- if (node.right) {
451
- go = this.nodeWalkBackward(node.right, actions);
452
- }
453
- if (go && actions.infix && (!!actions.showStructure || node.color === exports.RBColor.BLACK)) {
454
- go = actions.infix(node);
455
- }
456
- if (go) {
457
- go = this.nodeWalkBackward(node.left, actions);
458
- }
459
- if (go && actions.post && (!!actions.showStructure || node.color === exports.RBColor.BLACK)) {
460
- go = actions.post(node);
461
- }
462
- }
463
- return go;
464
- }
465
- nodeMap(node, action, accum, start, end) {
466
- let _start = start;
467
- let _end = end;
468
- if (!node) {
469
- return true;
470
- }
471
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy
472
- if (_start === undefined) {
473
- _start = this.nodeMin(node).key;
474
- }
475
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy
476
- if (_end === undefined) {
477
- _end = this.nodeMax(node).key;
478
- }
479
- const cmpStart = this.compareKeys(_start, node.key);
480
- const cmpEnd = this.compareKeys(_end, node.key);
481
- let go = true;
482
- if (cmpStart < 0) {
483
- go = this.nodeMap(node.left, action, accum, _start, _end);
484
- }
485
- if (go && cmpStart <= 0 && cmpEnd >= 0) {
486
- // REVIEW: test for black node here
487
- go = action(node, accum);
488
- }
489
- if (go && cmpEnd > 0) {
490
- go = this.nodeMap(node.right, action, accum, _start, _end);
491
- }
492
- return go;
493
- }
494
- }
495
- exports.RedBlackTree = RedBlackTree;
496
- //# sourceMappingURL=rbTree.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rbTree.js","sourceRoot":"","sources":["../../src/collections/rbTree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;GAEG;AACU,QAAA,OAAO,GAAG;IACtB,GAAG,EAAE,CAAC;IACN,KAAK,EAAE,CAAC;CACC,CAAC;AA4GX;;GAEG;AACH,MAAa,YAAY;IAIN;IACA;IAJV,IAAI,CAAkC;IAE9C,YACkB,WAA8B,EAC9B,GAAkC;QADlC,gBAAW,GAAX,WAAW,CAAmB;QAC9B,QAAG,GAAH,GAAG,CAA+B;IACjD,CAAC;IAEI,QAAQ,CAAC,GAAS,EAAE,IAAW,EAAE,KAAc,EAAE,IAAY;QACpE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAoC,CAAC;IACrE,CAAC;IAEO,KAAK,CAAC,IAAqC;QAClD,OAAO,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,eAAO,CAAC,GAAG,CAAC;IAC7C,CAAC;IAEO,QAAQ,CAAC,IAAqC;QACrD,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;IACM,IAAI;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IACM,OAAO;QACb,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IACM,GAAG,CAA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AAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACpD,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QAChD,IAAI,EAAE,GAAG,IAAI,CAAC;QACd,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;YAClB,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAC3D,CAAC;QACD,IAAI,EAAE,IAAI,QAAQ,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;YACxC,mCAAmC;YACnC,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC1B,CAAC;QACD,IAAI,EAAE,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,EAAE,CAAC;IACX,CAAC;CACD;AAtlBD,oCAslBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * @internal\n */\nexport const RBColor = {\n\tRED: 0,\n\tBLACK: 1,\n} as const;\n\n/**\n * @internal\n */\nexport type RBColor = (typeof RBColor)[keyof typeof RBColor];\n\n/**\n * @internal\n */\nexport interface RBNode<TKey, TData> {\n\tkey: TKey;\n\tdata: TData;\n\tleft: RBNode<TKey, TData> | undefined;\n\tright: RBNode<TKey, TData> | undefined;\n\tcolor: RBColor;\n\tsize: number;\n}\n/**\n * @internal\n */\nexport interface IRBAugmentation<TKey, TData> {\n\tupdate(node: RBNode<TKey, TData>): void;\n}\n/**\n * @internal\n */\nexport interface IRBMatcher<TKey, TData> {\n\tcontinueSubtree(node: RBNode<TKey, TData> | undefined, key: TKey): boolean;\n\tmatchNode(node: RBNode<TKey, TData> | undefined, key: TKey): boolean;\n}\n\n/**\n * @internal\n */\nexport interface RBNodeActions<TKey, TData> {\n\tinfix?(node: RBNode<TKey, TData>): boolean;\n\tpre?(node: RBNode<TKey, TData>): boolean;\n\tpost?(node: RBNode<TKey, TData>): boolean;\n\tshowStructure?: boolean;\n}\n\n/**\n * @internal\n */\nexport interface KeyComparer<TKey> {\n\t// eslint-disable-next-line @typescript-eslint/prefer-function-type\n\t(a: TKey, b: TKey): number;\n}\n\n/**\n * @internal\n */\nexport interface Property<TKey, TData> {\n\tkey: TKey;\n\tdata: TData;\n}\n\n/**\n * @internal\n */\nexport interface PropertyAction<TKey, TData> {\n\t// eslint-disable-next-line @typescript-eslint/prefer-function-type\n\t<TAccum>(p: Property<TKey, TData>, accum?: TAccum): boolean;\n}\n\n/**\n * @internal\n */\nexport interface QProperty<TKey, TData> {\n\tkey?: TKey;\n\tdata?: TData;\n}\n\n/**\n * @internal\n */\nexport type ConflictAction<TKey, TData> = (\n\tkey: TKey,\n\tcurrentKey: TKey,\n\tdata: TData,\n\tcurrentData: TData,\n) => QProperty<TKey, TData>;\n\n/**\n * @internal\n */\nexport interface SortedDictionary<TKey, TData> extends Dictionary<TKey, TData> {\n\tmax(): Property<TKey, TData> | undefined;\n\tmin(): Property<TKey, TData> | undefined;\n\tmapRange<TAccum>(\n\t\taction: PropertyAction<TKey, TData>,\n\t\taccum?: TAccum,\n\t\tstart?: TKey,\n\t\tend?: TKey,\n\t): void;\n}\n\n/**\n * @internal\n */\nexport interface Dictionary<TKey, TData> {\n\tget(key: TKey): Property<TKey, TData> | undefined;\n\tput(key: TKey, data: TData, conflict?: ConflictAction<TKey, TData>): void;\n\tremove(key: TKey): void;\n\tmap<TAccum>(action: PropertyAction<TKey, TData>, accum?: TAccum): void;\n}\n\n/**\n * @internal\n */\nexport class RedBlackTree<TKey, TData> implements SortedDictionary<TKey, TData> {\n\tprivate root: RBNode<TKey, TData> | undefined;\n\n\tconstructor(\n\t\tprivate readonly compareKeys: KeyComparer<TKey>,\n\t\tprivate readonly aug?: IRBAugmentation<TKey, TData>,\n\t) {}\n\n\tprivate makeNode(key: TKey, data: TData, color: RBColor, size: number): RBNode<TKey, TData> {\n\t\treturn { key, data, color, size } as unknown as RBNode<TKey, TData>;\n\t}\n\n\tprivate isRed(node: RBNode<TKey, TData> | undefined): boolean {\n\t\treturn !!node && node.color === RBColor.RED;\n\t}\n\n\tprivate nodeSize(node: RBNode<TKey, TData> | undefined): number {\n\t\treturn node ? node.size : 0;\n\t}\n\tpublic size(): number {\n\t\treturn this.nodeSize(this.root);\n\t}\n\tpublic isEmpty(): boolean {\n\t\treturn !this.root;\n\t}\n\tpublic get(key: TKey): RBNode<TKey, TData> | undefined {\n\t\tif (key !== undefined) {\n\t\t\treturn this.nodeGet(this.root, key);\n\t\t}\n\t}\n\tprivate nodeGet(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tkey: TKey,\n\t): RBNode<TKey, TData> | undefined {\n\t\tlet _node = node;\n\t\twhile (_node) {\n\t\t\tconst cmp = this.compareKeys(key, _node.key);\n\t\t\tif (cmp < 0) {\n\t\t\t\t_node = _node.left;\n\t\t\t} else if (cmp > 0) {\n\t\t\t\t_node = _node.right;\n\t\t\t} else {\n\t\t\t\treturn _node;\n\t\t\t}\n\t\t}\n\t}\n\tprivate contains(key: TKey): RBNode<TKey, TData> | undefined {\n\t\treturn this.get(key);\n\t}\n\n\tpublic gather(key: TKey, matcher: IRBMatcher<TKey, TData>): RBNode<TKey, TData>[] {\n\t\tconst results = [] as RBNode<TKey, TData>[];\n\t\tif (key !== undefined) {\n\t\t\tthis.nodeGather(this.root, results, key, matcher);\n\t\t}\n\t\treturn results;\n\t}\n\n\tprivate nodeGather(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tresults: RBNode<TKey, TData>[],\n\t\tkey: TKey,\n\t\tmatcher: IRBMatcher<TKey, TData>,\n\t): void {\n\t\tif (node) {\n\t\t\tif (matcher.continueSubtree(node.left, key)) {\n\t\t\t\tthis.nodeGather(node.left, results, key, matcher);\n\t\t\t}\n\t\t\tif (matcher.matchNode(node, key)) {\n\t\t\t\tresults.push(node);\n\t\t\t}\n\t\t\tif (matcher.continueSubtree(node.right, key)) {\n\t\t\t\tthis.nodeGather(node.right, results, key, matcher);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic walkExactMatchesForward(\n\t\tcompareFn: (node: RBNode<TKey, TData>) => number,\n\t\tactionFn: (node: RBNode<TKey, TData>) => void,\n\t\tcontinueLeftFn: (number: number) => boolean,\n\t\tcontinueRightFn: (number: number) => boolean,\n\t): void {\n\t\tthis.nodeWalkExactMatchesForward(\n\t\t\tthis.root,\n\t\t\tcompareFn,\n\t\t\tactionFn,\n\t\t\tcontinueLeftFn,\n\t\t\tcontinueRightFn,\n\t\t);\n\t}\n\n\tprivate nodeWalkExactMatchesForward(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tcompareFn: (node: RBNode<TKey, TData>) => number,\n\t\tactionFn: (node: RBNode<TKey, TData>) => void,\n\t\tcontinueLeftFn: (number: number) => boolean,\n\t\tcontinueRightFn: (number: number) => boolean,\n\t): void {\n\t\tif (!node) {\n\t\t\treturn;\n\t\t}\n\t\tconst result: number = compareFn(node);\n\t\tif (continueLeftFn(result)) {\n\t\t\tthis.nodeWalkExactMatchesForward(\n\t\t\t\tnode.left,\n\t\t\t\tcompareFn,\n\t\t\t\tactionFn,\n\t\t\t\tcontinueLeftFn,\n\t\t\t\tcontinueRightFn,\n\t\t\t);\n\t\t}\n\t\tif (result === 0) {\n\t\t\tactionFn(node);\n\t\t}\n\t\tif (continueRightFn(result)) {\n\t\t\tthis.nodeWalkExactMatchesForward(\n\t\t\t\tnode.right,\n\t\t\t\tcompareFn,\n\t\t\t\tactionFn,\n\t\t\t\tcontinueLeftFn,\n\t\t\t\tcontinueRightFn,\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic walkExactMatchesBackward(\n\t\tcompareFn: (node: RBNode<TKey, TData>) => number,\n\t\tactionFn: (node: RBNode<TKey, TData>) => void,\n\t\tcontinueLeftFn: (number: number) => boolean,\n\t\tcontinueRightFn: (number: number) => boolean,\n\t): void {\n\t\tthis.nodeWalkExactMatchesBackward(\n\t\t\tthis.root,\n\t\t\tcompareFn,\n\t\t\tactionFn,\n\t\t\tcontinueLeftFn,\n\t\t\tcontinueRightFn,\n\t\t);\n\t}\n\n\tprivate nodeWalkExactMatchesBackward(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tcompareFn: (node: RBNode<TKey, TData>) => number,\n\t\tactionFn: (node: RBNode<TKey, TData>) => void,\n\t\tcontinueLeftFn: (cmp: number) => boolean,\n\t\tcontinueRightFn: (cmp: number) => boolean,\n\t): void {\n\t\tif (!node) {\n\t\t\treturn;\n\t\t}\n\t\tconst result: number = compareFn(node);\n\t\tif (continueRightFn(result)) {\n\t\t\tthis.nodeWalkExactMatchesBackward(\n\t\t\t\tnode.right,\n\t\t\t\tcompareFn,\n\t\t\t\tactionFn,\n\t\t\t\tcontinueLeftFn,\n\t\t\t\tcontinueRightFn,\n\t\t\t);\n\t\t}\n\t\tif (result === 0) {\n\t\t\tactionFn(node);\n\t\t}\n\t\tif (continueLeftFn(result)) {\n\t\t\tthis.nodeWalkExactMatchesBackward(\n\t\t\t\tnode.left,\n\t\t\t\tcompareFn,\n\t\t\t\tactionFn,\n\t\t\t\tcontinueLeftFn,\n\t\t\t\tcontinueRightFn,\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic put(key: TKey, data: TData, conflict?: ConflictAction<TKey, TData>): void {\n\t\tif (key !== undefined) {\n\t\t\tif (data === undefined) {\n\t\t\t\tthis.remove(key);\n\t\t\t} else {\n\t\t\t\tthis.root = this.nodePut(this.root, key, data, conflict);\n\t\t\t\tthis.root.color = RBColor.BLACK;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate nodePut(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tkey: TKey,\n\t\tdata: TData,\n\t\tconflict?: ConflictAction<TKey, TData>,\n\t): RBNode<TKey, TData> {\n\t\tlet _node = node;\n\t\tif (_node) {\n\t\t\tconst cmp = this.compareKeys(key, _node.key);\n\t\t\tif (cmp < 0) {\n\t\t\t\t_node.left = this.nodePut(_node.left, key, data, conflict);\n\t\t\t} else if (cmp > 0) {\n\t\t\t\t_node.right = this.nodePut(_node.right, key, data, conflict);\n\t\t\t} else {\n\t\t\t\tif (conflict) {\n\t\t\t\t\tconst kd = conflict(key, _node.key, data, _node.data);\n\t\t\t\t\tif (kd.key) {\n\t\t\t\t\t\t_node.key = kd.key;\n\t\t\t\t\t}\n\t\t\t\t\t_node.data = kd.data ?? data;\n\t\t\t\t} else {\n\t\t\t\t\t_node.data = data;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (this.isRed(_node.right) && !this.isRed(_node.left)) {\n\t\t\t\t_node = this.rotateLeft(_node);\n\t\t\t}\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (this.isRed(_node.left) && this.isRed(_node.left!.left)) {\n\t\t\t\t_node = this.rotateRight(_node);\n\t\t\t}\n\t\t\tif (this.isRed(_node.left) && this.isRed(_node.right)) {\n\t\t\t\tthis.flipColors(_node);\n\t\t\t}\n\t\t\t_node.size = this.nodeSize(_node.left) + this.nodeSize(_node.right) + 1;\n\t\t\tif (this.aug) {\n\t\t\t\tthis.updateLocal(_node);\n\t\t\t}\n\t\t\treturn _node;\n\t\t} else {\n\t\t\treturn this.makeNode(key, data, RBColor.RED, 1);\n\t\t}\n\t}\n\n\tprivate updateLocal(node: RBNode<TKey, TData>): void {\n\t\tif (this.aug) {\n\t\t\tif (this.isRed(node.left)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tthis.aug.update(node.left!);\n\t\t\t}\n\t\t\tif (this.isRed(node.right)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tthis.aug.update(node.right!);\n\t\t\t}\n\t\t\tthis.aug.update(node);\n\t\t}\n\t}\n\n\tprivate nodeRemoveMin(node: RBNode<TKey, TData>): RBNode<TKey, TData> | undefined {\n\t\tlet _node = node;\n\t\tif (_node.left) {\n\t\t\tif (!this.isRed(_node.left) && !this.isRed(_node.left.left)) {\n\t\t\t\t_node = this.moveRedLeft(_node);\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t_node.left = this.nodeRemoveMin(_node.left!);\n\t\t\treturn this.balance(_node);\n\t\t}\n\t}\n\n\tpublic remove(key: TKey): void {\n\t\tif (key !== undefined) {\n\t\t\tif (!this.contains(key)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.removeExisting(key);\n\t\t}\n\t\t// TODO: error on undefined key\n\t}\n\n\tpublic removeExisting(key: TKey): void {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tif (!this.isRed(this.root!.left) && !this.isRed(this.root!.right)) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tthis.root!.color = RBColor.RED;\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tthis.root = this.nodeRemove(this.root!, key);\n\t}\n\n\tprivate nodeRemove(node: RBNode<TKey, TData>, key: TKey): RBNode<TKey, TData> | undefined {\n\t\tlet _node = node;\n\t\tif (this.compareKeys(key, _node.key) < 0) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (!this.isRed(_node.left) && !this.isRed(_node.left!.left)) {\n\t\t\t\t_node = this.moveRedLeft(_node);\n\t\t\t}\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t_node.left = this.nodeRemove(_node.left!, key);\n\t\t} else {\n\t\t\tif (this.isRed(_node.left)) {\n\t\t\t\t_node = this.rotateRight(_node);\n\t\t\t}\n\t\t\tif (this.compareKeys(key, _node.key) === 0 && !_node.right) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (!this.isRed(_node.right) && !this.isRed(_node.right!.left)) {\n\t\t\t\t_node = this.moveRedRight(_node);\n\t\t\t}\n\t\t\tif (this.compareKeys(key, _node.key) === 0) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst subtreeMin = this.nodeMin(_node.right!);\n\t\t\t\t_node.key = subtreeMin.key;\n\t\t\t\t_node.data = subtreeMin.data;\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t_node.right = this.nodeRemoveMin(_node.right!);\n\t\t\t} else {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t_node.right = this.nodeRemove(_node.right!, key);\n\t\t\t}\n\t\t}\n\t\treturn this.balance(_node);\n\t}\n\n\t/**\n\t * Finds the largest node that is less than or equal to a given key.\n\t */\n\tpublic floor(key: TKey): RBNode<TKey, TData> | undefined {\n\t\tif (!this.isEmpty()) {\n\t\t\treturn this.nodeFloor(this.root, key);\n\t\t}\n\t}\n\n\tprivate nodeFloor(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tkey: TKey,\n\t): RBNode<TKey, TData> | undefined {\n\t\tif (node) {\n\t\t\tconst cmp = this.compareKeys(key, node.key);\n\t\t\tif (cmp === 0) {\n\t\t\t\treturn node;\n\t\t\t} else if (cmp < 0) {\n\t\t\t\treturn this.nodeFloor(node.left, key);\n\t\t\t} else {\n\t\t\t\tconst rightFloor = this.nodeFloor(node.right, key);\n\t\t\t\treturn rightFloor ?? node;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Finds the smallest node that is greater than or equal to a given key.\n\t */\n\tpublic ceil(key: TKey): RBNode<TKey, TData> | undefined {\n\t\tif (!this.isEmpty()) {\n\t\t\treturn this.nodeCeil(this.root, key);\n\t\t}\n\t}\n\n\tprivate nodeCeil(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tkey: TKey,\n\t): RBNode<TKey, TData> | undefined {\n\t\tif (node) {\n\t\t\tconst cmp = this.compareKeys(key, node.key);\n\t\t\tif (cmp === 0) {\n\t\t\t\treturn node;\n\t\t\t} else if (cmp > 0) {\n\t\t\t\treturn this.nodeCeil(node.right, key);\n\t\t\t} else {\n\t\t\t\tconst leftCeil = this.nodeCeil(node.left, key);\n\t\t\t\treturn leftCeil ?? node;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic min(): RBNode<TKey, TData> | undefined {\n\t\tif (this.root) {\n\t\t\treturn this.nodeMin(this.root);\n\t\t}\n\t}\n\n\tprivate nodeMin(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\treturn node.left ? this.nodeMin(node.left) : node;\n\t}\n\n\tpublic max(): RBNode<TKey, TData> | undefined {\n\t\tif (this.root) {\n\t\t\treturn this.nodeMax(this.root);\n\t\t}\n\t}\n\n\tprivate nodeMax(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\treturn node.right ? this.nodeMax(node.right) : node;\n\t}\n\n\tprivate rotateRight(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst leftChild = node.left!;\n\t\tnode.left = leftChild.right;\n\t\tleftChild.right = node;\n\t\tleftChild.color = leftChild.right.color;\n\t\tleftChild.right.color = RBColor.RED;\n\t\tleftChild.size = node.size;\n\t\tnode.size = this.nodeSize(node.left) + this.nodeSize(node.right) + 1;\n\t\tif (this.aug) {\n\t\t\tthis.updateLocal(node);\n\t\t\tthis.updateLocal(leftChild);\n\t\t}\n\t\treturn leftChild;\n\t}\n\n\tprivate rotateLeft(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst rightChild = node.right!;\n\t\tnode.right = rightChild.left;\n\t\trightChild.left = node;\n\t\trightChild.color = rightChild.left.color;\n\t\trightChild.left.color = RBColor.RED;\n\t\trightChild.size = node.size;\n\t\tnode.size = this.nodeSize(node.left) + this.nodeSize(node.right) + 1;\n\t\tif (this.aug) {\n\t\t\tthis.updateLocal(node);\n\t\t\tthis.updateLocal(rightChild);\n\t\t}\n\t\treturn rightChild;\n\t}\n\n\tprivate oppositeColor(c: RBColor): RBColor {\n\t\treturn c === RBColor.BLACK ? RBColor.RED : RBColor.BLACK;\n\t}\n\n\tprivate flipColors(node: RBNode<TKey, TData>): void {\n\t\tnode.color = this.oppositeColor(node.color);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tnode.left!.color = this.oppositeColor(node.left!.color);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tnode.right!.color = this.oppositeColor(node.right!.color);\n\t}\n\n\tprivate moveRedLeft(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\tlet _node = node;\n\t\tthis.flipColors(_node);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tif (this.isRed(_node.right!.left)) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t_node.right = this.rotateRight(_node.right!);\n\t\t\t_node = this.rotateLeft(_node);\n\t\t\tthis.flipColors(_node);\n\t\t}\n\t\treturn _node;\n\t}\n\n\tprivate moveRedRight(node: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\tlet _node = node;\n\t\tthis.flipColors(_node);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tif (this.isRed(_node.left!.left)) {\n\t\t\t_node = this.rotateRight(_node);\n\t\t\tthis.flipColors(_node);\n\t\t}\n\t\treturn _node;\n\t}\n\n\tprivate balance(input: RBNode<TKey, TData>): RBNode<TKey, TData> {\n\t\tlet node: RBNode<TKey, TData> | undefined = input;\n\t\tif (this.isRed(node.right)) {\n\t\t\tnode = this.rotateLeft(node);\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tif (this.isRed(node.left) && this.isRed(node.left!.left)) {\n\t\t\tnode = this.rotateRight(node);\n\t\t}\n\t\tif (this.isRed(node.left) && this.isRed(node.right)) {\n\t\t\tthis.flipColors(node);\n\t\t}\n\t\tnode.size = this.nodeSize(node.left) + this.nodeSize(node.right) + 1;\n\t\tif (this.aug) {\n\t\t\tthis.aug.update(node);\n\t\t}\n\t\treturn node;\n\t}\n\n\tpublic mapRange<TAccum>(\n\t\taction: PropertyAction<TKey, TData>,\n\t\taccum?: TAccum,\n\t\tstart?: TKey,\n\t\tend?: TKey,\n\t): void {\n\t\tthis.nodeMap(this.root, action, accum, start, end);\n\t}\n\n\tpublic map<TAccum>(action: PropertyAction<TKey, TData>, accum?: TAccum): void {\n\t\t// TODO: optimize to avoid comparisons\n\t\tthis.nodeMap(this.root, action, accum);\n\t}\n\n\tpublic keys(): TKey[] {\n\t\tconst keyList: TKey[] = [];\n\t\tconst actions: RBNodeActions<TKey, TData> = {\n\t\t\tshowStructure: true,\n\t\t\tinfix: (node) => {\n\t\t\t\tkeyList.push(node.key);\n\t\t\t\treturn true;\n\t\t\t},\n\t\t};\n\t\tthis.walk(actions);\n\t\treturn keyList;\n\t}\n\n\t/**\n\t * Depth-first traversal with custom action; if action returns\n\t * false, traversal is halted.\n\t * @param action - action to apply to each node\n\t */\n\tpublic walk(actions: RBNodeActions<TKey, TData>): void {\n\t\tthis.nodeWalk(this.root, actions);\n\t}\n\n\tpublic walkBackward(actions: RBNodeActions<TKey, TData>): void {\n\t\tthis.nodeWalkBackward(this.root, actions);\n\t}\n\n\tprivate nodeWalk(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tactions: RBNodeActions<TKey, TData>,\n\t): boolean {\n\t\tlet go = true;\n\t\tif (node) {\n\t\t\tif (actions.pre && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.pre(node);\n\t\t\t}\n\t\t\tif (node.left) {\n\t\t\t\tgo = this.nodeWalk(node.left, actions);\n\t\t\t}\n\t\t\tif (go && actions.infix && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.infix(node);\n\t\t\t}\n\t\t\tif (go) {\n\t\t\t\tgo = this.nodeWalk(node.right, actions);\n\t\t\t}\n\t\t\tif (go && actions.post && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.post(node);\n\t\t\t}\n\t\t}\n\t\treturn go;\n\t}\n\n\tprivate nodeWalkBackward(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\tactions: RBNodeActions<TKey, TData>,\n\t): boolean {\n\t\tlet go = true;\n\t\tif (node) {\n\t\t\tif (actions.pre && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.pre(node);\n\t\t\t}\n\t\t\tif (node.right) {\n\t\t\t\tgo = this.nodeWalkBackward(node.right, actions);\n\t\t\t}\n\t\t\tif (go && actions.infix && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.infix(node);\n\t\t\t}\n\t\t\tif (go) {\n\t\t\t\tgo = this.nodeWalkBackward(node.left, actions);\n\t\t\t}\n\t\t\tif (go && actions.post && (!!actions.showStructure || node.color === RBColor.BLACK)) {\n\t\t\t\tgo = actions.post(node);\n\t\t\t}\n\t\t}\n\t\treturn go;\n\t}\n\n\tprivate nodeMap<TAccum>(\n\t\tnode: RBNode<TKey, TData> | undefined,\n\t\taction: PropertyAction<TKey, TData>,\n\t\taccum?: TAccum,\n\t\tstart?: TKey,\n\t\tend?: TKey,\n\t): boolean {\n\t\tlet _start = start;\n\t\tlet _end = end;\n\t\tif (!node) {\n\t\t\treturn true;\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy\n\t\tif (_start === undefined) {\n\t\t\t_start = this.nodeMin(node).key;\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy\n\t\tif (_end === undefined) {\n\t\t\t_end = this.nodeMax(node).key;\n\t\t}\n\t\tconst cmpStart = this.compareKeys(_start, node.key);\n\t\tconst cmpEnd = this.compareKeys(_end, node.key);\n\t\tlet go = true;\n\t\tif (cmpStart < 0) {\n\t\t\tgo = this.nodeMap(node.left, action, accum, _start, _end);\n\t\t}\n\t\tif (go && cmpStart <= 0 && cmpEnd >= 0) {\n\t\t\t// REVIEW: test for black node here\n\t\t\tgo = action(node, accum);\n\t\t}\n\t\tif (go && cmpEnd > 0) {\n\t\t\tgo = this.nodeMap(node.right, action, accum, _start, _end);\n\t\t}\n\t\treturn go;\n\t}\n}\n"]}
@@ -1,6 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- export { type ConflictAction, type Dictionary, type IRBAugmentation, type IRBMatcher, type KeyComparer, type Property, type PropertyAction, type QProperty, RBColor, type RBNode, type RBNodeActions, RedBlackTree, type SortedDictionary, } from "./rbTree.js";
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/collections/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,OAAO,EACP,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,YAAY,EACZ,KAAK,gBAAgB,GACrB,MAAM,aAAa,CAAC"}
@@ -1,6 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- export { RBColor, RedBlackTree, } from "./rbTree.js";
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/collections/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EASN,OAAO,EAGP,YAAY,GAEZ,MAAM,aAAa,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\ttype ConflictAction,\n\ttype Dictionary,\n\ttype IRBAugmentation,\n\ttype IRBMatcher,\n\ttype KeyComparer,\n\ttype Property,\n\ttype PropertyAction,\n\ttype QProperty,\n\tRBColor,\n\ttype RBNode,\n\ttype RBNodeActions,\n\tRedBlackTree,\n\ttype SortedDictionary,\n} from \"./rbTree.js\";\n"]}