ezh 0.2.0 → 0.2.2

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/lib/RbTree.js DELETED
@@ -1,727 +0,0 @@
1
- export { Z, O, Q, E, R, J, };
2
- class F {
3
- ad() {
4
- return !this.k;
5
- }
6
- G(a) {
7
- while (a.parent?.e) {
8
- let parent = a.parent;
9
- let m = parent.parent;
10
- if (parent === m.c) {
11
- const x = m.d;
12
- if (x?.e) {
13
- parent.e = false;
14
- x.e = false;
15
- m.e = true;
16
- a = m;
17
- }
18
- else {
19
- if (a === parent.d) {
20
- a = parent;
21
- this.y(a);
22
- parent = a.parent;
23
- m = parent.parent;
24
- }
25
- parent.e = false;
26
- m.e = true;
27
- this.z(m);
28
- }
29
- }
30
- else {
31
- const x = m.c;
32
- if (x?.e === true) {
33
- parent.e = false;
34
- x.e = false;
35
- m.e = true;
36
- a = m;
37
- }
38
- else {
39
- if (a === parent.c) {
40
- a = parent;
41
- this.z(a);
42
- parent = a.parent;
43
- m = parent.parent;
44
- }
45
- parent.e = false;
46
- m.e = true;
47
- this.y(m);
48
- }
49
- }
50
- }
51
- this.k.e = false;
52
- }
53
- r(a) {
54
- const { c, d, parent } = a;
55
- if (!c) {
56
- if (!parent) {
57
- this.k = d;
58
- if (d) {
59
- d.parent = undefined;
60
- d.e = false;
61
- }
62
- return;
63
- }
64
- if (parent.c === a) {
65
- parent.c = d;
66
- }
67
- else {
68
- parent.d = d;
69
- }
70
- if (d) {
71
- d.parent = parent;
72
- d.e = false;
73
- return;
74
- }
75
- if (!a.e) {
76
- this.H(parent);
77
- }
78
- return;
79
- }
80
- if (!d) {
81
- if (parent) {
82
- if (parent.c === a) {
83
- parent.c = c;
84
- }
85
- else {
86
- parent.d = c;
87
- }
88
- }
89
- else {
90
- this.k = c;
91
- }
92
- c.parent = parent;
93
- c.e = false;
94
- return;
95
- }
96
- let u;
97
- let replace;
98
- let target = d;
99
- if (!target.c) {
100
- u = target;
101
- replace = target.d;
102
- }
103
- else {
104
- do {
105
- target = target.c;
106
- } while (target.c);
107
- replace = target.d;
108
- u = target.parent;
109
- if (u.c === target) {
110
- u.c = replace;
111
- }
112
- else {
113
- u.d = replace;
114
- }
115
- if (replace) {
116
- replace.parent = u;
117
- }
118
- target.d = d;
119
- d.parent = target;
120
- }
121
- if (parent) {
122
- if (parent.c === a) {
123
- parent.c = target;
124
- }
125
- else {
126
- parent.d = target;
127
- }
128
- }
129
- else {
130
- this.k = target;
131
- }
132
- target.parent = parent;
133
- target.c = c;
134
- c.parent = target;
135
- const L = target.e;
136
- target.e = a.e;
137
- if (replace) {
138
- replace.e = false;
139
- return;
140
- }
141
- if (!L) {
142
- this.H(u);
143
- }
144
- }
145
- H(parent) {
146
- let a;
147
- let h;
148
- for (;;) {
149
- if (a === parent.c) {
150
- h = parent.d;
151
- if (h.e) {
152
- this.y(parent);
153
- h.e = false;
154
- parent.e = true;
155
- h = parent.d;
156
- continue;
157
- }
158
- if (h.d?.e) {
159
- this.y(parent);
160
- h.e = parent.e;
161
- parent.e = false;
162
- h.d.e = false;
163
- return;
164
- }
165
- if (h.c?.e) {
166
- h.c.e = false;
167
- this.z(h);
168
- h.e = true;
169
- h = parent.d;
170
- continue;
171
- }
172
- }
173
- else {
174
- h = parent.c;
175
- if (h.e) {
176
- this.z(parent);
177
- h.e = false;
178
- parent.e = true;
179
- h = parent.c;
180
- continue;
181
- }
182
- if (h.c?.e) {
183
- this.z(parent);
184
- h.e = parent.e;
185
- parent.e = false;
186
- h.c.e = false;
187
- return;
188
- }
189
- if (h.d?.e) {
190
- h.d.e = false;
191
- this.y(h);
192
- h.e = true;
193
- h = parent.c;
194
- continue;
195
- }
196
- }
197
- if (parent.e) {
198
- parent.e = false;
199
- h.e = true;
200
- return;
201
- }
202
- h.e = true;
203
- a = parent;
204
- if (!a.parent) {
205
- return;
206
- }
207
- parent = a.parent;
208
- }
209
- }
210
- y(a) {
211
- const s = a.d;
212
- a.d = s?.c;
213
- if (s?.c) {
214
- s.c.parent = a;
215
- }
216
- s.parent = a.parent;
217
- if (!a.parent) {
218
- this.k = s;
219
- }
220
- else if (a === a.parent.c) {
221
- a.parent.c = s;
222
- }
223
- else {
224
- a.parent.d = s;
225
- }
226
- s.c = a;
227
- a.parent = s;
228
- }
229
- z(a) {
230
- const t = a.c;
231
- a.c = t?.d;
232
- if (t?.d) {
233
- t.d.parent = a;
234
- }
235
- t.parent = a.parent;
236
- if (!a.parent) {
237
- this.k = t;
238
- }
239
- else if (a === a.parent.d) {
240
- a.parent.d = t;
241
- }
242
- else {
243
- a.parent.c = t;
244
- }
245
- t.d = a;
246
- a.parent = t;
247
- }
248
- k;
249
- }
250
- const A = 1;
251
- const B = 2;
252
- const Z = 0;
253
- const O = 1;
254
- const Q = 2;
255
- const E = 3;
256
- class R extends F {
257
- search(key) {
258
- return this.I(key)?.value;
259
- }
260
- delete(key) {
261
- const a = this.I(key);
262
- if (a) {
263
- this.r(a);
264
- return a.value;
265
- }
266
- return;
267
- }
268
- ap(pop) {
269
- let a = this.k;
270
- if (a) {
271
- while (a.c) {
272
- a = a.c;
273
- }
274
- if (pop) {
275
- this.r(a);
276
- }
277
- return a.value;
278
- }
279
- return;
280
- }
281
- M(pop) {
282
- let a = this.k;
283
- if (a) {
284
- while (a.d) {
285
- a = a.d;
286
- }
287
- if (pop) {
288
- this.r(a);
289
- }
290
- return a.value;
291
- }
292
- return;
293
- }
294
- _(key, value, $) {
295
- let a = this.k;
296
- if (a) {
297
- let i;
298
- while (key !== a.key) {
299
- if (key < a.key) {
300
- if (a.c) {
301
- a = a.c;
302
- continue;
303
- }
304
- i = { key, value, e: true, parent: a, c: undefined, d: undefined };
305
- a.c = i;
306
- }
307
- else {
308
- if (a.d) {
309
- a = a.d;
310
- continue;
311
- }
312
- i = { key, value, e: true, parent: a, c: undefined, d: undefined };
313
- a.d = i;
314
- }
315
- this.G(i);
316
- return;
317
- }
318
- const g = a.value;
319
- if ($) {
320
- a.value = value;
321
- }
322
- return g;
323
- }
324
- this.k = { key, value, e: false, parent: undefined, c: undefined, d: undefined };
325
- return;
326
- }
327
- ae(o, n) {
328
- let f = 0;
329
- let a = this.k;
330
- if (a) {
331
- const stack = [];
332
- if (n !== undefined) {
333
- for (;;) {
334
- if (n < a.key) {
335
- if (a.c) {
336
- stack.push(a);
337
- a = a.c;
338
- continue;
339
- }
340
- }
341
- else if (n > a.key) {
342
- if (a.d) {
343
- a = a.d;
344
- continue;
345
- }
346
- return f;
347
- }
348
- break;
349
- }
350
- }
351
- else {
352
- while (a.c) {
353
- stack.push(a);
354
- a = a.c;
355
- }
356
- }
357
- let j;
358
- for (;;) {
359
- const p = o(a.key, a.value);
360
- f++;
361
- if (p & B) {
362
- (j ?? (j = [])).push(a);
363
- }
364
- if (p & A) {
365
- f = -f;
366
- break;
367
- }
368
- if (a.d) {
369
- a = a.d;
370
- while (a.c) {
371
- stack.push(a);
372
- a = a.c;
373
- }
374
- }
375
- else {
376
- a = stack.pop();
377
- if (!a) {
378
- break;
379
- }
380
- }
381
- }
382
- if (j) {
383
- let b = j.length;
384
- while (b > 0) {
385
- this.r(j[--b]);
386
- }
387
- }
388
- }
389
- return f;
390
- }
391
- P(o, n) {
392
- let f = 0;
393
- let a = this.k;
394
- if (a) {
395
- const stack = [];
396
- if (n !== undefined) {
397
- for (;;) {
398
- if (n > a.key) {
399
- if (a.d) {
400
- stack.push(a);
401
- a = a.d;
402
- continue;
403
- }
404
- }
405
- else if (n < a.key) {
406
- if (a.c) {
407
- a = a.c;
408
- continue;
409
- }
410
- return f;
411
- }
412
- break;
413
- }
414
- }
415
- else {
416
- while (a.d) {
417
- stack.push(a);
418
- a = a.d;
419
- }
420
- }
421
- let j;
422
- for (;;) {
423
- const p = o(a.key, a.value);
424
- f++;
425
- if (p & B) {
426
- (j ?? (j = [])).push(a);
427
- }
428
- if (p & A) {
429
- f = -f;
430
- break;
431
- }
432
- if (a.c) {
433
- a = a.c;
434
- while (a.d) {
435
- stack.push(a);
436
- a = a.d;
437
- }
438
- }
439
- else {
440
- a = stack.pop();
441
- if (!a) {
442
- break;
443
- }
444
- }
445
- }
446
- if (j) {
447
- let b = j.length;
448
- while (b > 0) {
449
- this.r(j[--b]);
450
- }
451
- }
452
- }
453
- return f;
454
- }
455
- I(key) {
456
- let a = this.k;
457
- if (a) {
458
- while (key !== a.key) {
459
- if (key < a.key) {
460
- if (a.c) {
461
- a = a.c;
462
- continue;
463
- }
464
- }
465
- else {
466
- if (a.d) {
467
- a = a.d;
468
- continue;
469
- }
470
- }
471
- return;
472
- }
473
- }
474
- return a;
475
- }
476
- }
477
- class J extends F {
478
- search(key) {
479
- let a = this.k;
480
- if (a) {
481
- const { v: D } = this;
482
- let q;
483
- while ((q = D(key, a)) !== 0) {
484
- if (q < 0) {
485
- if (a.c) {
486
- a = a.c;
487
- continue;
488
- }
489
- }
490
- else {
491
- if (a.d) {
492
- a = a.d;
493
- continue;
494
- }
495
- }
496
- return;
497
- }
498
- }
499
- return a;
500
- }
501
- delete(key) {
502
- const a = this.search(key);
503
- if (a) {
504
- this.r(a);
505
- a.e = undefined;
506
- return a;
507
- }
508
- return;
509
- }
510
- ap(pop) {
511
- let a = this.k;
512
- if (a) {
513
- while (a.c) {
514
- a = a.c;
515
- }
516
- if (pop) {
517
- this.r(a);
518
- }
519
- return a;
520
- }
521
- return;
522
- }
523
- M(pop) {
524
- let a = this.k;
525
- if (a) {
526
- while (a.d) {
527
- a = a.d;
528
- }
529
- if (pop) {
530
- this.r(a);
531
- }
532
- return a;
533
- }
534
- return;
535
- }
536
- _(i, $) {
537
- if (i.e !== undefined) {
538
- throw new Error('Cannot insert a node which is already in an ObjRbTree');
539
- }
540
- let a = this.k;
541
- if (a) {
542
- const { v: D } = this;
543
- let q;
544
- while ((q = D(i, a)) !== 0) {
545
- if (q < 0) {
546
- if (a.c) {
547
- a = a.c;
548
- continue;
549
- }
550
- i.e = true;
551
- i.parent = a;
552
- a.c = i;
553
- }
554
- else {
555
- if (a.d) {
556
- a = a.d;
557
- continue;
558
- }
559
- i.e = true;
560
- i.parent = a;
561
- a.d = i;
562
- }
563
- this.G(i);
564
- return;
565
- }
566
- if ($) {
567
- const { parent, c, d, e } = a;
568
- i.parent = parent;
569
- i.e = e;
570
- i.c = c;
571
- i.d = d;
572
- if (parent) {
573
- if (parent.c === a) {
574
- parent.c = i;
575
- }
576
- else {
577
- parent.d = i;
578
- }
579
- }
580
- if (c) {
581
- c.parent = i;
582
- }
583
- if (d) {
584
- d.parent = i;
585
- }
586
- a.e = undefined;
587
- }
588
- return a;
589
- }
590
- i.e = false;
591
- this.k = i;
592
- return;
593
- }
594
- ae(o, n) {
595
- let f = 0;
596
- let a = this.k;
597
- if (a) {
598
- const stack = [];
599
- if (n) {
600
- const { v } = this;
601
- for (;;) {
602
- const q = v(n, a);
603
- if (q < 0) {
604
- if (a.c) {
605
- stack.push(a);
606
- a = a.c;
607
- continue;
608
- }
609
- }
610
- else if (q > 0) {
611
- if (a.d) {
612
- a = a.d;
613
- continue;
614
- }
615
- return f;
616
- }
617
- break;
618
- }
619
- }
620
- else {
621
- while (a.c) {
622
- stack.push(a);
623
- a = a.c;
624
- }
625
- }
626
- let j;
627
- for (;;) {
628
- const p = o(a);
629
- f++;
630
- if (p & B) {
631
- (j ?? (j = [])).push(a);
632
- }
633
- if (p & A) {
634
- f = -f;
635
- break;
636
- }
637
- if (a.d) {
638
- a = a.d;
639
- while (a.c) {
640
- stack.push(a);
641
- a = a.c;
642
- }
643
- }
644
- else {
645
- a = stack.pop();
646
- if (!a) {
647
- break;
648
- }
649
- }
650
- }
651
- if (j) {
652
- let b = j.length;
653
- while (b > 0) {
654
- this.r(j[--b]);
655
- }
656
- }
657
- }
658
- return f;
659
- }
660
- P(o, n) {
661
- let f = 0;
662
- let a = this.k;
663
- if (a) {
664
- const stack = [];
665
- if (n) {
666
- const { v } = this;
667
- for (;;) {
668
- const q = v(n, a);
669
- if (q > 0) {
670
- if (a.d) {
671
- stack.push(a);
672
- a = a.d;
673
- continue;
674
- }
675
- }
676
- else if (q < 0) {
677
- if (a.c) {
678
- a = a.c;
679
- continue;
680
- }
681
- return f;
682
- }
683
- break;
684
- }
685
- }
686
- else {
687
- while (a.d) {
688
- stack.push(a);
689
- a = a.d;
690
- }
691
- }
692
- let j;
693
- for (;;) {
694
- const p = o(a);
695
- f++;
696
- if (p & B) {
697
- (j ?? (j = [])).push(a);
698
- }
699
- if (p & A) {
700
- f = -f;
701
- break;
702
- }
703
- if (a.c) {
704
- a = a.c;
705
- while (a.d) {
706
- stack.push(a);
707
- a = a.d;
708
- }
709
- }
710
- else {
711
- a = stack.pop();
712
- if (!a) {
713
- break;
714
- }
715
- }
716
- }
717
- if (j) {
718
- let b = j.length;
719
- while (b > 0) {
720
- this.r(j[--b]);
721
- }
722
- }
723
- }
724
- return f;
725
- }
726
- }
727
- //# sourceMappingURL=RbTree.js.map