jc-structure 0.2.13 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/jc-structure.js +274 -202
- package/dist/jc-structure.umd.cjs +2 -2
- package/index.d.ts +13 -6
- package/package.json +1 -1
- package/types/global.d.ts +1 -1
- package/types/linkedList.d.ts +1 -1
package/dist/jc-structure.js
CHANGED
|
@@ -1,4 +1,34 @@
|
|
|
1
1
|
class V {
|
|
2
|
+
items = [];
|
|
3
|
+
head = 0;
|
|
4
|
+
tail = 0;
|
|
5
|
+
dequeue() {
|
|
6
|
+
if (this.isEmpty()) return;
|
|
7
|
+
const t = this.items[this.head];
|
|
8
|
+
return this.head++, t;
|
|
9
|
+
}
|
|
10
|
+
enqueue(...t) {
|
|
11
|
+
for (const e of t)
|
|
12
|
+
Array.isArray(e) ? (this.items.push(...e), this.tail += e.length) : (this.items.push(e), this.tail++);
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
front() {
|
|
16
|
+
return this.isEmpty() ? void 0 : this.items[this.head];
|
|
17
|
+
}
|
|
18
|
+
isEmpty() {
|
|
19
|
+
return this.head === this.tail;
|
|
20
|
+
}
|
|
21
|
+
size() {
|
|
22
|
+
return this.tail - this.head;
|
|
23
|
+
}
|
|
24
|
+
cleanup() {
|
|
25
|
+
this.items = [], this.head = 0, this.tail = 0;
|
|
26
|
+
}
|
|
27
|
+
toString() {
|
|
28
|
+
return this.isEmpty() ? "Queue: (0) []" : `Queue: (${this.size()}) [${this.front()} ...]`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class _ {
|
|
2
32
|
items = {};
|
|
3
33
|
count = 0;
|
|
4
34
|
lowestCount = 0;
|
|
@@ -42,14 +72,43 @@ class V {
|
|
|
42
72
|
size() {
|
|
43
73
|
return this.count - this.lowestCount;
|
|
44
74
|
}
|
|
45
|
-
|
|
75
|
+
cleanup() {
|
|
46
76
|
this.items = {}, this.count = 0, this.lowestCount = 0;
|
|
47
77
|
}
|
|
48
78
|
toString() {
|
|
49
|
-
return this.isEmpty() ? "" : `Queue
|
|
79
|
+
return this.isEmpty() ? "Queue: (0) []" : `Queue: (${this.size()}) [${this.front()} ...]`;
|
|
50
80
|
}
|
|
51
81
|
}
|
|
52
|
-
class
|
|
82
|
+
class O {
|
|
83
|
+
_arr;
|
|
84
|
+
constructor() {
|
|
85
|
+
this._arr = [];
|
|
86
|
+
}
|
|
87
|
+
isEmpty() {
|
|
88
|
+
return this._arr.length === 0;
|
|
89
|
+
}
|
|
90
|
+
cleanup() {
|
|
91
|
+
this._arr = [];
|
|
92
|
+
}
|
|
93
|
+
size() {
|
|
94
|
+
return this._arr.length;
|
|
95
|
+
}
|
|
96
|
+
toString() {
|
|
97
|
+
return this.isEmpty() ? "Stack: (0) []" : `Stack: (${this.size()}) [${this.peek()}, ...]`;
|
|
98
|
+
}
|
|
99
|
+
pop() {
|
|
100
|
+
return this._arr.pop();
|
|
101
|
+
}
|
|
102
|
+
push(...t) {
|
|
103
|
+
for (const e of t)
|
|
104
|
+
Array.isArray(e) ? this._arr.push(...e) : this._arr.push(e);
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
peek() {
|
|
108
|
+
return this._arr[this._arr.length - 1];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
class G {
|
|
53
112
|
items = {};
|
|
54
113
|
count = 0;
|
|
55
114
|
constructor() {
|
|
@@ -93,14 +152,14 @@ class F {
|
|
|
93
152
|
size() {
|
|
94
153
|
return this.count;
|
|
95
154
|
}
|
|
96
|
-
|
|
155
|
+
cleanup() {
|
|
97
156
|
this.items = {}, this.count = 0;
|
|
98
157
|
}
|
|
99
158
|
toString() {
|
|
100
|
-
return this.isEmpty() ? "" : `Stack
|
|
159
|
+
return this.isEmpty() ? "Stack: (0) []" : `Stack: (${this.size()}) [ ${this.peek()} ...]`;
|
|
101
160
|
}
|
|
102
161
|
}
|
|
103
|
-
class
|
|
162
|
+
class B {
|
|
104
163
|
stack = [];
|
|
105
164
|
minStack = [];
|
|
106
165
|
push(t) {
|
|
@@ -126,45 +185,16 @@ class _ {
|
|
|
126
185
|
this.stack = [], this.minStack = [];
|
|
127
186
|
}
|
|
128
187
|
toString() {
|
|
129
|
-
return this.isEmpty() ? "" : `
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
class R {
|
|
133
|
-
_arr;
|
|
134
|
-
constructor() {
|
|
135
|
-
this._arr = [];
|
|
136
|
-
}
|
|
137
|
-
isEmpty() {
|
|
138
|
-
return this._arr.length === 0;
|
|
139
|
-
}
|
|
140
|
-
clear() {
|
|
141
|
-
this._arr = [];
|
|
142
|
-
}
|
|
143
|
-
size() {
|
|
144
|
-
return this._arr.length;
|
|
145
|
-
}
|
|
146
|
-
toString() {
|
|
147
|
-
return this.isEmpty() ? "Stack: (0) []" : `Stack: (${this.size()}) [${this.peek()}, ...]`;
|
|
148
|
-
}
|
|
149
|
-
pop() {
|
|
150
|
-
return this._arr.pop();
|
|
151
|
-
}
|
|
152
|
-
push(...t) {
|
|
153
|
-
for (const e of t)
|
|
154
|
-
Array.isArray(e) ? this._arr.push(...e) : this._arr.push(e);
|
|
155
|
-
return this;
|
|
156
|
-
}
|
|
157
|
-
peek() {
|
|
158
|
-
return this._arr[this._arr.length - 1];
|
|
188
|
+
return this.isEmpty() ? "Stack: (0) []" : `Stack: (${this.size()}) [ ${this.peek()} ...]`;
|
|
159
189
|
}
|
|
160
190
|
}
|
|
161
|
-
function
|
|
162
|
-
return
|
|
191
|
+
function T(o, t) {
|
|
192
|
+
return o === t ? 0 : o < t ? -1 : 1;
|
|
163
193
|
}
|
|
164
194
|
class E {
|
|
165
195
|
heap = [];
|
|
166
196
|
compareFn;
|
|
167
|
-
constructor(t =
|
|
197
|
+
constructor(t = T) {
|
|
168
198
|
this.compareFn = t;
|
|
169
199
|
}
|
|
170
200
|
static getLeftIndex(t) {
|
|
@@ -188,14 +218,14 @@ class E {
|
|
|
188
218
|
isEmpty() {
|
|
189
219
|
return this.size() === 0;
|
|
190
220
|
}
|
|
191
|
-
|
|
221
|
+
cleanup() {
|
|
192
222
|
this.heap = [];
|
|
193
223
|
}
|
|
194
224
|
toString() {
|
|
195
225
|
return this.heap.toString();
|
|
196
226
|
}
|
|
197
227
|
}
|
|
198
|
-
class
|
|
228
|
+
class q extends E {
|
|
199
229
|
insert(t) {
|
|
200
230
|
return t ? !1 : (this.heap.push(t), this.siftUp(this.heap.length - 1), !0);
|
|
201
231
|
}
|
|
@@ -215,15 +245,15 @@ class D extends E {
|
|
|
215
245
|
E.swap(this.heap, e, t), t = e, e = E.getParentIndex(t);
|
|
216
246
|
}
|
|
217
247
|
}
|
|
218
|
-
class
|
|
219
|
-
constructor(t = (e, s) =>
|
|
248
|
+
class X extends q {
|
|
249
|
+
constructor(t = (e, s) => T(s, e)) {
|
|
220
250
|
super(t);
|
|
221
251
|
}
|
|
222
252
|
}
|
|
223
|
-
function U(
|
|
224
|
-
return { value:
|
|
253
|
+
function U(o) {
|
|
254
|
+
return { value: o };
|
|
225
255
|
}
|
|
226
|
-
class
|
|
256
|
+
class j {
|
|
227
257
|
capacity;
|
|
228
258
|
length = 0;
|
|
229
259
|
head = null;
|
|
@@ -256,12 +286,12 @@ class B {
|
|
|
256
286
|
s ? (this.detach(s), this.prepend(s), s.value = e) : (s = U(e), this.length++, this.prepend(s), this.trimCache(), this.lookup.set(t, s), this.reverseLookup);
|
|
257
287
|
}
|
|
258
288
|
}
|
|
259
|
-
class
|
|
289
|
+
class k {
|
|
260
290
|
constructor(t, e = null, s = null) {
|
|
261
291
|
this.value = t, this.next = e, this.prev = s;
|
|
262
292
|
}
|
|
263
293
|
}
|
|
264
|
-
class
|
|
294
|
+
class Q {
|
|
265
295
|
count = 0;
|
|
266
296
|
head = null;
|
|
267
297
|
tail = null;
|
|
@@ -320,7 +350,7 @@ class X {
|
|
|
320
350
|
insert(t, e) {
|
|
321
351
|
if (e < 0 || e > this.count)
|
|
322
352
|
throw new Error(`Index out of bounds: ${e}`);
|
|
323
|
-
const s = new
|
|
353
|
+
const s = new k(t);
|
|
324
354
|
if (e === 0)
|
|
325
355
|
s.next = this.head, this.head && (this.head.prev = s), this.head = s, this.count === 0 && (this.tail = s);
|
|
326
356
|
else if (e === this.count)
|
|
@@ -344,7 +374,7 @@ class X {
|
|
|
344
374
|
return this.count++, !0;
|
|
345
375
|
}
|
|
346
376
|
push(t) {
|
|
347
|
-
const e = new
|
|
377
|
+
const e = new k(t);
|
|
348
378
|
this.head ? this.tail && (this.tail.next = e, e.prev = this.tail, this.tail = e) : (this.head = e, this.tail = e), this.count++;
|
|
349
379
|
}
|
|
350
380
|
remove(t) {
|
|
@@ -390,7 +420,7 @@ class X {
|
|
|
390
420
|
size() {
|
|
391
421
|
return this.count;
|
|
392
422
|
}
|
|
393
|
-
|
|
423
|
+
cleanup() {
|
|
394
424
|
this.head = null, this.tail = null, this.count = 0;
|
|
395
425
|
}
|
|
396
426
|
toString() {
|
|
@@ -416,10 +446,10 @@ class H {
|
|
|
416
446
|
this.key = t, this.value = e;
|
|
417
447
|
}
|
|
418
448
|
}
|
|
419
|
-
function
|
|
420
|
-
return
|
|
449
|
+
function N(o, t = { emptyString: !1, zeroNumber: !1 }) {
|
|
450
|
+
return o == null ? !(t.emptyString && o === "" || t.zeroNumber && o === 0) : !1;
|
|
421
451
|
}
|
|
422
|
-
class
|
|
452
|
+
class F {
|
|
423
453
|
table = [];
|
|
424
454
|
constructor() {
|
|
425
455
|
}
|
|
@@ -430,9 +460,9 @@ class q {
|
|
|
430
460
|
return -1;
|
|
431
461
|
}
|
|
432
462
|
set(t, e) {
|
|
433
|
-
if (
|
|
463
|
+
if (N(t))
|
|
434
464
|
throw new Error("key is required");
|
|
435
|
-
if (
|
|
465
|
+
if (N(e))
|
|
436
466
|
throw new Error("value is required");
|
|
437
467
|
if (this.has(t)) {
|
|
438
468
|
let s = this.getItemIndex(t);
|
|
@@ -479,7 +509,7 @@ class q {
|
|
|
479
509
|
size() {
|
|
480
510
|
return this.table.length;
|
|
481
511
|
}
|
|
482
|
-
|
|
512
|
+
cleanup() {
|
|
483
513
|
this.table = [];
|
|
484
514
|
}
|
|
485
515
|
toString() {
|
|
@@ -489,12 +519,12 @@ class q {
|
|
|
489
519
|
return t = t.slice(0, -1), t;
|
|
490
520
|
}
|
|
491
521
|
}
|
|
492
|
-
class
|
|
522
|
+
class W {
|
|
493
523
|
isDirected;
|
|
494
524
|
vertices;
|
|
495
525
|
adjList;
|
|
496
526
|
constructor(t = !1) {
|
|
497
|
-
this.isDirected = t, this.vertices = [], this.adjList = new
|
|
527
|
+
this.isDirected = t, this.vertices = [], this.adjList = new F();
|
|
498
528
|
}
|
|
499
529
|
addVertex(t) {
|
|
500
530
|
this.vertices.includes(t) || (this.vertices.push(t), this.adjList.set(t, []));
|
|
@@ -574,10 +604,10 @@ class w {
|
|
|
574
604
|
return this.mul(-1);
|
|
575
605
|
}
|
|
576
606
|
}
|
|
577
|
-
class
|
|
607
|
+
class S {
|
|
578
608
|
_matrix;
|
|
579
609
|
static zero(t, e) {
|
|
580
|
-
return new
|
|
610
|
+
return new S(
|
|
581
611
|
Array.from({ length: t }, () => Array.from({ length: e }, () => 0))
|
|
582
612
|
);
|
|
583
613
|
}
|
|
@@ -618,7 +648,7 @@ class I {
|
|
|
618
648
|
return this._matrix[t[0]][t[1]] = e, this;
|
|
619
649
|
}
|
|
620
650
|
mul(t) {
|
|
621
|
-
return new
|
|
651
|
+
return new S(this._matrix.map((e) => e.map((s) => s * t)));
|
|
622
652
|
}
|
|
623
653
|
div(t) {
|
|
624
654
|
return this.mul(1 / t);
|
|
@@ -626,7 +656,7 @@ class I {
|
|
|
626
656
|
add(t) {
|
|
627
657
|
if (this.row !== t.row || this.col !== t.col)
|
|
628
658
|
throw new Error("Matrix dimensions do not match");
|
|
629
|
-
return new
|
|
659
|
+
return new S(
|
|
630
660
|
this._matrix.map(
|
|
631
661
|
(e, s) => e.map((r, i) => r + t.getItem([s, i]))
|
|
632
662
|
)
|
|
@@ -644,14 +674,14 @@ class I {
|
|
|
644
674
|
mulVector(t) {
|
|
645
675
|
if (this.col !== t.dimension)
|
|
646
676
|
throw new Error("Matrix dimensions do not match");
|
|
647
|
-
return new
|
|
677
|
+
return new S(
|
|
648
678
|
this._matrix.map((e) => e.map((s, r) => s * t.getItem(r)))
|
|
649
679
|
);
|
|
650
680
|
}
|
|
651
681
|
mulMatrix(t) {
|
|
652
682
|
if (this.col !== t.row)
|
|
653
683
|
throw new Error("Matrix dimensions do not match");
|
|
654
|
-
const e =
|
|
684
|
+
const e = S.zero(this.row, t.col);
|
|
655
685
|
for (let s = 0; s < this.row; s++) {
|
|
656
686
|
const r = this.rowVector(s);
|
|
657
687
|
for (let i = 0; i < this.col; i++)
|
|
@@ -660,7 +690,7 @@ class I {
|
|
|
660
690
|
return e;
|
|
661
691
|
}
|
|
662
692
|
}
|
|
663
|
-
class
|
|
693
|
+
class p {
|
|
664
694
|
static distance(t, e) {
|
|
665
695
|
return Math.hypot(e.x - t.x, e.y - t.y);
|
|
666
696
|
}
|
|
@@ -670,7 +700,7 @@ class u {
|
|
|
670
700
|
this.x = t, this.y = e;
|
|
671
701
|
}
|
|
672
702
|
distanceTo(t) {
|
|
673
|
-
return
|
|
703
|
+
return p.distance(this, t);
|
|
674
704
|
}
|
|
675
705
|
}
|
|
676
706
|
class g {
|
|
@@ -685,12 +715,12 @@ class g {
|
|
|
685
715
|
}
|
|
686
716
|
static getIntersection(t, e, s = g.EPSILON) {
|
|
687
717
|
if (g.isParallel(t, e)) return null;
|
|
688
|
-
const r = t.p1.x, i = t.p1.y, n = t.p2.x, a = t.p2.y,
|
|
718
|
+
const r = t.p1.x, i = t.p1.y, n = t.p2.x, a = t.p2.y, c = e.p1.x, f = e.p1.y, u = e.p2.x, h = e.p2.y, l = (r - n) * (f - h) - (i - a) * (c - u);
|
|
689
719
|
if (Math.abs(l) < s) return null;
|
|
690
|
-
const m = ((r -
|
|
691
|
-
if (m >= 0 && m <= 1 &&
|
|
692
|
-
const
|
|
693
|
-
return new
|
|
720
|
+
const m = ((r - c) * (f - h) - (i - f) * (c - u)) / l, I = -((r - n) * (i - f) - (i - a) * (r - c)) / l;
|
|
721
|
+
if (m >= 0 && m <= 1 && I >= 0 && I <= 1) {
|
|
722
|
+
const R = r + m * (n - r), D = i + m * (a - i);
|
|
723
|
+
return new p(R, D);
|
|
694
724
|
}
|
|
695
725
|
return null;
|
|
696
726
|
}
|
|
@@ -698,13 +728,13 @@ class g {
|
|
|
698
728
|
return g.getIntersection(t, e) !== null;
|
|
699
729
|
}
|
|
700
730
|
static distanceToPoint(t, e, s = g.EPSILON) {
|
|
701
|
-
const r = e.x - t.p1.x, i = e.y - t.p1.y, n = t.p2.x - t.p1.x, a = t.p2.y - t.p1.y,
|
|
702
|
-
let
|
|
703
|
-
f > s && (
|
|
704
|
-
let
|
|
705
|
-
|
|
706
|
-
const m = e.x -
|
|
707
|
-
return Math.hypot(m +
|
|
731
|
+
const r = e.x - t.p1.x, i = e.y - t.p1.y, n = t.p2.x - t.p1.x, a = t.p2.y - t.p1.y, c = r * n + i * a, f = n * n + a * a;
|
|
732
|
+
let u = -1;
|
|
733
|
+
f > s && (u = c / f);
|
|
734
|
+
let h, l;
|
|
735
|
+
u < 0 ? (h = t.p1.x, l = t.p1.y) : u > 1 ? (h = t.p2.x, l = t.p2.y) : (h = t.p1.x + u * n, l = t.p1.y + u * a);
|
|
736
|
+
const m = e.x - h, I = e.y - l;
|
|
737
|
+
return Math.hypot(m + I);
|
|
708
738
|
}
|
|
709
739
|
p1;
|
|
710
740
|
p2;
|
|
@@ -717,7 +747,7 @@ class g {
|
|
|
717
747
|
}
|
|
718
748
|
get midpoint() {
|
|
719
749
|
const t = (this.p1.x + this.p2.x) / 2, e = (this.p1.y + this.p2.y) / 2;
|
|
720
|
-
return new
|
|
750
|
+
return new p(t, e);
|
|
721
751
|
}
|
|
722
752
|
get angle() {
|
|
723
753
|
return Math.atan2(this.p2.y - this.p1.y, this.p2.x - this.p1.x);
|
|
@@ -728,9 +758,9 @@ class g {
|
|
|
728
758
|
}
|
|
729
759
|
get direction() {
|
|
730
760
|
const t = this.length;
|
|
731
|
-
if (t < g.EPSILON) return new
|
|
761
|
+
if (t < g.EPSILON) return new p(0, 0);
|
|
732
762
|
const e = (this.p2.x - this.p1.x) / t, s = (this.p2.y - this.p1.y) / t;
|
|
733
|
-
return new
|
|
763
|
+
return new p(e, s);
|
|
734
764
|
}
|
|
735
765
|
get start() {
|
|
736
766
|
return this.p1;
|
|
@@ -739,31 +769,31 @@ class g {
|
|
|
739
769
|
return this.p2;
|
|
740
770
|
}
|
|
741
771
|
}
|
|
742
|
-
class
|
|
772
|
+
class L {
|
|
743
773
|
static EPSILON = 1e-10;
|
|
744
774
|
name;
|
|
745
775
|
constructor(t) {
|
|
746
776
|
this.name = t;
|
|
747
777
|
}
|
|
748
778
|
}
|
|
749
|
-
class
|
|
779
|
+
class d extends L {
|
|
750
780
|
static isValid(t, e, s) {
|
|
751
781
|
return t <= 0 || e <= 0 || s <= 0 ? !1 : t + e > s && t + s > e && e + s > t;
|
|
752
782
|
}
|
|
753
783
|
static area(t, e, s) {
|
|
754
|
-
if (!
|
|
784
|
+
if (!d.isValid(t, e, s))
|
|
755
785
|
throw new Error("Invalid triangle");
|
|
756
786
|
const r = (t + e + s) / 2;
|
|
757
787
|
return Math.sqrt(r * (r - t) * (r - e) * (r - s));
|
|
758
788
|
}
|
|
759
789
|
static getType(t, e, s) {
|
|
760
|
-
if (!
|
|
790
|
+
if (!d.isValid(t, e, s))
|
|
761
791
|
throw new Error("Invalid triangle sides");
|
|
762
|
-
const r = [t, e, s].sort((
|
|
763
|
-
return Math.abs(i - n) <
|
|
792
|
+
const r = [t, e, s].sort((c, f) => c - f), [i, n, a] = r;
|
|
793
|
+
return Math.abs(i - n) < d.EPSILON && Math.abs(n - a) < d.EPSILON ? "equilateral" : Math.abs(i - n) < d.EPSILON || Math.abs(n - a) < d.EPSILON ? "isosceles" : "scalene";
|
|
764
794
|
}
|
|
765
795
|
static getAngles(t, e, s) {
|
|
766
|
-
if (!
|
|
796
|
+
if (!d.isValid(t, e, s))
|
|
767
797
|
throw new Error("Invalid triangle sides");
|
|
768
798
|
const r = Math.acos((e * e + s * s - t * t) / (2 * e * s)), i = Math.acos((t * t + s * s - e * e) / (2 * t * s)), n = Math.PI - r - i;
|
|
769
799
|
return [r, i, n];
|
|
@@ -779,65 +809,65 @@ class p extends N {
|
|
|
779
809
|
areCollinear() {
|
|
780
810
|
return Math.abs(
|
|
781
811
|
(this.p2.x - this.p1.x) * (this.p3.y - this.p1.y) - (this.p3.x - this.p1.x) * (this.p2.y - this.p1.y)
|
|
782
|
-
) <
|
|
812
|
+
) < L.EPSILON;
|
|
783
813
|
}
|
|
784
814
|
get side() {
|
|
785
815
|
return [
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
816
|
+
p.distance(this.p1, this.p2),
|
|
817
|
+
p.distance(this.p2, this.p3),
|
|
818
|
+
p.distance(this.p3, this.p1)
|
|
789
819
|
];
|
|
790
820
|
}
|
|
791
821
|
perimeter() {
|
|
792
|
-
return
|
|
822
|
+
return d.isValid(this.side[0], this.side[1], this.side[2]), this.side.reduce((t, e) => t + e, 0);
|
|
793
823
|
}
|
|
794
824
|
area() {
|
|
795
825
|
const [t, e, s] = this.side;
|
|
796
|
-
return
|
|
826
|
+
return d.area(t, e, s);
|
|
797
827
|
}
|
|
798
828
|
get type() {
|
|
799
829
|
const [t, e, s] = this.side;
|
|
800
|
-
return
|
|
830
|
+
return d.getType(t, e, s);
|
|
801
831
|
}
|
|
802
832
|
get angles() {
|
|
803
833
|
const [t, e, s] = this.side;
|
|
804
|
-
return
|
|
834
|
+
return d.getAngles(t, e, s);
|
|
805
835
|
}
|
|
806
836
|
get centroid() {
|
|
807
|
-
return new
|
|
837
|
+
return new p(
|
|
808
838
|
(this.p1.x + this.p2.x + this.p3.x) / 3,
|
|
809
839
|
(this.p1.y + this.p2.y + this.p3.y) / 3
|
|
810
840
|
);
|
|
811
841
|
}
|
|
812
842
|
get incenter() {
|
|
813
843
|
const [t, e, s] = this.side, r = this.perimeter() / 2, i = (t * this.p1.x + e * this.p2.x + s * this.p3.x) / r, n = (t * this.p1.y + e * this.p2.y + s * this.p3.y) / r;
|
|
814
|
-
return new
|
|
844
|
+
return new p(i, n);
|
|
815
845
|
}
|
|
816
846
|
get circumcenter() {
|
|
817
847
|
const t = 2 * (this.p1.x * (this.p2.y - this.p3.y) + this.p2.x * (this.p3.y - this.p1.y) + this.p3.x * (this.p1.y - this.p2.y));
|
|
818
|
-
if (Math.abs(t) <
|
|
848
|
+
if (Math.abs(t) < d.EPSILON)
|
|
819
849
|
throw new Error("Cannot calculate circumcenter for collinear points");
|
|
820
850
|
const e = ((this.p1.x * this.p1.x + this.p1.y * this.p1.y) * (this.p2.y - this.p3.y) + (this.p2.x * this.p2.x + this.p2.y * this.p2.y) * (this.p3.y - this.p1.y) + (this.p3.x * this.p3.x + this.p3.y * this.p3.y) * (this.p1.y - this.p2.y)) / t, s = ((this.p1.x * this.p1.x + this.p1.y * this.p1.y) * (this.p3.x - this.p2.x) + (this.p2.x * this.p2.x + this.p2.y * this.p2.y) * (this.p1.x - this.p3.x) + (this.p3.x * this.p3.x + this.p3.y * this.p3.y) * (this.p2.x - this.p1.x)) / t;
|
|
821
|
-
return new
|
|
851
|
+
return new p(e, s);
|
|
822
852
|
}
|
|
823
853
|
containsPoint(t) {
|
|
824
|
-
const e =
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
), s =
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
), r =
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
854
|
+
const e = d.area(
|
|
855
|
+
p.distance(t, this.p1),
|
|
856
|
+
p.distance(t, this.p2),
|
|
857
|
+
p.distance(this.p1, this.p2)
|
|
858
|
+
), s = d.area(
|
|
859
|
+
p.distance(t, this.p2),
|
|
860
|
+
p.distance(t, this.p3),
|
|
861
|
+
p.distance(this.p2, this.p3)
|
|
862
|
+
), r = d.area(
|
|
863
|
+
p.distance(t, this.p3),
|
|
864
|
+
p.distance(t, this.p1),
|
|
865
|
+
p.distance(this.p3, this.p1)
|
|
836
866
|
);
|
|
837
|
-
return Math.abs(e + s + r - this.area()) <
|
|
867
|
+
return Math.abs(e + s + r - this.area()) < d.EPSILON;
|
|
838
868
|
}
|
|
839
869
|
}
|
|
840
|
-
class
|
|
870
|
+
class J {
|
|
841
871
|
static sleep(t) {
|
|
842
872
|
return new Promise((e) => setTimeout(e, t));
|
|
843
873
|
}
|
|
@@ -861,7 +891,7 @@ class W {
|
|
|
861
891
|
return t.prototype.constructor = s, s;
|
|
862
892
|
}
|
|
863
893
|
}
|
|
864
|
-
class
|
|
894
|
+
class Y {
|
|
865
895
|
static groupBy(t, e) {
|
|
866
896
|
if (!e)
|
|
867
897
|
throw new Error("generateKey is required");
|
|
@@ -873,8 +903,8 @@ class Q {
|
|
|
873
903
|
console.warn("Invalid key generated for item:", n);
|
|
874
904
|
continue;
|
|
875
905
|
}
|
|
876
|
-
const
|
|
877
|
-
|
|
906
|
+
const c = r.get(a) ?? [];
|
|
907
|
+
c.push(n), r.set(a, c);
|
|
878
908
|
} catch (a) {
|
|
879
909
|
console.error("Error generating key for item:", n, a);
|
|
880
910
|
}
|
|
@@ -907,23 +937,23 @@ class Q {
|
|
|
907
937
|
return e;
|
|
908
938
|
}
|
|
909
939
|
}
|
|
910
|
-
function
|
|
911
|
-
return
|
|
940
|
+
function P(o) {
|
|
941
|
+
return o !== null && (typeof o == "object" || typeof o == "function");
|
|
912
942
|
}
|
|
913
|
-
class
|
|
943
|
+
class Z {
|
|
914
944
|
map = /* @__PURE__ */ new Map();
|
|
915
945
|
weakMap = /* @__PURE__ */ new WeakMap();
|
|
916
946
|
set(t, e) {
|
|
917
|
-
|
|
947
|
+
P(t) ? this.weakMap.set(t, e) : this.map.set(t, e);
|
|
918
948
|
}
|
|
919
949
|
get(t) {
|
|
920
|
-
return
|
|
950
|
+
return P(t) ? this.weakMap.get(t) : this.map.get(t);
|
|
921
951
|
}
|
|
922
952
|
has(t) {
|
|
923
|
-
return
|
|
953
|
+
return P(t) ? this.weakMap.has(t) : this.map.has(t);
|
|
924
954
|
}
|
|
925
955
|
}
|
|
926
|
-
class
|
|
956
|
+
class K {
|
|
927
957
|
static jsonClone(t) {
|
|
928
958
|
try {
|
|
929
959
|
return JSON.parse(JSON.stringify(t));
|
|
@@ -942,8 +972,8 @@ class Z {
|
|
|
942
972
|
if (t instanceof Map) {
|
|
943
973
|
const n = /* @__PURE__ */ new Map();
|
|
944
974
|
e.set(t, n);
|
|
945
|
-
for (const [a,
|
|
946
|
-
n.set(this.deepClone(a, e), this.deepClone(
|
|
975
|
+
for (const [a, c] of t)
|
|
976
|
+
n.set(this.deepClone(a, e), this.deepClone(c, e));
|
|
947
977
|
return n;
|
|
948
978
|
}
|
|
949
979
|
if (t instanceof Set) {
|
|
@@ -956,7 +986,7 @@ class Z {
|
|
|
956
986
|
if (Array.isArray(t)) {
|
|
957
987
|
const n = new Array(t.length);
|
|
958
988
|
e.set(t, n);
|
|
959
|
-
for (let a = 0,
|
|
989
|
+
for (let a = 0, c = t.length; a < c; a++)
|
|
960
990
|
n[a] = this.deepClone(t[a], e);
|
|
961
991
|
return n;
|
|
962
992
|
}
|
|
@@ -977,8 +1007,8 @@ class Z {
|
|
|
977
1007
|
return new n(t);
|
|
978
1008
|
if (typeof t == "function")
|
|
979
1009
|
return new Proxy(t, {
|
|
980
|
-
apply(n, a,
|
|
981
|
-
return n.apply(a,
|
|
1010
|
+
apply(n, a, c) {
|
|
1011
|
+
return n.apply(a, c);
|
|
982
1012
|
},
|
|
983
1013
|
get(n, a) {
|
|
984
1014
|
if (a in n)
|
|
@@ -993,40 +1023,40 @@ class Z {
|
|
|
993
1023
|
return r;
|
|
994
1024
|
}
|
|
995
1025
|
}
|
|
996
|
-
const
|
|
1026
|
+
const C = {
|
|
997
1027
|
date: "yyyy-MM-dd",
|
|
998
1028
|
datetime: "yyyy-MM-dd HH:mm:ss",
|
|
999
1029
|
time: "HH:mm:ss",
|
|
1000
1030
|
iso: "yyyy-MM-ddTHH:mm:ss.SSS"
|
|
1001
1031
|
};
|
|
1002
|
-
class
|
|
1032
|
+
class v {
|
|
1003
1033
|
static defaultOptions = {
|
|
1004
1034
|
paddingZero: !1,
|
|
1005
1035
|
locale: "en-US"
|
|
1006
1036
|
};
|
|
1007
1037
|
static setDefaultOptions(t) {
|
|
1008
|
-
|
|
1038
|
+
v.defaultOptions = { ...v.defaultOptions, ...t };
|
|
1009
1039
|
}
|
|
1010
1040
|
static format(t, e, s = {}) {
|
|
1011
|
-
const r = { ...
|
|
1012
|
-
return
|
|
1041
|
+
const r = { ...v.defaultOptions, ...s }, i = v.getDateInfo(t, r);
|
|
1042
|
+
return v.normalizeFormatter(e)(i);
|
|
1013
1043
|
}
|
|
1014
1044
|
// 获取日期信息
|
|
1015
1045
|
static getDateInfo(t, e) {
|
|
1016
|
-
const s = (
|
|
1046
|
+
const s = (h, l = 2) => e.paddingZero ? h.toString().padStart(l, "0") : h.toString(), r = t.getFullYear(), i = t.getMonth() + 1, n = t.getDate(), a = t.getHours(), c = t.getMinutes(), f = t.getSeconds(), u = t.getMilliseconds();
|
|
1017
1047
|
return {
|
|
1018
1048
|
year: r,
|
|
1019
1049
|
month: i,
|
|
1020
1050
|
day: n,
|
|
1021
1051
|
hour: a,
|
|
1022
|
-
minute:
|
|
1052
|
+
minute: c,
|
|
1023
1053
|
second: f,
|
|
1024
|
-
millisecond:
|
|
1054
|
+
millisecond: u,
|
|
1025
1055
|
yyyy: s(r, 4),
|
|
1026
1056
|
MM: s(i),
|
|
1027
1057
|
dd: s(n),
|
|
1028
1058
|
HH: s(a),
|
|
1029
|
-
mm: s(
|
|
1059
|
+
mm: s(c),
|
|
1030
1060
|
ss: s(f)
|
|
1031
1061
|
};
|
|
1032
1062
|
}
|
|
@@ -1035,7 +1065,7 @@ class S {
|
|
|
1035
1065
|
return t;
|
|
1036
1066
|
if (typeof t != "string")
|
|
1037
1067
|
throw new Error("Formatter must be a string or function");
|
|
1038
|
-
t in
|
|
1068
|
+
t in C && (t = C[t]);
|
|
1039
1069
|
const e = {
|
|
1040
1070
|
yyyy: "yyyy",
|
|
1041
1071
|
MM: "MM",
|
|
@@ -1056,11 +1086,11 @@ class S {
|
|
|
1056
1086
|
};
|
|
1057
1087
|
}
|
|
1058
1088
|
static formatRelative(t, e = /* @__PURE__ */ new Date()) {
|
|
1059
|
-
const s = t.getTime() - e.getTime(), r = Math.abs(s), i = Math.floor(r / 1e3), n = Math.floor(i / 60), a = Math.floor(n / 60),
|
|
1060
|
-
return
|
|
1089
|
+
const s = t.getTime() - e.getTime(), r = Math.abs(s), i = Math.floor(r / 1e3), n = Math.floor(i / 60), a = Math.floor(n / 60), c = Math.floor(a / 24);
|
|
1090
|
+
return c > 0 ? s > 0 ? `${c}天后` : `${c}天前` : a > 0 ? s > 0 ? `${a}小时后` : `${a}小时前` : n > 0 ? s > 0 ? `${n}分钟后` : `${n}分钟前` : s > 0 ? "刚刚" : "";
|
|
1061
1091
|
}
|
|
1062
1092
|
}
|
|
1063
|
-
class
|
|
1093
|
+
class $ {
|
|
1064
1094
|
lights;
|
|
1065
1095
|
currentIndex;
|
|
1066
1096
|
switchTime;
|
|
@@ -1070,7 +1100,7 @@ class T {
|
|
|
1070
1100
|
{ color: "green", latest: 10 },
|
|
1071
1101
|
{ color: "yellow", latest: 3 }
|
|
1072
1102
|
];
|
|
1073
|
-
constructor(t =
|
|
1103
|
+
constructor(t = $.DEFAULT_LIGHTS) {
|
|
1074
1104
|
this.lights = t, this.currentIndex = 0, this.switchTime = Date.now();
|
|
1075
1105
|
}
|
|
1076
1106
|
render(t) {
|
|
@@ -1095,12 +1125,12 @@ class T {
|
|
|
1095
1125
|
};
|
|
1096
1126
|
}
|
|
1097
1127
|
}
|
|
1098
|
-
class
|
|
1128
|
+
class tt {
|
|
1099
1129
|
static escape(t) {
|
|
1100
1130
|
return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1101
1131
|
}
|
|
1102
1132
|
}
|
|
1103
|
-
class
|
|
1133
|
+
class et {
|
|
1104
1134
|
static ROMAN_MAP = /* @__PURE__ */ new Map([
|
|
1105
1135
|
["M", 1e3],
|
|
1106
1136
|
["CM", 900],
|
|
@@ -1129,10 +1159,10 @@ class K {
|
|
|
1129
1159
|
if (this.ROMAN_MAP.has(n))
|
|
1130
1160
|
s += this.ROMAN_MAP.get(n), r += 2;
|
|
1131
1161
|
else {
|
|
1132
|
-
const a = t[r],
|
|
1133
|
-
if (!
|
|
1162
|
+
const a = t[r], c = this.ROMAN_MAP.get(a);
|
|
1163
|
+
if (!c)
|
|
1134
1164
|
throw new Error(`Invalid Roman numeral sequence at position ${r}`);
|
|
1135
|
-
s +=
|
|
1165
|
+
s += c, r += 1;
|
|
1136
1166
|
}
|
|
1137
1167
|
}
|
|
1138
1168
|
if (this.toRoman(s) !== t)
|
|
@@ -1214,19 +1244,19 @@ class y {
|
|
|
1214
1244
|
return [];
|
|
1215
1245
|
if (e < 0 || !Number.isInteger(e))
|
|
1216
1246
|
throw new Error("Precision must be a non-negative integer");
|
|
1217
|
-
const s = t.reduce((
|
|
1247
|
+
const s = t.reduce((h, l) => h + l, 0);
|
|
1218
1248
|
if (s === 0)
|
|
1219
1249
|
return t.map(() => "0%");
|
|
1220
|
-
const i = 100 * Math.pow(10, e), n = t.map((
|
|
1221
|
-
let f = a.reduce((
|
|
1222
|
-
for (;
|
|
1223
|
-
let
|
|
1224
|
-
for (let m = 0; m <
|
|
1225
|
-
|
|
1226
|
-
if (
|
|
1227
|
-
a[
|
|
1250
|
+
const i = 100 * Math.pow(10, e), n = t.map((h) => h / s * i), a = n.map((h) => Math.floor(h)), c = n.map((h, l) => h - a[l]);
|
|
1251
|
+
let f = a.reduce((h, l) => h + l, 0), u = i - f;
|
|
1252
|
+
for (; u > 0; ) {
|
|
1253
|
+
let h = -1, l = -1;
|
|
1254
|
+
for (let m = 0; m < c.length; m++)
|
|
1255
|
+
c[m] > l && (l = c[m], h = m);
|
|
1256
|
+
if (h === -1) break;
|
|
1257
|
+
a[h]++, c[h] = 0, u--;
|
|
1228
1258
|
}
|
|
1229
|
-
return a.map((
|
|
1259
|
+
return a.map((h) => `${(h / i * 100).toFixed(e)}%`);
|
|
1230
1260
|
}
|
|
1231
1261
|
static gcd(t, e) {
|
|
1232
1262
|
return e === 0 ? t : this.gcd(e, t % e);
|
|
@@ -1318,8 +1348,18 @@ class y {
|
|
|
1318
1348
|
const r = e[1] - e[0];
|
|
1319
1349
|
return (t - e[0]) * ((s[1] - s[0]) / r) + s[0];
|
|
1320
1350
|
}
|
|
1351
|
+
static getPythagoreanTriple(t) {
|
|
1352
|
+
if (t <= 0 || !Number.isInteger(t))
|
|
1353
|
+
throw new Error("n must be a positive integer");
|
|
1354
|
+
if (y.isOdd(t)) {
|
|
1355
|
+
const s = t * t;
|
|
1356
|
+
return [t, (s - 1) / 2, (s + 1) / 2];
|
|
1357
|
+
}
|
|
1358
|
+
const e = t / 2;
|
|
1359
|
+
return [t, e * e - 1, e * e + 1];
|
|
1360
|
+
}
|
|
1321
1361
|
}
|
|
1322
|
-
class
|
|
1362
|
+
class st {
|
|
1323
1363
|
static READ = 1;
|
|
1324
1364
|
static WRITE = 2;
|
|
1325
1365
|
static SHARE = 4;
|
|
@@ -1338,7 +1378,7 @@ class tt {
|
|
|
1338
1378
|
return t ^ e;
|
|
1339
1379
|
}
|
|
1340
1380
|
}
|
|
1341
|
-
class
|
|
1381
|
+
class A {
|
|
1342
1382
|
static frequencyStatistics(t) {
|
|
1343
1383
|
return [...t].reduce(
|
|
1344
1384
|
(e, s) => (e[s] = (e[s] || 0) + 1, e),
|
|
@@ -1407,7 +1447,7 @@ class v {
|
|
|
1407
1447
|
return e;
|
|
1408
1448
|
}
|
|
1409
1449
|
static pointAt(t, e) {
|
|
1410
|
-
if (e >=
|
|
1450
|
+
if (e >= A.pointLength(t)) return;
|
|
1411
1451
|
let s = 0;
|
|
1412
1452
|
for (let r = 0, i = t.length; r < i; ) {
|
|
1413
1453
|
const n = t.codePointAt(r);
|
|
@@ -1417,10 +1457,10 @@ class v {
|
|
|
1417
1457
|
r += n > 65535 ? 2 : 1, s++;
|
|
1418
1458
|
}
|
|
1419
1459
|
}
|
|
1420
|
-
static sliceByPoint(t, e, s =
|
|
1460
|
+
static sliceByPoint(t, e, s = A.pointLength(t)) {
|
|
1421
1461
|
let r = "";
|
|
1422
1462
|
for (let i = e; i < s; i++)
|
|
1423
|
-
r +=
|
|
1463
|
+
r += A.pointAt(t, i);
|
|
1424
1464
|
return r;
|
|
1425
1465
|
}
|
|
1426
1466
|
static capitalize(t) {
|
|
@@ -1433,7 +1473,7 @@ class v {
|
|
|
1433
1473
|
return t.length <= e ? this : t.slice(0, e - s.length) + s;
|
|
1434
1474
|
}
|
|
1435
1475
|
static isPalindrome(t) {
|
|
1436
|
-
return t.toLowerCase().replace(/[^a-z0-9]/g, "") ===
|
|
1476
|
+
return t.toLowerCase().replace(/[^a-z0-9]/g, "") === A.reverse(t);
|
|
1437
1477
|
}
|
|
1438
1478
|
static count(t, e) {
|
|
1439
1479
|
const s = e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -1446,7 +1486,7 @@ class v {
|
|
|
1446
1486
|
return t.replace(/[A-Z]/g, (e) => `_${e.toLowerCase()}`);
|
|
1447
1487
|
}
|
|
1448
1488
|
}
|
|
1449
|
-
class
|
|
1489
|
+
class rt {
|
|
1450
1490
|
static isValidHex(t) {
|
|
1451
1491
|
return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t);
|
|
1452
1492
|
}
|
|
@@ -1466,7 +1506,7 @@ const x = {
|
|
|
1466
1506
|
UI_HIDE_LOADING: "隐藏加载事件",
|
|
1467
1507
|
UI_SHOW_MESSAGE: "显示消息事件"
|
|
1468
1508
|
};
|
|
1469
|
-
class
|
|
1509
|
+
class M {
|
|
1470
1510
|
static instance = null;
|
|
1471
1511
|
listeners = {};
|
|
1472
1512
|
debugMode;
|
|
@@ -1478,7 +1518,7 @@ class A {
|
|
|
1478
1518
|
);
|
|
1479
1519
|
}
|
|
1480
1520
|
static getInstance(t) {
|
|
1481
|
-
return
|
|
1521
|
+
return M.instance || (M.instance = new M(t)), M.instance;
|
|
1482
1522
|
}
|
|
1483
1523
|
on(t, e) {
|
|
1484
1524
|
this.debugLog(`添加事件监听: ${x[t]}`), this.listeners[t].add(e);
|
|
@@ -1512,7 +1552,7 @@ class A {
|
|
|
1512
1552
|
this.debugMode && console.log(`[EventEmitter] ${t}`, e || "");
|
|
1513
1553
|
}
|
|
1514
1554
|
}
|
|
1515
|
-
class
|
|
1555
|
+
class b {
|
|
1516
1556
|
//#region private static members
|
|
1517
1557
|
static OPERATORS = /* @__PURE__ */ new Set(["+", "-", "*", "/"]);
|
|
1518
1558
|
static VALID_CHARS_REG = /^[0-9+\-*/().\s]+$/;
|
|
@@ -1576,7 +1616,7 @@ class P {
|
|
|
1576
1616
|
static EXPRESSION_REG = new RegExp("(?<!\\d)-?\\d*\\.?\\d+|[+\\-*/()]", "g");
|
|
1577
1617
|
static toArr(t) {
|
|
1578
1618
|
this.validateExpression(t);
|
|
1579
|
-
const e = t.match(
|
|
1619
|
+
const e = t.match(b.EXPRESSION_REG);
|
|
1580
1620
|
if (!e)
|
|
1581
1621
|
throw new Error("Invalid expression format");
|
|
1582
1622
|
return e.filter((s) => s.trim() !== "").map((s) => {
|
|
@@ -1588,7 +1628,7 @@ class P {
|
|
|
1588
1628
|
static infixToPostfix(t) {
|
|
1589
1629
|
if (!t?.trim())
|
|
1590
1630
|
throw new Error("Expression cannot be empty");
|
|
1591
|
-
const e = new
|
|
1631
|
+
const e = new O(), s = this.toArr(t);
|
|
1592
1632
|
console.log(s);
|
|
1593
1633
|
const r = [];
|
|
1594
1634
|
for (const i of s)
|
|
@@ -1605,8 +1645,8 @@ class P {
|
|
|
1605
1645
|
static evaluatePostfix(t) {
|
|
1606
1646
|
if (!t.length)
|
|
1607
1647
|
throw new Error("Postfix expression cannot be empty");
|
|
1608
|
-
typeof t == "string" && (t =
|
|
1609
|
-
const e = new
|
|
1648
|
+
typeof t == "string" && (t = b.toArr(t));
|
|
1649
|
+
const e = new O();
|
|
1610
1650
|
for (const s of t)
|
|
1611
1651
|
if (this.FLOAT_NUM_REG.test(s))
|
|
1612
1652
|
e.push(parseFloat(s));
|
|
@@ -1619,12 +1659,21 @@ class P {
|
|
|
1619
1659
|
return e.pop() ?? 0;
|
|
1620
1660
|
}
|
|
1621
1661
|
}
|
|
1622
|
-
class
|
|
1662
|
+
class z {
|
|
1623
1663
|
static isMatchingPair(t, e) {
|
|
1624
1664
|
return t === "(" && e === ")" || t === "{" && e === "}" || t === "[" && e === "]";
|
|
1625
1665
|
}
|
|
1666
|
+
static arr_2d_init(t, e, s = !1) {
|
|
1667
|
+
return typeof s == "boolean" ? Array.from(
|
|
1668
|
+
{ length: t },
|
|
1669
|
+
() => Array(e).fill(s)
|
|
1670
|
+
) : Array.from(
|
|
1671
|
+
{ length: t },
|
|
1672
|
+
() => Array(e).fill(s)
|
|
1673
|
+
);
|
|
1674
|
+
}
|
|
1626
1675
|
static isvalidBrackets(t) {
|
|
1627
|
-
const e = new
|
|
1676
|
+
const e = new O();
|
|
1628
1677
|
for (let s = 0, r = t.length; s < r; s++) {
|
|
1629
1678
|
const i = t[s];
|
|
1630
1679
|
if (["{", "[", "("].includes(i))
|
|
@@ -1639,36 +1688,59 @@ class st {
|
|
|
1639
1688
|
}
|
|
1640
1689
|
return e.isEmpty();
|
|
1641
1690
|
}
|
|
1691
|
+
static findPath(t, e, s) {
|
|
1692
|
+
const r = t.length, i = t[0].length, n = z.arr_2d_init(r, i, !1), a = new O(), c = [
|
|
1693
|
+
[-1, 0],
|
|
1694
|
+
[0, 1],
|
|
1695
|
+
[1, 0],
|
|
1696
|
+
[0, -1]
|
|
1697
|
+
];
|
|
1698
|
+
function f(u, h) {
|
|
1699
|
+
if (u < 0 || u >= r || h < 0 || h >= i || t[u][h] === 1 || n[u][h])
|
|
1700
|
+
return !1;
|
|
1701
|
+
if (t[u][h] === 2)
|
|
1702
|
+
return a.push([u, h]), !0;
|
|
1703
|
+
n[u][h] = !0, a.push([u, h]);
|
|
1704
|
+
for (const [l, m] of c) {
|
|
1705
|
+
const I = u + l, R = h + m;
|
|
1706
|
+
if (f(I, R))
|
|
1707
|
+
return !0;
|
|
1708
|
+
}
|
|
1709
|
+
return a.pop(), !1;
|
|
1710
|
+
}
|
|
1711
|
+
return f(e, s), a;
|
|
1712
|
+
}
|
|
1642
1713
|
}
|
|
1643
1714
|
export {
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1715
|
+
Y as Arr,
|
|
1716
|
+
V as ArrQueue,
|
|
1717
|
+
O as ArrStack,
|
|
1718
|
+
st as BitPerm,
|
|
1719
|
+
rt as Color,
|
|
1720
|
+
v as DateEx,
|
|
1721
|
+
F as Dictionary,
|
|
1722
|
+
M as Emitter,
|
|
1723
|
+
b as Expression,
|
|
1724
|
+
J as Func,
|
|
1725
|
+
W as Graph,
|
|
1726
|
+
j as LRU,
|
|
1655
1727
|
g as Line,
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1728
|
+
Q as LinkedList,
|
|
1729
|
+
S as Matrix,
|
|
1730
|
+
X as MaxHeap,
|
|
1731
|
+
Z as MemoizeMap,
|
|
1732
|
+
q as MinHeap,
|
|
1733
|
+
B as MinStack,
|
|
1662
1734
|
y as Num,
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1735
|
+
K as Obj,
|
|
1736
|
+
_ as ObjQueue,
|
|
1737
|
+
G as ObjStack,
|
|
1738
|
+
p as Point,
|
|
1739
|
+
tt as Reg,
|
|
1740
|
+
et as Roman,
|
|
1741
|
+
z as StackApplication,
|
|
1742
|
+
A as Str,
|
|
1743
|
+
$ as TrafficLight,
|
|
1744
|
+
d as Triangle,
|
|
1673
1745
|
w as Vector
|
|
1674
1746
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(o,O){typeof exports=="object"&&typeof module<"u"?O(exports):typeof define=="function"&&define.amd?define(["exports"],O):(o=typeof globalThis<"u"?globalThis:o||self,O(o["jc-structure"]={}))})(this,(function(o){"use strict";class O{items={};count=0;lowestCount=0;constructor(){}dequeue(){if(this.isEmpty())return;const t=this.items[this.lowestCount];return delete this.items[this.lowestCount],this.lowestCount++,t}enqueue(...t){if(t.length===0)return this;if(t.length===1){const e=t[0];return Array.isArray(e)?this.batchEnqueue(e):this.enqueueItem(e)}for(const e of t)Array.isArray(e)?this.batchEnqueue(e):this.enqueueItem(e);return this}batchEnqueue(t){return t.filter(s=>this.isValidItem(s)).forEach(s=>{this.isValidItem(s)&&(this.items[this.count]=s,this.count++)}),this}enqueueItem(t){if(!this.isValidItem(t))throw new Error("Invalid item");return this.items[this.count]=t,this.count++,this}isValidItem(t){return t!=null}front(){return this.isEmpty()?void 0:this.items[this.lowestCount]}isEmpty(){return this.size()===0}size(){return this.count-this.lowestCount}clear(){this.items={},this.count=0,this.lowestCount=0}toString(){return this.isEmpty()?"":`Queue(size: ${this.size()}):[${this.items[this.lowestCount]},...rest]`}}class U{items={};count=0;constructor(){}pop(){if(this.isEmpty())return;this.count--;const t=this.items[this.count];return delete this.items[this.count],t}push(...t){if(t.length===0)return this;if(t.length===1){const e=t[0];return Array.isArray(e)?this.addItems(e):this.addItem(e)}for(const e of t)Array.isArray(e)?this.addItems(e):this.addItem(e);return this}addItem(t){if(!this.isValidItem(t))throw new Error("Invalid item: item cannot be null or undefined");return this.items[this.count]=t,this.count++,this}addItems(t){return t.filter(s=>this.isValidItem(s)).forEach(s=>{this.items[this.count]=s,this.count++}),this}isValidItem(t){return t!=null}peek(){return this.isEmpty()?void 0:this.items[this.count-1]}isEmpty(){return this.count===0}size(){return this.count}clear(){this.items={},this.count=0}toString(){return this.isEmpty()?"":`Stack(count: ${this.count}):[${this.items[this.count-1]},...rest]`}}class V{stack=[];minStack=[];push(t){this.stack.push(t),(this.minStack.length===0||t<=this.minStack[this.minStack.length-1])&&this.minStack.push(t)}pop(){const t=this.stack.pop();return t===this.minStack[this.minStack.length-1]&&this.minStack.pop(),t}peek(){return this.stack[this.stack.length-1]}getMin(){return this.minStack[this.minStack.length-1]}isEmpty(){return this.size()===0}size(){return this.stack.length}clear(){this.stack=[],this.minStack=[]}toString(){return this.isEmpty()?"":`MinStack(count: ${this.size()}):[${this.getMin()},...rest]`}}class R{_arr;constructor(){this._arr=[]}isEmpty(){return this._arr.length===0}clear(){this._arr=[]}size(){return this._arr.length}toString(){return this.isEmpty()?"Stack: (0) []":`Stack: (${this.size()}) [${this.peek()}, ...]`}pop(){return this._arr.pop()}push(...t){for(const e of t)Array.isArray(e)?this._arr.push(...e):this._arr.push(e);return this}peek(){return this._arr[this._arr.length-1]}}function N(h,t){return h===t?0:h<t?-1:1}class I{heap=[];compareFn;constructor(t=N){this.compareFn=t}static getLeftIndex(t){return 2*t+1}static getRightIndex(t){return 2*t+2}static getParentIndex(t){return t===0?void 0:Math.floor((t-1)/2)}static swap(t,e,s){[t[e],t[s]]=[t[s],t[e]]}find(){return this.isEmpty()?void 0:this.heap[0]}size(){return this.heap.length}isEmpty(){return this.size()===0}clear(){this.heap=[]}toString(){return this.heap.toString()}}class C extends I{insert(t){return t?!1:(this.heap.push(t),this.siftUp(this.heap.length-1),!0)}extract(){if(this.isEmpty())return;if(this.heap.length===1)return this.heap.shift();const t=this.heap[0];return this.heap[0]=this.heap.pop(),this.siftDown(0),t}siftUp(t){let e=t,s=I.getLeftIndex(e),r=I.getRightIndex(e),i=this.size();s<i&&this.compareFn(this.heap[e],this.heap[s])===-1&&(e=s),r<i&&this.compareFn(this.heap[e],this.heap[r])===1&&(e=r),e!==t&&(I.swap(this.heap,t,e),this.siftUp(e))}siftDown(t){let e=I.getParentIndex(t);for(;t>0&&e&&this.compareFn(this.heap[e],this.heap[t])===1;)I.swap(this.heap,e,t),t=e,e=I.getParentIndex(t)}}class q extends C{constructor(t=(e,s)=>N(s,e)){super(t)}}function F(h){return{value:h}}class _{capacity;length=0;head=null;tail=null;lookup=new Map;reverseLookup=new Map;constructor(t=10){this.capacity=t}prepend(t){this.head?(t.next=this.head,this.head.prev=t,this.head=t):this.head=this.tail=t}detach(t){t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),this.head===t&&(this.head=this.head.next||null),this.tail===t&&(this.tail=this.tail.prev||null),t.next=void 0,t.prev=void 0}trimCache(){if(this.length<=this.capacity)return;const t=this.tail;this.detach(t);const e=this.reverseLookup.get(t);this.lookup.delete(e),this.reverseLookup.delete(t),this.length--}get(t){const e=this.lookup.get(t);if(e)return this.detach(e),this.prepend(e),e.value}update(t,e){let s=this.lookup.get(t);s?(this.detach(s),this.prepend(s),s.value=e):(s=F(e),this.length++,this.prepend(s),this.trimCache(),this.lookup.set(t,s),this.reverseLookup)}}class T{constructor(t,e=null,s=null){this.value=t,this.next=e,this.prev=s}}class G{count=0;head=null;tail=null;constructor(t){t&&t.forEach(e=>this.push(e))}[Symbol.iterator](){let t=this.head;return{next(){if(t){const e=t.value;return t=t.next,{value:e,done:!1}}return{value:void 0,done:!0}}}}equals(t,e){if(t===e)return!0;if(t==null||e==null)return!1;if(typeof t=="object"&&typeof e=="object"){if(t.equals&&typeof t.equals=="function")return t.equals(e);const s=Object.keys(t),r=Object.keys(e);return s.length!==r.length?!1:s.every(i=>t[i]===e[i])}return!1}indexOf(t){let e=this.head,s=0;for(;e;){if(this.equals(e.value,t))return s;s++,e=e.next}return-1}getElementAt(t){if(t<0||t>=this.count)return null;if(t>this.count/2){let s=this.tail,r=this.count-1;for(;r>t&&s;)s=s.prev,r--;return s}let e=this.head;for(let s=0;s<t&&e;s++)e=e.next;return e}getValueAt(t){return this.getElementAt(t)?.value}insert(t,e){if(e<0||e>this.count)throw new Error(`Index out of bounds: ${e}`);const s=new T(t);if(e===0)s.next=this.head,this.head&&(this.head.prev=s),this.head=s,this.count===0&&(this.tail=s);else if(e===this.count)s.prev=this.tail,this.tail&&(this.tail.next=s),this.tail=s;else{let r;if(e<this.count/2){r=this.head;for(let i=0;i<e-1&&r;i++)r=r.next}else{r=this.tail;for(let i=this.count-1;i>e-1&&r;i--)r=r.prev}if(r){const i=r.next;s.prev=r,s.next=i,r.next=s,i&&(i.prev=s)}}return this.count++,!0}push(t){const e=new T(t);this.head?this.tail&&(this.tail.next=e,e.prev=this.tail,this.tail=e):(this.head=e,this.tail=e),this.count++}remove(t){let e=this.head,s=this.tail,r=0,i=this.count-1;for(;e&&s;){if(this.equals(e.value,t))return this.removeAt(r);if(this.equals(s.value,t))return this.removeAt(i);if(e=e.next,s=s.prev,r++,i--,r>i)break}return null}removeAt(t){if(t<0||t>=this.count)return null;let e;if(t===0)e=this.head,e&&(this.head=e.next,this.head&&(this.head.prev=null),this.count===1&&(this.tail=null));else if(t===this.count-1)e=this.tail,e&&(this.tail=e.prev,this.tail&&(this.tail.next=null),this.count===1&&(this.head=null));else{if(t<this.count/2){e=this.head;for(let s=0;s<t&&e;s++)e=e.next}else{e=this.tail;for(let s=this.count-1;s>t&&e;s--)e=e.prev}if(e){const s=e.prev,r=e.next;s&&(s.next=r),r&&(r.prev=s)}}return this.count--,e?.value||null}isEmpty(){return this.count===0}size(){return this.count}clear(){this.head=null,this.tail=null,this.count=0}toString(){if(this.isEmpty())return"";let t="",e=this.head;for(;e;)t+=JSON.stringify(e.value),e.next&&(t+=","),e=e.next;return t}toArray(){const t=[];let e=this.head;for(;e;)t.push(e.value),e=e.next;return t}}class B{key;value;constructor(t,e){this.key=t,this.value=e}}function z(h,t={emptyString:!1,zeroNumber:!1}){return h==null?!(t.emptyString&&h===""||t.zeroNumber&&h===0):!1}class ${table=[];constructor(){}getItemIndex(t){for(let e=0,s=this.table.length;e<s;e++)if(this.table[e].key===t)return e;return-1}set(t,e){if(z(t))throw new Error("key is required");if(z(e))throw new Error("value is required");if(this.has(t)){let s=this.getItemIndex(t);this.table[s].value=e}else{const s=new B(t,e);this.table.push(s)}}remove(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table.splice(e,1)[0]}}has(t){return this.getItemIndex(t)!==-1}get(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table[e]}}keys(){return this.table.map(t=>t.key)}values(){return this.table.map(t=>t.value)}keyValues(){return this.table.map(t=>[t.key,t.value])}forEach(t){for(let e=0,s=this.size();e<s;e++){let r=this.table[e];if(!t(r.key,r.value))break}}isEmpty(){return!this.size()}size(){return this.table.length}clear(){this.table=[]}toString(){let t="";for(let e=0,s=this.table.length;e<s;e++)t+=this.table[e].toString(),t+=",";return t=t.slice(0,-1),t}}class j{isDirected;vertices;adjList;constructor(t=!1){this.isDirected=t,this.vertices=[],this.adjList=new $}addVertex(t){this.vertices.includes(t)||(this.vertices.push(t),this.adjList.set(t,[]))}addEdge(t,e){this.adjList.get(t)||this.addVertex(t),this.adjList.get(e)||this.addVertex(e),this.adjList.get(t)?.value.indexOf(e)===-1&&this.adjList.get(t)?.value.push(e),this.isDirected||this.adjList.get(e)?.value.indexOf(t)===-1&&this.adjList.get(e)?.value.push(t)}getVertices(){return this.vertices}getAdjacencyList(){return this.adjList}toString(){let t="";for(let e=0;e<this.vertices.length;e++)t+=this.vertices[e]+"-->",t+=this.adjList.get(this.vertices[e])?.toString()||"",t+=`
|
|
2
|
-
`;return t}}class E{_data;static zero(t){return new E(...Array(t).fill(0))}constructor(...t){this._data=t}get dimension(){return this._data.length}get norm(){return Math.hypot(...this._data)}getItem(t){return this._data[t]}normalize(){const t=this.norm;if(t===0)throw new Error("Cannot normalize a zero vector");const e=this._data.map(s=>s/t);return new E(...e)}add(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to add");const e=this._data.map((s,r)=>s+t._data[r]);return new E(...e)}sub(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to subtract");const e=this._data.map((s,r)=>s-t._data[r]);return new E(...e)}mul(t){return new E(...this._data.map(e=>e*t))}dot(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to dot product");return this._data.reduce((e,s,r)=>e+s*t._data[r],0)}pos(){return this.mul(1)}neg(){return this.mul(-1)}}class S{_matrix;static zero(t,e){return new S(Array.from({length:t},()=>Array.from({length:e},()=>0)))}static rotate(t){const e=t.length;for(let s=0;s<(e+1)/2;s++)for(let r=s;r<e/2;r++){const i=t[e-1-r][s];t[e-1-r][s]=t[e-1-s][e-1-r],t[e-1-s][e-1-r]=t[r][e-1-s],t[r][e-1-s]=t[s][r],t[s][r]=i}return t}constructor(t){this._matrix=t}get shape(){return[this._matrix.length,this._matrix[0].length]}get row(){return this.shape[0]}get col(){return this.shape[1]}get size(){return this.row*this.col}rowVector(t){return new E(...this._matrix[t])}colVector(t){return new E(...this._matrix.map(e=>e[t]))}getItem(t){return this._matrix[t[0]][t[1]]}setItem(t,e){return this._matrix[t[0]][t[1]]=e,this}mul(t){return new S(this._matrix.map(e=>e.map(s=>s*t)))}div(t){return this.mul(1/t)}add(t){if(this.row!==t.row||this.col!==t.col)throw new Error("Matrix dimensions do not match");return new S(this._matrix.map((e,s)=>e.map((r,i)=>r+t.getItem([s,i]))))}sub(t){return this.add(t.neg())}pos(){return this.mul(1)}neg(){return this.mul(-1)}mulVector(t){if(this.col!==t.dimension)throw new Error("Matrix dimensions do not match");return new S(this._matrix.map(e=>e.map((s,r)=>s*t.getItem(r))))}mulMatrix(t){if(this.col!==t.row)throw new Error("Matrix dimensions do not match");const e=S.zero(this.row,t.col);for(let s=0;s<this.row;s++){const r=this.rowVector(s);for(let i=0;i<this.col;i++)e.setItem([s,i],r.dot(t.colVector(i)))}return e}}class l{static distance(t,e){return Math.hypot(e.x-t.x,e.y-t.y)}x;y;constructor(t,e){this.x=t,this.y=e}distanceTo(t){return l.distance(this,t)}}class g{static EPSILON=1e-10;static sloped(t,e=g.EPSILON){const s=t.p2.x-t.p1.x,r=t.p2.y-t.p1.y;return Math.abs(s)<e?Math.abs(r)<e?0:null:r/s}static isParallel(t,e,s=g.EPSILON){const r=g.sloped(t),i=g.sloped(e);return r===null&&i===null?!0:r===null||i===null?!1:Math.abs(r-i)<s}static getIntersection(t,e,s=g.EPSILON){if(g.isParallel(t,e))return null;const r=t.p1.x,i=t.p1.y,n=t.p2.x,a=t.p2.y,c=e.p1.x,d=e.p1.y,m=e.p2.x,u=e.p2.y,p=(r-n)*(d-u)-(i-a)*(c-m);if(Math.abs(p)<s)return null;const y=((r-c)*(d-u)-(i-d)*(c-m))/p,b=-((r-n)*(i-d)-(i-a)*(r-c))/p;if(y>=0&&y<=1&&b>=0&&b<=1){const st=r+y*(n-r),rt=i+y*(a-i);return new l(st,rt)}return null}static isIntersecting(t,e){return g.getIntersection(t,e)!==null}static distanceToPoint(t,e,s=g.EPSILON){const r=e.x-t.p1.x,i=e.y-t.p1.y,n=t.p2.x-t.p1.x,a=t.p2.y-t.p1.y,c=r*n+i*a,d=n*n+a*a;let m=-1;d>s&&(m=c/d);let u,p;m<0?(u=t.p1.x,p=t.p1.y):m>1?(u=t.p2.x,p=t.p2.y):(u=t.p1.x+m*n,p=t.p1.y+m*a);const y=e.x-u,b=e.y-p;return Math.hypot(y+b)}p1;p2;constructor(t,e){this.p1=t,this.p2=e}get length(){const t=this.p2.x-this.p1.x,e=this.p2.y-this.p1.y;return Math.sqrt(t*t+e*e)}get midpoint(){const t=(this.p1.x+this.p2.x)/2,e=(this.p1.y+this.p2.y)/2;return new l(t,e)}get angle(){return Math.atan2(this.p2.y-this.p1.y,this.p2.x-this.p1.x)}containsPoint(t,e=g.EPSILON){const s=(t.x-this.p1.x)*(this.p2.y-this.p1.y)-(t.y-this.p1.y)*(this.p2.x-this.p1.x);return Math.abs(s)>e?!1:(t.x-this.p1.x)*(t.x-this.p2.x)+(t.y-this.p1.y)*(t.y-this.p2.y)<=e}get direction(){const t=this.length;if(t<g.EPSILON)return new l(0,0);const e=(this.p2.x-this.p1.x)/t,s=(this.p2.y-this.p1.y)/t;return new l(e,s)}get start(){return this.p1}get end(){return this.p2}}class D{static EPSILON=1e-10;name;constructor(t){this.name=t}}class f extends D{static isValid(t,e,s){return t<=0||e<=0||s<=0?!1:t+e>s&&t+s>e&&e+s>t}static area(t,e,s){if(!f.isValid(t,e,s))throw new Error("Invalid triangle");const r=(t+e+s)/2;return Math.sqrt(r*(r-t)*(r-e)*(r-s))}static getType(t,e,s){if(!f.isValid(t,e,s))throw new Error("Invalid triangle sides");const r=[t,e,s].sort((c,d)=>c-d),[i,n,a]=r;return Math.abs(i-n)<f.EPSILON&&Math.abs(n-a)<f.EPSILON?"equilateral":Math.abs(i-n)<f.EPSILON||Math.abs(n-a)<f.EPSILON?"isosceles":"scalene"}static getAngles(t,e,s){if(!f.isValid(t,e,s))throw new Error("Invalid triangle sides");const r=Math.acos((e*e+s*s-t*t)/(2*e*s)),i=Math.acos((t*t+s*s-e*e)/(2*t*s)),n=Math.PI-r-i;return[r,i,n]}p1;p2;p3;constructor(t,e,s,r="triangle"){if(super(r),this.p1=t,this.p2=e,this.p3=s,this.areCollinear())throw new Error("Points are collinear, cannot form a triangle")}areCollinear(){return Math.abs((this.p2.x-this.p1.x)*(this.p3.y-this.p1.y)-(this.p3.x-this.p1.x)*(this.p2.y-this.p1.y))<D.EPSILON}get side(){return[l.distance(this.p1,this.p2),l.distance(this.p2,this.p3),l.distance(this.p3,this.p1)]}perimeter(){return f.isValid(this.side[0],this.side[1],this.side[2]),this.side.reduce((t,e)=>t+e,0)}area(){const[t,e,s]=this.side;return f.area(t,e,s)}get type(){const[t,e,s]=this.side;return f.getType(t,e,s)}get angles(){const[t,e,s]=this.side;return f.getAngles(t,e,s)}get centroid(){return new l((this.p1.x+this.p2.x+this.p3.x)/3,(this.p1.y+this.p2.y+this.p3.y)/3)}get incenter(){const[t,e,s]=this.side,r=this.perimeter()/2,i=(t*this.p1.x+e*this.p2.x+s*this.p3.x)/r,n=(t*this.p1.y+e*this.p2.y+s*this.p3.y)/r;return new l(i,n)}get circumcenter(){const t=2*(this.p1.x*(this.p2.y-this.p3.y)+this.p2.x*(this.p3.y-this.p1.y)+this.p3.x*(this.p1.y-this.p2.y));if(Math.abs(t)<f.EPSILON)throw new Error("Cannot calculate circumcenter for collinear points");const e=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p2.y-this.p3.y)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p3.y-this.p1.y)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p1.y-this.p2.y))/t,s=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p3.x-this.p2.x)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p1.x-this.p3.x)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p2.x-this.p1.x))/t;return new l(e,s)}containsPoint(t){const e=f.area(l.distance(t,this.p1),l.distance(t,this.p2),l.distance(this.p1,this.p2)),s=f.area(l.distance(t,this.p2),l.distance(t,this.p3),l.distance(this.p2,this.p3)),r=f.area(l.distance(t,this.p3),l.distance(t,this.p1),l.distance(this.p3,this.p1));return Math.abs(e+s+r-this.area())<f.EPSILON}}class X{static sleep(t){return new Promise(e=>setTimeout(e,t))}static binarySearchTemplate(t,e,s){let r=-1,i=t.length,n;for(;i-r>1;)n=i-(i-r)>>1,s(t[n],e)?i=n:r=n;return i}static singleton(t){let e;const s=new Proxy(t,{construct(r,i,n){return e||(e=Reflect.construct(r,i,n)),e}});return t.prototype.constructor=s,s}}class W{static groupBy(t,e){if(!e)throw new Error("generateKey is required");const s=typeof e=="string"?i=>i[e]:e,r=new Map;for(const[i,n]of t.entries())try{const a=s(n,i,t);if(a==null){console.warn("Invalid key generated for item:",n);continue}const c=r.get(a)??[];c.push(n),r.set(a,c)}catch(a){console.error("Error generating key for item:",n,a)}return Object.fromEntries(r)}static LIS(t){if(!t.length)return[];const e=[[t[0]]];for(let r=1,i=t.length;r<i;r++){const n=t[r];s(n)}function s(r){for(let i=e.length-1;i>=0;i--){const n=e[i],a=n[e[i].length-1];if(a<r){e[i+1]=[...n,r];break}else a>r&&i===0&&(e[i]=[r])}}return e[e.length-1]}static LCP(t){if(!t.length)return"";let e=t[0];for(let s=1;s<t.length;s++)for(;!t[s].startsWith(e);)if(e=e.slice(0,-1),e==="")return"";return e}}function k(h){return h!==null&&(typeof h=="object"||typeof h=="function")}class Q{map=new Map;weakMap=new WeakMap;set(t,e){k(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return k(t)?this.weakMap.get(t):this.map.get(t)}has(t){return k(t)?this.weakMap.has(t):this.map.has(t)}}class J{static jsonClone(t){try{return JSON.parse(JSON.stringify(t))}catch{throw new Error("Object is not JSON cloneable")}}static structureClone(t){return structuredClone(t)}static deepClone(t,e=new WeakMap){if(t==null||typeof t!="object")return t;if(e.has(t))return e.get(t);if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp)return new RegExp(t.source,t.flags);if(t instanceof Map){const n=new Map;e.set(t,n);for(const[a,c]of t)n.set(this.deepClone(a,e),this.deepClone(c,e));return n}if(t instanceof Set){const n=new Set;e.set(t,n);for(const a of t)n.add(this.deepClone(a,e));return n}if(Array.isArray(t)){const n=new Array(t.length);e.set(t,n);for(let a=0,c=t.length;a<c;a++)n[a]=this.deepClone(t[a],e);return n}if(t instanceof ArrayBuffer)return t.slice(0);const s=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];for(const n of s)if(t instanceof n)return new n(t);if(typeof t=="function")return new Proxy(t,{apply(n,a,c){return n.apply(a,c)},get(n,a){if(a in n)return n[a]}});const r=Object.create(Object.getPrototypeOf(t));e.set(t,r);const i=Object.getOwnPropertyDescriptors(t);for(const[n,a]of Object.entries(i))a.value!==void 0&&(a.value=this.deepClone(a.value,e)),Object.defineProperty(r,n,a);return r}}const H={date:"yyyy-MM-dd",datetime:"yyyy-MM-dd HH:mm:ss",time:"HH:mm:ss",iso:"yyyy-MM-ddTHH:mm:ss.SSS"};class M{static defaultOptions={paddingZero:!1,locale:"en-US"};static setDefaultOptions(t){M.defaultOptions={...M.defaultOptions,...t}}static format(t,e,s={}){const r={...M.defaultOptions,...s},i=M.getDateInfo(t,r);return M.normalizeFormatter(e)(i)}static getDateInfo(t,e){const s=(u,p=2)=>e.paddingZero?u.toString().padStart(p,"0"):u.toString(),r=t.getFullYear(),i=t.getMonth()+1,n=t.getDate(),a=t.getHours(),c=t.getMinutes(),d=t.getSeconds(),m=t.getMilliseconds();return{year:r,month:i,day:n,hour:a,minute:c,second:d,millisecond:m,yyyy:s(r,4),MM:s(i),dd:s(n),HH:s(a),mm:s(c),ss:s(d)}}static normalizeFormatter(t){if(typeof t=="function")return t;if(typeof t!="string")throw new Error("Formatter must be a string or function");t in H&&(t=H[t]);const e={yyyy:"yyyy",MM:"MM",dd:"dd",HH:"HH",mm:"mm",ss:"ss",SSS:"SSS"};return s=>{let r=t;for(const[i,n]of Object.entries(e))r=r.replace(new RegExp(i,"g"),String(s[n]||""));return r}}static formatRelative(t,e=new Date){const s=t.getTime()-e.getTime(),r=Math.abs(s),i=Math.floor(r/1e3),n=Math.floor(i/60),a=Math.floor(n/60),c=Math.floor(a/24);return c>0?s>0?`${c}天后`:`${c}天前`:a>0?s>0?`${a}小时后`:`${a}小时前`:n>0?s>0?`${n}分钟后`:`${n}分钟前`:s>0?"刚刚":""}}class L{lights;currentIndex;switchTime;static DEFAULT_LIGHTS=[{color:"red",latest:7},{color:"yellow",latest:3},{color:"green",latest:10},{color:"yellow",latest:3}];constructor(t=L.DEFAULT_LIGHTS){this.lights=t,this.currentIndex=0,this.switchTime=Date.now()}render(t){requestAnimationFrame(this.render.bind(this,t));const e=this.getCurrentLight();t(e)}get current(){return this.lights[this.currentIndex]}get disTime(){return Date.now()-this.switchTime}update(){for(;!(this.disTime<this.current.latest);)this.switchTime+=this.current.latest*1e3,this.currentIndex=(this.currentIndex+1)%this.lights.length}getCurrentLight(){return this.update(),{color:this.current.color,remain:this.current.latest-this.disTime}}}class Z{static escape(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}}class Y{static ROMAN_MAP=new Map([["M",1e3],["CM",900],["D",500],["CD",400],["C",100],["XC",90],["L",50],["XL",40],["X",10],["IX",9],["V",5],["IV",4],["I",1]]);static toInteger(t){if(t.length===0)throw new Error("Input cannot be empty");const e=new Set(["I","V","X","L","C","D","M"]);for(const n of t)if(!e.has(n))throw new Error(`Invalid Roman numeral character: ${n}`);let s=0,r=0;for(;r<t.length;){const n=t.slice(r,r+2);if(this.ROMAN_MAP.has(n))s+=this.ROMAN_MAP.get(n),r+=2;else{const a=t[r],c=this.ROMAN_MAP.get(a);if(!c)throw new Error(`Invalid Roman numeral sequence at position ${r}`);s+=c,r+=1}}if(this.toRoman(s)!==t)throw new Error("Invalid Roman numeral sequence");return s}static toRoman(t){if(t<=0||t>=4e3)throw new Error("Number must be between 1 and 3999");if(!Number.isInteger(t))throw new Error("Number must be an integer");let e="";for(const[s,r]of this.ROMAN_MAP)for(;t>=r;)e+=s,t-=r;return e}}class w{static handleNumRange(t,e=!1,s=Number.MIN_SAFE_INTEGER,r=Number.MAX_SAFE_INTEGER){if(e&&!Number.isInteger(t))throw new Error("n must be an integer");if(t<s||t>=r)throw new RangeError(`n must be in the range of ${s} to ${r}`)}static consecutiveSum(t){return w.handleNumRange(t,!0,0,1e8),t*(t+1)/2}static consecutiveSquaresSum(t){return w.handleNumRange(t,!0,0,1e6),t*(t+1)*(2*t+1)/6}static consecutivecubesSum(t){return w.handleNumRange(t,!0,0,1e4),t*(t+1)*(2*t+1)*(3*t*t+3*t-1)/30}static clamp(t,e,s){return s==null?Math.min(t,e):Math.min(Math.max(t,e),s)}static factorial(t){if(w.handleNumRange(t,!0,0,1e3),t<2)return 1;let e=1;for(let s=2;s<=t;s++)e*=s;return e}static fibonacci(t,e=1,s=1){return w.handleNumRange(t,!0,0,1e3),t<2?s:this.fibonacci(t-1,s,s+e)}static fibonacciIterative(t){if(w.handleNumRange(t,!0,0,1e3),t<2)return t;let e=0,s=1;for(let r=2;r<=t;r++)[e,s]=[s,(e+s)%1000000007];return s}static floatEqual(t,e,s=1e-6){return Math.abs(t-e)<s}static fastPower(t,e){if(w.handleNumRange(e,!0,0,10),w.handleNumRange(t,!1,0,1e3),t===0)return 0;if(e===0)return 1;const s=this.fastPower(t,e>>1);return e%2===0?s*s:s*s*t}static fastSqrt(t){if(w.handleNumRange(t,!1,0,1e8),typeof BigInt>"u")return Math.sqrt(t);const e=.5*t,s=new ArrayBuffer(8);new Float64Array(s)[0]=t;let r=new BigInt64Array(s)[0];r=0x1ff7a3bea91d9b1bn+(r>>1n);const i=new ArrayBuffer(8);new BigInt64Array(i)[0]=r;let n=new Float64Array(i)[0];return n=n*.5+e/n,n=n*.5+e/n,n=n*.5+e/n,n}static getPercentWithPrecision(t,e=2){if(!Array.isArray(t)||t.length===0)return[];if(e<0||!Number.isInteger(e))throw new Error("Precision must be a non-negative integer");const s=t.reduce((u,p)=>u+p,0);if(s===0)return t.map(()=>"0%");const i=100*Math.pow(10,e),n=t.map(u=>u/s*i),a=n.map(u=>Math.floor(u)),c=n.map((u,p)=>u-a[p]);let d=a.reduce((u,p)=>u+p,0),m=i-d;for(;m>0;){let u=-1,p=-1;for(let y=0;y<c.length;y++)c[y]>p&&(p=c[y],u=y);if(u===-1)break;a[u]++,c[u]=0,m--}return a.map(u=>`${(u/i*100).toFixed(e)}%`)}static gcd(t,e){return e===0?t:this.gcd(e,t%e)}static isValidPositiveInteger(t){return Number.isInteger(t)&&t>0&&t<=Number.MAX_SAFE_INTEGER}static isPowerOfTwo(t){return t>0&&(t&t-1)===0}static isOdd(t){return t%2===1||t%2===-1}static isPrime(t){if(t<=1)return!1;for(let e=2;e<=Math.sqrt(t);e++)if(t%e===0)return!1;return!0}static isPalindrome(t){if(t<0||t%10===0&&t!==0)return!1;let e=0,s=t;for(;t>0;){const r=t%10;e=e*10+r,t=Math.floor(t/10)}return s===e}static isArmstrong(t){const e=t.toString(),s=e.length;let r=0;for(let i=0;i<s;i++)r+=Math.pow(parseInt(e[i]),s);return r===t}static isHappy(t){const e=new Set;for(;t!==1;){if(e.has(t))return!1;e.add(t),t=(t+"").split("").reduce((s,r)=>s+Number(r)*Number(r),0)}return!0}static isPerfect(t){let e=0;for(let s=1;s<t;s++)t%s===0&&(e+=s);return e===t}static isSameSign(t,e){return t>=0&&e>=0||t<=0&&e<=0}static isRange(t,e,s){if(s==null&&(s=e,e=0),e>=s)throw new Error("The maximum value must be greater than the minimum value");return e<=t&&t<s}static lcm(t,e){return t*e/this.gcd(t,e)}static middle(t,e){return e-(e-t>>1)}static random(t,e){if(e==null&&(e=t,t=0),t>=e)throw new Error("The maximum value must be greater than the minimum value");return Math.random()*(e-t)+t}static randomInt(t,e){return Math.floor(this.random(t,e))}static round(t,e=0){if(!Number.isInteger(e))throw new Error("precision must be an integer");const s=Math.pow(10,e);return Math.round(t*s)/s}static scale(t,e,s){if(e[0]>=e[1]||s[0]>=s[1])throw new Error("Invalid range");t=this.clamp(t,e[0],e[1]);const r=e[1]-e[0];return(t-e[0])*((s[1]-s[0])/r)+s[0]}}class K{static READ=1;static WRITE=2;static SHARE=4;static DELETE=8;static CREATE=16;static include(t,e){return(t&e)===e}static add(t,e){return t|e}static remove(t,e){return t&~e}static toggle(t,e){return t^e}}class x{static frequencyStatistics(t){return[...t].reduce((e,s)=>(e[s]=(e[s]||0)+1,e),{})}static isValidBracket(t){const e=[],s={"(":")","[":"]","{":"}"},r=new Set(Object.values(s));for(const i of t)if(i in s)e.push(s[i]);else if(r.has(i)&&i!==e.pop())return!1;return e.length===0}static random(t=8){const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let s="";for(let r=0;r<t;r++)s+=e.charAt(Math.floor(Math.random()*e.length));return s}static template(t,e){return t.replace(/\${(\w+)}/g,(s,r)=>e[r]||"")}static escapeHtml(t){const e={"&":"&","<":"<",">":">",'"':""","'":"'"," ":" ","±":"±","×":"×","÷":"÷","≠":"≠","≤":"≤","≥":"≥"},s=new RegExp(`[${Object.keys(e).join("")}]`,"g");return t.replace(s,r=>e[r])}static isEmail(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}static isUrl(t){try{return new URL(t),!0}catch{return!1}}static pointLength(t){let e=0;for(let s=0,r=t.length;s<r;){const i=t.codePointAt(s);s+=i>65535?2:1,e++}return e}static pointAt(t,e){if(e>=x.pointLength(t))return;let s=0;for(let r=0,i=t.length;r<i;){const n=t.codePointAt(r);if(!n)return;if(s===e)return String.fromCodePoint(n);r+=n>65535?2:1,s++}}static sliceByPoint(t,e,s=x.pointLength(t)){let r="";for(let i=e;i<s;i++)r+=x.pointAt(t,i);return r}static capitalize(t){return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}static reverse(t){return t.split("").reverse().join("")}static truncate(t,e,s="..."){return t.length<=e?this:t.slice(0,e-s.length)+s}static isPalindrome(t){return t.toLowerCase().replace(/[^a-z0-9]/g,"")===x.reverse(t)}static count(t,e){const s=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return(t.match(new RegExp(s,"g"))||[]).length}static toCamelCase(t){return t.replace(/_([a-z])/g,(e,s)=>s.toUpperCase())}static toSnakeCase(t){return t.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`)}}class tt{static isValidHex(t){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t)}static isValidRGB(t){return/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.test(t)}}const v={AUTH_UNAUTHORIZED:"未授权事件",AUTH_LOGIN_SUCCESS:"登录成功事件",AUTH_LOGOUT:"注销事件",AUTH_TOKEN_EXPIRED:"令牌过期事件",REQUEST_ERROR:"请求错误事件",REQUEST_TIMEOUT:"请求超时事件",REQUEST_NETWORK_ERROR:"网络错误事件",UI_SHOW_LOADING:"显示加载事件",UI_HIDE_LOADING:"隐藏加载事件",UI_SHOW_MESSAGE:"显示消息事件"};class A{static instance=null;listeners={};debugMode;constructor(t=!1){this.debugMode=t,Object.keys(v).forEach(e=>{this.listeners[e]=new Set})}static getInstance(t){return A.instance||(A.instance=new A(t)),A.instance}on(t,e){this.debugLog(`添加事件监听: ${v[t]}`),this.listeners[t].add(e)}emit(t,e){this.debugLog(`触发事件: ${v[t]}`,e),this.listeners[t].forEach(s=>{try{s(e)}catch(r){console.error(`事件 ${v[t]} 处理出错:`,r)}})}off(t,e){this.debugLog(`移除事件监听: ${v[t]}`),this.listeners[t].delete(e)}once(t,e){this.debugLog(`添加一次性事件监听: ${v[t]}`);const s=r=>{e(r),this.off(t,s)};this.on(t,s)}clear(){this.debugLog("清除所有事件监听器"),Object.values(this.listeners).forEach(t=>t.clear())}getListenerCount(t){return this.listeners[t].size}debugLog(t,e){this.debugMode&&console.log(`[EventEmitter] ${t}`,e||"")}}class P{static OPERATORS=new Set(["+","-","*","/"]);static VALID_CHARS_REG=/^[0-9+\-*/().\s]+$/;static PRIORITY_MAP=new Map([["+",1],["-",1],["*",2],["/",2],["(",0],[")",0]]);static getPriority(t){return this.PRIORITY_MAP.get(t)??0}static validateExpression(t){if(!t)throw new Error("Expression cannot be empty");if(!this.VALID_CHARS_REG.test(t))throw new Error("Expression contains invalid characters")}static processClosingParenthesis(t,e){for(;!t.isEmpty();){if(t.peek()==="("){t.pop();break}const r=t.pop();r&&e.push(r)}}static processOperator(t,e,s){for(;!e.isEmpty();){const r=e.peek();if(!r||r==="(")break;if(this.getPriority(t)<=this.getPriority(r)){const i=e.pop();i&&s.push(i)}else break}e.push(t)}static applyOperator(t,e,s){switch(s){case"+":return t+e;case"-":return t-e;case"*":return t*e;case"/":if(e===0)throw new Error("Division by zero");return t/e;default:throw new Error("Invalid operator")}}static FLOAT_NUM_REG=/^-?\d*\.?\d+$/;static EXPRESSION_REG=new RegExp("(?<!\\d)-?\\d*\\.?\\d+|[+\\-*/()]","g");static toArr(t){this.validateExpression(t);const e=t.match(P.EXPRESSION_REG);if(!e)throw new Error("Invalid expression format");return e.filter(s=>s.trim()!=="").map(s=>{if(this.FLOAT_NUM_REG.test(s)||this.OPERATORS.has(s)||s==="("||s===")")return s;throw new Error(`Invalid token: ${s}`)})}static infixToPostfix(t){if(!t?.trim())throw new Error("Expression cannot be empty");const e=new R,s=this.toArr(t);console.log(s);const r=[];for(const i of s)this.FLOAT_NUM_REG.test(i)?r.push(i):i==="("?e.push(i):i===")"?this.processClosingParenthesis(e,r):this.OPERATORS.has(i)&&this.processOperator(i,e,r);for(;!e.isEmpty();){const i=e.pop();i&&i!=="("&&r.push(i)}return{postfix:r.join(" "),postfixArr:r}}static evaluatePostfix(t){if(!t.length)throw new Error("Postfix expression cannot be empty");typeof t=="string"&&(t=P.toArr(t));const e=new R;for(const s of t)if(this.FLOAT_NUM_REG.test(s))e.push(parseFloat(s));else if(this.OPERATORS.has(s)){const r=e.pop(),i=e.pop();if(i===void 0||r===void 0)throw new Error("Invalid postfix expression");e.push(this.applyOperator(i,r,s))}return e.pop()??0}}class et{static isMatchingPair(t,e){return t==="("&&e===")"||t==="{"&&e==="}"||t==="["&&e==="]"}static isvalidBrackets(t){const e=new R;for(let s=0,r=t.length;s<r;s++){const i=t[s];if(["{","[","("].includes(i))e.push(i);else if(["}","]",")"].includes(i)){if(e.isEmpty())return!1;const n=e.pop();if(!n||!this.isMatchingPair(n,i))return!1}}return e.isEmpty()}}o.Arr=W,o.ArrStack=R,o.BitPerm=K,o.Color=tt,o.DateEx=M,o.Dictionary=$,o.Emitter=A,o.Expression=P,o.Func=X,o.Graph=j,o.LRU=_,o.Line=g,o.LinkedList=G,o.Matrix=S,o.MaxHeap=q,o.MemoizeMap=Q,o.MinHeap=C,o.MinStack=V,o.Num=w,o.Obj=J,o.Point=l,o.Queue=O,o.Reg=Z,o.Roman=Y,o.Stack=U,o.StackApplication=et,o.Str=x,o.TrafficLight=L,o.Triangle=f,o.Vector=E,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(o,R){typeof exports=="object"&&typeof module<"u"?R(exports):typeof define=="function"&&define.amd?define(["exports"],R):(o=typeof globalThis<"u"?globalThis:o||self,R(o["jc-structure"]={}))})(this,(function(o){"use strict";class R{items=[];head=0;tail=0;dequeue(){if(this.isEmpty())return;const t=this.items[this.head];return this.head++,t}enqueue(...t){for(const e of t)Array.isArray(e)?(this.items.push(...e),this.tail+=e.length):(this.items.push(e),this.tail++);return this}front(){return this.isEmpty()?void 0:this.items[this.head]}isEmpty(){return this.head===this.tail}size(){return this.tail-this.head}cleanup(){this.items=[],this.head=0,this.tail=0}toString(){return this.isEmpty()?"Queue: (0) []":`Queue: (${this.size()}) [${this.front()} ...]`}}class F{items={};count=0;lowestCount=0;constructor(){}dequeue(){if(this.isEmpty())return;const t=this.items[this.lowestCount];return delete this.items[this.lowestCount],this.lowestCount++,t}enqueue(...t){if(t.length===0)return this;if(t.length===1){const e=t[0];return Array.isArray(e)?this.batchEnqueue(e):this.enqueueItem(e)}for(const e of t)Array.isArray(e)?this.batchEnqueue(e):this.enqueueItem(e);return this}batchEnqueue(t){return t.filter(s=>this.isValidItem(s)).forEach(s=>{this.isValidItem(s)&&(this.items[this.count]=s,this.count++)}),this}enqueueItem(t){if(!this.isValidItem(t))throw new Error("Invalid item");return this.items[this.count]=t,this.count++,this}isValidItem(t){return t!=null}front(){return this.isEmpty()?void 0:this.items[this.lowestCount]}isEmpty(){return this.size()===0}size(){return this.count-this.lowestCount}cleanup(){this.items={},this.count=0,this.lowestCount=0}toString(){return this.isEmpty()?"Queue: (0) []":`Queue: (${this.size()}) [${this.front()} ...]`}}class P{_arr;constructor(){this._arr=[]}isEmpty(){return this._arr.length===0}cleanup(){this._arr=[]}size(){return this._arr.length}toString(){return this.isEmpty()?"Stack: (0) []":`Stack: (${this.size()}) [${this.peek()}, ...]`}pop(){return this._arr.pop()}push(...t){for(const e of t)Array.isArray(e)?this._arr.push(...e):this._arr.push(e);return this}peek(){return this._arr[this._arr.length-1]}}class V{items={};count=0;constructor(){}pop(){if(this.isEmpty())return;this.count--;const t=this.items[this.count];return delete this.items[this.count],t}push(...t){if(t.length===0)return this;if(t.length===1){const e=t[0];return Array.isArray(e)?this.addItems(e):this.addItem(e)}for(const e of t)Array.isArray(e)?this.addItems(e):this.addItem(e);return this}addItem(t){if(!this.isValidItem(t))throw new Error("Invalid item: item cannot be null or undefined");return this.items[this.count]=t,this.count++,this}addItems(t){return t.filter(s=>this.isValidItem(s)).forEach(s=>{this.items[this.count]=s,this.count++}),this}isValidItem(t){return t!=null}peek(){return this.isEmpty()?void 0:this.items[this.count-1]}isEmpty(){return this.count===0}size(){return this.count}cleanup(){this.items={},this.count=0}toString(){return this.isEmpty()?"Stack: (0) []":`Stack: (${this.size()}) [ ${this.peek()} ...]`}}class _{stack=[];minStack=[];push(t){this.stack.push(t),(this.minStack.length===0||t<=this.minStack[this.minStack.length-1])&&this.minStack.push(t)}pop(){const t=this.stack.pop();return t===this.minStack[this.minStack.length-1]&&this.minStack.pop(),t}peek(){return this.stack[this.stack.length-1]}getMin(){return this.minStack[this.minStack.length-1]}isEmpty(){return this.size()===0}size(){return this.stack.length}clear(){this.stack=[],this.minStack=[]}toString(){return this.isEmpty()?"Stack: (0) []":`Stack: (${this.size()}) [ ${this.peek()} ...]`}}function T(c,t){return c===t?0:c<t?-1:1}class I{heap=[];compareFn;constructor(t=T){this.compareFn=t}static getLeftIndex(t){return 2*t+1}static getRightIndex(t){return 2*t+2}static getParentIndex(t){return t===0?void 0:Math.floor((t-1)/2)}static swap(t,e,s){[t[e],t[s]]=[t[s],t[e]]}find(){return this.isEmpty()?void 0:this.heap[0]}size(){return this.heap.length}isEmpty(){return this.size()===0}cleanup(){this.heap=[]}toString(){return this.heap.toString()}}class $ extends I{insert(t){return t?!1:(this.heap.push(t),this.siftUp(this.heap.length-1),!0)}extract(){if(this.isEmpty())return;if(this.heap.length===1)return this.heap.shift();const t=this.heap[0];return this.heap[0]=this.heap.pop(),this.siftDown(0),t}siftUp(t){let e=t,s=I.getLeftIndex(e),r=I.getRightIndex(e),i=this.size();s<i&&this.compareFn(this.heap[e],this.heap[s])===-1&&(e=s),r<i&&this.compareFn(this.heap[e],this.heap[r])===1&&(e=r),e!==t&&(I.swap(this.heap,t,e),this.siftUp(e))}siftDown(t){let e=I.getParentIndex(t);for(;t>0&&e&&this.compareFn(this.heap[e],this.heap[t])===1;)I.swap(this.heap,e,t),t=e,e=I.getParentIndex(t)}}class G extends ${constructor(t=(e,s)=>T(s,e)){super(t)}}function B(c){return{value:c}}class j{capacity;length=0;head=null;tail=null;lookup=new Map;reverseLookup=new Map;constructor(t=10){this.capacity=t}prepend(t){this.head?(t.next=this.head,this.head.prev=t,this.head=t):this.head=this.tail=t}detach(t){t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),this.head===t&&(this.head=this.head.next||null),this.tail===t&&(this.tail=this.tail.prev||null),t.next=void 0,t.prev=void 0}trimCache(){if(this.length<=this.capacity)return;const t=this.tail;this.detach(t);const e=this.reverseLookup.get(t);this.lookup.delete(e),this.reverseLookup.delete(t),this.length--}get(t){const e=this.lookup.get(t);if(e)return this.detach(e),this.prepend(e),e.value}update(t,e){let s=this.lookup.get(t);s?(this.detach(s),this.prepend(s),s.value=e):(s=B(e),this.length++,this.prepend(s),this.trimCache(),this.lookup.set(t,s),this.reverseLookup)}}class z{constructor(t,e=null,s=null){this.value=t,this.next=e,this.prev=s}}class Q{count=0;head=null;tail=null;constructor(t){t&&t.forEach(e=>this.push(e))}[Symbol.iterator](){let t=this.head;return{next(){if(t){const e=t.value;return t=t.next,{value:e,done:!1}}return{value:void 0,done:!0}}}}equals(t,e){if(t===e)return!0;if(t==null||e==null)return!1;if(typeof t=="object"&&typeof e=="object"){if(t.equals&&typeof t.equals=="function")return t.equals(e);const s=Object.keys(t),r=Object.keys(e);return s.length!==r.length?!1:s.every(i=>t[i]===e[i])}return!1}indexOf(t){let e=this.head,s=0;for(;e;){if(this.equals(e.value,t))return s;s++,e=e.next}return-1}getElementAt(t){if(t<0||t>=this.count)return null;if(t>this.count/2){let s=this.tail,r=this.count-1;for(;r>t&&s;)s=s.prev,r--;return s}let e=this.head;for(let s=0;s<t&&e;s++)e=e.next;return e}getValueAt(t){return this.getElementAt(t)?.value}insert(t,e){if(e<0||e>this.count)throw new Error(`Index out of bounds: ${e}`);const s=new z(t);if(e===0)s.next=this.head,this.head&&(this.head.prev=s),this.head=s,this.count===0&&(this.tail=s);else if(e===this.count)s.prev=this.tail,this.tail&&(this.tail.next=s),this.tail=s;else{let r;if(e<this.count/2){r=this.head;for(let i=0;i<e-1&&r;i++)r=r.next}else{r=this.tail;for(let i=this.count-1;i>e-1&&r;i--)r=r.prev}if(r){const i=r.next;s.prev=r,s.next=i,r.next=s,i&&(i.prev=s)}}return this.count++,!0}push(t){const e=new z(t);this.head?this.tail&&(this.tail.next=e,e.prev=this.tail,this.tail=e):(this.head=e,this.tail=e),this.count++}remove(t){let e=this.head,s=this.tail,r=0,i=this.count-1;for(;e&&s;){if(this.equals(e.value,t))return this.removeAt(r);if(this.equals(s.value,t))return this.removeAt(i);if(e=e.next,s=s.prev,r++,i--,r>i)break}return null}removeAt(t){if(t<0||t>=this.count)return null;let e;if(t===0)e=this.head,e&&(this.head=e.next,this.head&&(this.head.prev=null),this.count===1&&(this.tail=null));else if(t===this.count-1)e=this.tail,e&&(this.tail=e.prev,this.tail&&(this.tail.next=null),this.count===1&&(this.head=null));else{if(t<this.count/2){e=this.head;for(let s=0;s<t&&e;s++)e=e.next}else{e=this.tail;for(let s=this.count-1;s>t&&e;s--)e=e.prev}if(e){const s=e.prev,r=e.next;s&&(s.next=r),r&&(r.prev=s)}}return this.count--,e?.value||null}isEmpty(){return this.count===0}size(){return this.count}cleanup(){this.head=null,this.tail=null,this.count=0}toString(){if(this.isEmpty())return"";let t="",e=this.head;for(;e;)t+=JSON.stringify(e.value),e.next&&(t+=","),e=e.next;return t}toArray(){const t=[];let e=this.head;for(;e;)t.push(e.value),e=e.next;return t}}class X{key;value;constructor(t,e){this.key=t,this.value=e}}function D(c,t={emptyString:!1,zeroNumber:!1}){return c==null?!(t.emptyString&&c===""||t.zeroNumber&&c===0):!1}class H{table=[];constructor(){}getItemIndex(t){for(let e=0,s=this.table.length;e<s;e++)if(this.table[e].key===t)return e;return-1}set(t,e){if(D(t))throw new Error("key is required");if(D(e))throw new Error("value is required");if(this.has(t)){let s=this.getItemIndex(t);this.table[s].value=e}else{const s=new X(t,e);this.table.push(s)}}remove(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table.splice(e,1)[0]}}has(t){return this.getItemIndex(t)!==-1}get(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table[e]}}keys(){return this.table.map(t=>t.key)}values(){return this.table.map(t=>t.value)}keyValues(){return this.table.map(t=>[t.key,t.value])}forEach(t){for(let e=0,s=this.size();e<s;e++){let r=this.table[e];if(!t(r.key,r.value))break}}isEmpty(){return!this.size()}size(){return this.table.length}cleanup(){this.table=[]}toString(){let t="";for(let e=0,s=this.table.length;e<s;e++)t+=this.table[e].toString(),t+=",";return t=t.slice(0,-1),t}}class W{isDirected;vertices;adjList;constructor(t=!1){this.isDirected=t,this.vertices=[],this.adjList=new H}addVertex(t){this.vertices.includes(t)||(this.vertices.push(t),this.adjList.set(t,[]))}addEdge(t,e){this.adjList.get(t)||this.addVertex(t),this.adjList.get(e)||this.addVertex(e),this.adjList.get(t)?.value.indexOf(e)===-1&&this.adjList.get(t)?.value.push(e),this.isDirected||this.adjList.get(e)?.value.indexOf(t)===-1&&this.adjList.get(e)?.value.push(t)}getVertices(){return this.vertices}getAdjacencyList(){return this.adjList}toString(){let t="";for(let e=0;e<this.vertices.length;e++)t+=this.vertices[e]+"-->",t+=this.adjList.get(this.vertices[e])?.toString()||"",t+=`
|
|
2
|
+
`;return t}}class E{_data;static zero(t){return new E(...Array(t).fill(0))}constructor(...t){this._data=t}get dimension(){return this._data.length}get norm(){return Math.hypot(...this._data)}getItem(t){return this._data[t]}normalize(){const t=this.norm;if(t===0)throw new Error("Cannot normalize a zero vector");const e=this._data.map(s=>s/t);return new E(...e)}add(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to add");const e=this._data.map((s,r)=>s+t._data[r]);return new E(...e)}sub(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to subtract");const e=this._data.map((s,r)=>s-t._data[r]);return new E(...e)}mul(t){return new E(...this._data.map(e=>e*t))}dot(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to dot product");return this._data.reduce((e,s,r)=>e+s*t._data[r],0)}pos(){return this.mul(1)}neg(){return this.mul(-1)}}class S{_matrix;static zero(t,e){return new S(Array.from({length:t},()=>Array.from({length:e},()=>0)))}static rotate(t){const e=t.length;for(let s=0;s<(e+1)/2;s++)for(let r=s;r<e/2;r++){const i=t[e-1-r][s];t[e-1-r][s]=t[e-1-s][e-1-r],t[e-1-s][e-1-r]=t[r][e-1-s],t[r][e-1-s]=t[s][r],t[s][r]=i}return t}constructor(t){this._matrix=t}get shape(){return[this._matrix.length,this._matrix[0].length]}get row(){return this.shape[0]}get col(){return this.shape[1]}get size(){return this.row*this.col}rowVector(t){return new E(...this._matrix[t])}colVector(t){return new E(...this._matrix.map(e=>e[t]))}getItem(t){return this._matrix[t[0]][t[1]]}setItem(t,e){return this._matrix[t[0]][t[1]]=e,this}mul(t){return new S(this._matrix.map(e=>e.map(s=>s*t)))}div(t){return this.mul(1/t)}add(t){if(this.row!==t.row||this.col!==t.col)throw new Error("Matrix dimensions do not match");return new S(this._matrix.map((e,s)=>e.map((r,i)=>r+t.getItem([s,i]))))}sub(t){return this.add(t.neg())}pos(){return this.mul(1)}neg(){return this.mul(-1)}mulVector(t){if(this.col!==t.dimension)throw new Error("Matrix dimensions do not match");return new S(this._matrix.map(e=>e.map((s,r)=>s*t.getItem(r))))}mulMatrix(t){if(this.col!==t.row)throw new Error("Matrix dimensions do not match");const e=S.zero(this.row,t.col);for(let s=0;s<this.row;s++){const r=this.rowVector(s);for(let i=0;i<this.col;i++)e.setItem([s,i],r.dot(t.colVector(i)))}return e}}class p{static distance(t,e){return Math.hypot(e.x-t.x,e.y-t.y)}x;y;constructor(t,e){this.x=t,this.y=e}distanceTo(t){return p.distance(this,t)}}class y{static EPSILON=1e-10;static sloped(t,e=y.EPSILON){const s=t.p2.x-t.p1.x,r=t.p2.y-t.p1.y;return Math.abs(s)<e?Math.abs(r)<e?0:null:r/s}static isParallel(t,e,s=y.EPSILON){const r=y.sloped(t),i=y.sloped(e);return r===null&&i===null?!0:r===null||i===null?!1:Math.abs(r-i)<s}static getIntersection(t,e,s=y.EPSILON){if(y.isParallel(t,e))return null;const r=t.p1.x,i=t.p1.y,n=t.p2.x,a=t.p2.y,u=e.p1.x,m=e.p1.y,l=e.p2.x,h=e.p2.y,f=(r-n)*(m-h)-(i-a)*(u-l);if(Math.abs(f)<s)return null;const g=((r-u)*(m-h)-(i-m)*(u-l))/f,O=-((r-n)*(i-m)-(i-a)*(r-u))/f;if(g>=0&&g<=1&&O>=0&&O<=1){const C=r+g*(n-r),it=i+g*(a-i);return new p(C,it)}return null}static isIntersecting(t,e){return y.getIntersection(t,e)!==null}static distanceToPoint(t,e,s=y.EPSILON){const r=e.x-t.p1.x,i=e.y-t.p1.y,n=t.p2.x-t.p1.x,a=t.p2.y-t.p1.y,u=r*n+i*a,m=n*n+a*a;let l=-1;m>s&&(l=u/m);let h,f;l<0?(h=t.p1.x,f=t.p1.y):l>1?(h=t.p2.x,f=t.p2.y):(h=t.p1.x+l*n,f=t.p1.y+l*a);const g=e.x-h,O=e.y-f;return Math.hypot(g+O)}p1;p2;constructor(t,e){this.p1=t,this.p2=e}get length(){const t=this.p2.x-this.p1.x,e=this.p2.y-this.p1.y;return Math.sqrt(t*t+e*e)}get midpoint(){const t=(this.p1.x+this.p2.x)/2,e=(this.p1.y+this.p2.y)/2;return new p(t,e)}get angle(){return Math.atan2(this.p2.y-this.p1.y,this.p2.x-this.p1.x)}containsPoint(t,e=y.EPSILON){const s=(t.x-this.p1.x)*(this.p2.y-this.p1.y)-(t.y-this.p1.y)*(this.p2.x-this.p1.x);return Math.abs(s)>e?!1:(t.x-this.p1.x)*(t.x-this.p2.x)+(t.y-this.p1.y)*(t.y-this.p2.y)<=e}get direction(){const t=this.length;if(t<y.EPSILON)return new p(0,0);const e=(this.p2.x-this.p1.x)/t,s=(this.p2.y-this.p1.y)/t;return new p(e,s)}get start(){return this.p1}get end(){return this.p2}}class U{static EPSILON=1e-10;name;constructor(t){this.name=t}}class d extends U{static isValid(t,e,s){return t<=0||e<=0||s<=0?!1:t+e>s&&t+s>e&&e+s>t}static area(t,e,s){if(!d.isValid(t,e,s))throw new Error("Invalid triangle");const r=(t+e+s)/2;return Math.sqrt(r*(r-t)*(r-e)*(r-s))}static getType(t,e,s){if(!d.isValid(t,e,s))throw new Error("Invalid triangle sides");const r=[t,e,s].sort((u,m)=>u-m),[i,n,a]=r;return Math.abs(i-n)<d.EPSILON&&Math.abs(n-a)<d.EPSILON?"equilateral":Math.abs(i-n)<d.EPSILON||Math.abs(n-a)<d.EPSILON?"isosceles":"scalene"}static getAngles(t,e,s){if(!d.isValid(t,e,s))throw new Error("Invalid triangle sides");const r=Math.acos((e*e+s*s-t*t)/(2*e*s)),i=Math.acos((t*t+s*s-e*e)/(2*t*s)),n=Math.PI-r-i;return[r,i,n]}p1;p2;p3;constructor(t,e,s,r="triangle"){if(super(r),this.p1=t,this.p2=e,this.p3=s,this.areCollinear())throw new Error("Points are collinear, cannot form a triangle")}areCollinear(){return Math.abs((this.p2.x-this.p1.x)*(this.p3.y-this.p1.y)-(this.p3.x-this.p1.x)*(this.p2.y-this.p1.y))<U.EPSILON}get side(){return[p.distance(this.p1,this.p2),p.distance(this.p2,this.p3),p.distance(this.p3,this.p1)]}perimeter(){return d.isValid(this.side[0],this.side[1],this.side[2]),this.side.reduce((t,e)=>t+e,0)}area(){const[t,e,s]=this.side;return d.area(t,e,s)}get type(){const[t,e,s]=this.side;return d.getType(t,e,s)}get angles(){const[t,e,s]=this.side;return d.getAngles(t,e,s)}get centroid(){return new p((this.p1.x+this.p2.x+this.p3.x)/3,(this.p1.y+this.p2.y+this.p3.y)/3)}get incenter(){const[t,e,s]=this.side,r=this.perimeter()/2,i=(t*this.p1.x+e*this.p2.x+s*this.p3.x)/r,n=(t*this.p1.y+e*this.p2.y+s*this.p3.y)/r;return new p(i,n)}get circumcenter(){const t=2*(this.p1.x*(this.p2.y-this.p3.y)+this.p2.x*(this.p3.y-this.p1.y)+this.p3.x*(this.p1.y-this.p2.y));if(Math.abs(t)<d.EPSILON)throw new Error("Cannot calculate circumcenter for collinear points");const e=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p2.y-this.p3.y)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p3.y-this.p1.y)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p1.y-this.p2.y))/t,s=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p3.x-this.p2.x)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p1.x-this.p3.x)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p2.x-this.p1.x))/t;return new p(e,s)}containsPoint(t){const e=d.area(p.distance(t,this.p1),p.distance(t,this.p2),p.distance(this.p1,this.p2)),s=d.area(p.distance(t,this.p2),p.distance(t,this.p3),p.distance(this.p2,this.p3)),r=d.area(p.distance(t,this.p3),p.distance(t,this.p1),p.distance(this.p3,this.p1));return Math.abs(e+s+r-this.area())<d.EPSILON}}class J{static sleep(t){return new Promise(e=>setTimeout(e,t))}static binarySearchTemplate(t,e,s){let r=-1,i=t.length,n;for(;i-r>1;)n=i-(i-r)>>1,s(t[n],e)?i=n:r=n;return i}static singleton(t){let e;const s=new Proxy(t,{construct(r,i,n){return e||(e=Reflect.construct(r,i,n)),e}});return t.prototype.constructor=s,s}}class Y{static groupBy(t,e){if(!e)throw new Error("generateKey is required");const s=typeof e=="string"?i=>i[e]:e,r=new Map;for(const[i,n]of t.entries())try{const a=s(n,i,t);if(a==null){console.warn("Invalid key generated for item:",n);continue}const u=r.get(a)??[];u.push(n),r.set(a,u)}catch(a){console.error("Error generating key for item:",n,a)}return Object.fromEntries(r)}static LIS(t){if(!t.length)return[];const e=[[t[0]]];for(let r=1,i=t.length;r<i;r++){const n=t[r];s(n)}function s(r){for(let i=e.length-1;i>=0;i--){const n=e[i],a=n[e[i].length-1];if(a<r){e[i+1]=[...n,r];break}else a>r&&i===0&&(e[i]=[r])}}return e[e.length-1]}static LCP(t){if(!t.length)return"";let e=t[0];for(let s=1;s<t.length;s++)for(;!t[s].startsWith(e);)if(e=e.slice(0,-1),e==="")return"";return e}}function k(c){return c!==null&&(typeof c=="object"||typeof c=="function")}class Z{map=new Map;weakMap=new WeakMap;set(t,e){k(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return k(t)?this.weakMap.get(t):this.map.get(t)}has(t){return k(t)?this.weakMap.has(t):this.map.has(t)}}class K{static jsonClone(t){try{return JSON.parse(JSON.stringify(t))}catch{throw new Error("Object is not JSON cloneable")}}static structureClone(t){return structuredClone(t)}static deepClone(t,e=new WeakMap){if(t==null||typeof t!="object")return t;if(e.has(t))return e.get(t);if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp)return new RegExp(t.source,t.flags);if(t instanceof Map){const n=new Map;e.set(t,n);for(const[a,u]of t)n.set(this.deepClone(a,e),this.deepClone(u,e));return n}if(t instanceof Set){const n=new Set;e.set(t,n);for(const a of t)n.add(this.deepClone(a,e));return n}if(Array.isArray(t)){const n=new Array(t.length);e.set(t,n);for(let a=0,u=t.length;a<u;a++)n[a]=this.deepClone(t[a],e);return n}if(t instanceof ArrayBuffer)return t.slice(0);const s=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];for(const n of s)if(t instanceof n)return new n(t);if(typeof t=="function")return new Proxy(t,{apply(n,a,u){return n.apply(a,u)},get(n,a){if(a in n)return n[a]}});const r=Object.create(Object.getPrototypeOf(t));e.set(t,r);const i=Object.getOwnPropertyDescriptors(t);for(const[n,a]of Object.entries(i))a.value!==void 0&&(a.value=this.deepClone(a.value,e)),Object.defineProperty(r,n,a);return r}}const q={date:"yyyy-MM-dd",datetime:"yyyy-MM-dd HH:mm:ss",time:"HH:mm:ss",iso:"yyyy-MM-ddTHH:mm:ss.SSS"};class A{static defaultOptions={paddingZero:!1,locale:"en-US"};static setDefaultOptions(t){A.defaultOptions={...A.defaultOptions,...t}}static format(t,e,s={}){const r={...A.defaultOptions,...s},i=A.getDateInfo(t,r);return A.normalizeFormatter(e)(i)}static getDateInfo(t,e){const s=(h,f=2)=>e.paddingZero?h.toString().padStart(f,"0"):h.toString(),r=t.getFullYear(),i=t.getMonth()+1,n=t.getDate(),a=t.getHours(),u=t.getMinutes(),m=t.getSeconds(),l=t.getMilliseconds();return{year:r,month:i,day:n,hour:a,minute:u,second:m,millisecond:l,yyyy:s(r,4),MM:s(i),dd:s(n),HH:s(a),mm:s(u),ss:s(m)}}static normalizeFormatter(t){if(typeof t=="function")return t;if(typeof t!="string")throw new Error("Formatter must be a string or function");t in q&&(t=q[t]);const e={yyyy:"yyyy",MM:"MM",dd:"dd",HH:"HH",mm:"mm",ss:"ss",SSS:"SSS"};return s=>{let r=t;for(const[i,n]of Object.entries(e))r=r.replace(new RegExp(i,"g"),String(s[n]||""));return r}}static formatRelative(t,e=new Date){const s=t.getTime()-e.getTime(),r=Math.abs(s),i=Math.floor(r/1e3),n=Math.floor(i/60),a=Math.floor(n/60),u=Math.floor(a/24);return u>0?s>0?`${u}天后`:`${u}天前`:a>0?s>0?`${a}小时后`:`${a}小时前`:n>0?s>0?`${n}分钟后`:`${n}分钟前`:s>0?"刚刚":""}}class L{lights;currentIndex;switchTime;static DEFAULT_LIGHTS=[{color:"red",latest:7},{color:"yellow",latest:3},{color:"green",latest:10},{color:"yellow",latest:3}];constructor(t=L.DEFAULT_LIGHTS){this.lights=t,this.currentIndex=0,this.switchTime=Date.now()}render(t){requestAnimationFrame(this.render.bind(this,t));const e=this.getCurrentLight();t(e)}get current(){return this.lights[this.currentIndex]}get disTime(){return Date.now()-this.switchTime}update(){for(;!(this.disTime<this.current.latest);)this.switchTime+=this.current.latest*1e3,this.currentIndex=(this.currentIndex+1)%this.lights.length}getCurrentLight(){return this.update(),{color:this.current.color,remain:this.current.latest-this.disTime}}}class tt{static escape(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}}class et{static ROMAN_MAP=new Map([["M",1e3],["CM",900],["D",500],["CD",400],["C",100],["XC",90],["L",50],["XL",40],["X",10],["IX",9],["V",5],["IV",4],["I",1]]);static toInteger(t){if(t.length===0)throw new Error("Input cannot be empty");const e=new Set(["I","V","X","L","C","D","M"]);for(const n of t)if(!e.has(n))throw new Error(`Invalid Roman numeral character: ${n}`);let s=0,r=0;for(;r<t.length;){const n=t.slice(r,r+2);if(this.ROMAN_MAP.has(n))s+=this.ROMAN_MAP.get(n),r+=2;else{const a=t[r],u=this.ROMAN_MAP.get(a);if(!u)throw new Error(`Invalid Roman numeral sequence at position ${r}`);s+=u,r+=1}}if(this.toRoman(s)!==t)throw new Error("Invalid Roman numeral sequence");return s}static toRoman(t){if(t<=0||t>=4e3)throw new Error("Number must be between 1 and 3999");if(!Number.isInteger(t))throw new Error("Number must be an integer");let e="";for(const[s,r]of this.ROMAN_MAP)for(;t>=r;)e+=s,t-=r;return e}}class w{static handleNumRange(t,e=!1,s=Number.MIN_SAFE_INTEGER,r=Number.MAX_SAFE_INTEGER){if(e&&!Number.isInteger(t))throw new Error("n must be an integer");if(t<s||t>=r)throw new RangeError(`n must be in the range of ${s} to ${r}`)}static consecutiveSum(t){return w.handleNumRange(t,!0,0,1e8),t*(t+1)/2}static consecutiveSquaresSum(t){return w.handleNumRange(t,!0,0,1e6),t*(t+1)*(2*t+1)/6}static consecutivecubesSum(t){return w.handleNumRange(t,!0,0,1e4),t*(t+1)*(2*t+1)*(3*t*t+3*t-1)/30}static clamp(t,e,s){return s==null?Math.min(t,e):Math.min(Math.max(t,e),s)}static factorial(t){if(w.handleNumRange(t,!0,0,1e3),t<2)return 1;let e=1;for(let s=2;s<=t;s++)e*=s;return e}static fibonacci(t,e=1,s=1){return w.handleNumRange(t,!0,0,1e3),t<2?s:this.fibonacci(t-1,s,s+e)}static fibonacciIterative(t){if(w.handleNumRange(t,!0,0,1e3),t<2)return t;let e=0,s=1;for(let r=2;r<=t;r++)[e,s]=[s,(e+s)%1000000007];return s}static floatEqual(t,e,s=1e-6){return Math.abs(t-e)<s}static fastPower(t,e){if(w.handleNumRange(e,!0,0,10),w.handleNumRange(t,!1,0,1e3),t===0)return 0;if(e===0)return 1;const s=this.fastPower(t,e>>1);return e%2===0?s*s:s*s*t}static fastSqrt(t){if(w.handleNumRange(t,!1,0,1e8),typeof BigInt>"u")return Math.sqrt(t);const e=.5*t,s=new ArrayBuffer(8);new Float64Array(s)[0]=t;let r=new BigInt64Array(s)[0];r=0x1ff7a3bea91d9b1bn+(r>>1n);const i=new ArrayBuffer(8);new BigInt64Array(i)[0]=r;let n=new Float64Array(i)[0];return n=n*.5+e/n,n=n*.5+e/n,n=n*.5+e/n,n}static getPercentWithPrecision(t,e=2){if(!Array.isArray(t)||t.length===0)return[];if(e<0||!Number.isInteger(e))throw new Error("Precision must be a non-negative integer");const s=t.reduce((h,f)=>h+f,0);if(s===0)return t.map(()=>"0%");const i=100*Math.pow(10,e),n=t.map(h=>h/s*i),a=n.map(h=>Math.floor(h)),u=n.map((h,f)=>h-a[f]);let m=a.reduce((h,f)=>h+f,0),l=i-m;for(;l>0;){let h=-1,f=-1;for(let g=0;g<u.length;g++)u[g]>f&&(f=u[g],h=g);if(h===-1)break;a[h]++,u[h]=0,l--}return a.map(h=>`${(h/i*100).toFixed(e)}%`)}static gcd(t,e){return e===0?t:this.gcd(e,t%e)}static isValidPositiveInteger(t){return Number.isInteger(t)&&t>0&&t<=Number.MAX_SAFE_INTEGER}static isPowerOfTwo(t){return t>0&&(t&t-1)===0}static isOdd(t){return t%2===1||t%2===-1}static isPrime(t){if(t<=1)return!1;for(let e=2;e<=Math.sqrt(t);e++)if(t%e===0)return!1;return!0}static isPalindrome(t){if(t<0||t%10===0&&t!==0)return!1;let e=0,s=t;for(;t>0;){const r=t%10;e=e*10+r,t=Math.floor(t/10)}return s===e}static isArmstrong(t){const e=t.toString(),s=e.length;let r=0;for(let i=0;i<s;i++)r+=Math.pow(parseInt(e[i]),s);return r===t}static isHappy(t){const e=new Set;for(;t!==1;){if(e.has(t))return!1;e.add(t),t=(t+"").split("").reduce((s,r)=>s+Number(r)*Number(r),0)}return!0}static isPerfect(t){let e=0;for(let s=1;s<t;s++)t%s===0&&(e+=s);return e===t}static isSameSign(t,e){return t>=0&&e>=0||t<=0&&e<=0}static isRange(t,e,s){if(s==null&&(s=e,e=0),e>=s)throw new Error("The maximum value must be greater than the minimum value");return e<=t&&t<s}static lcm(t,e){return t*e/this.gcd(t,e)}static middle(t,e){return e-(e-t>>1)}static random(t,e){if(e==null&&(e=t,t=0),t>=e)throw new Error("The maximum value must be greater than the minimum value");return Math.random()*(e-t)+t}static randomInt(t,e){return Math.floor(this.random(t,e))}static round(t,e=0){if(!Number.isInteger(e))throw new Error("precision must be an integer");const s=Math.pow(10,e);return Math.round(t*s)/s}static scale(t,e,s){if(e[0]>=e[1]||s[0]>=s[1])throw new Error("Invalid range");t=this.clamp(t,e[0],e[1]);const r=e[1]-e[0];return(t-e[0])*((s[1]-s[0])/r)+s[0]}static getPythagoreanTriple(t){if(t<=0||!Number.isInteger(t))throw new Error("n must be a positive integer");if(w.isOdd(t)){const s=t*t;return[t,(s-1)/2,(s+1)/2]}const e=t/2;return[t,e*e-1,e*e+1]}}class st{static READ=1;static WRITE=2;static SHARE=4;static DELETE=8;static CREATE=16;static include(t,e){return(t&e)===e}static add(t,e){return t|e}static remove(t,e){return t&~e}static toggle(t,e){return t^e}}class v{static frequencyStatistics(t){return[...t].reduce((e,s)=>(e[s]=(e[s]||0)+1,e),{})}static isValidBracket(t){const e=[],s={"(":")","[":"]","{":"}"},r=new Set(Object.values(s));for(const i of t)if(i in s)e.push(s[i]);else if(r.has(i)&&i!==e.pop())return!1;return e.length===0}static random(t=8){const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let s="";for(let r=0;r<t;r++)s+=e.charAt(Math.floor(Math.random()*e.length));return s}static template(t,e){return t.replace(/\${(\w+)}/g,(s,r)=>e[r]||"")}static escapeHtml(t){const e={"&":"&","<":"<",">":">",'"':""","'":"'"," ":" ","±":"±","×":"×","÷":"÷","≠":"≠","≤":"≤","≥":"≥"},s=new RegExp(`[${Object.keys(e).join("")}]`,"g");return t.replace(s,r=>e[r])}static isEmail(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}static isUrl(t){try{return new URL(t),!0}catch{return!1}}static pointLength(t){let e=0;for(let s=0,r=t.length;s<r;){const i=t.codePointAt(s);s+=i>65535?2:1,e++}return e}static pointAt(t,e){if(e>=v.pointLength(t))return;let s=0;for(let r=0,i=t.length;r<i;){const n=t.codePointAt(r);if(!n)return;if(s===e)return String.fromCodePoint(n);r+=n>65535?2:1,s++}}static sliceByPoint(t,e,s=v.pointLength(t)){let r="";for(let i=e;i<s;i++)r+=v.pointAt(t,i);return r}static capitalize(t){return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}static reverse(t){return t.split("").reverse().join("")}static truncate(t,e,s="..."){return t.length<=e?this:t.slice(0,e-s.length)+s}static isPalindrome(t){return t.toLowerCase().replace(/[^a-z0-9]/g,"")===v.reverse(t)}static count(t,e){const s=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return(t.match(new RegExp(s,"g"))||[]).length}static toCamelCase(t){return t.replace(/_([a-z])/g,(e,s)=>s.toUpperCase())}static toSnakeCase(t){return t.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`)}}class rt{static isValidHex(t){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t)}static isValidRGB(t){return/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.test(t)}}const M={AUTH_UNAUTHORIZED:"未授权事件",AUTH_LOGIN_SUCCESS:"登录成功事件",AUTH_LOGOUT:"注销事件",AUTH_TOKEN_EXPIRED:"令牌过期事件",REQUEST_ERROR:"请求错误事件",REQUEST_TIMEOUT:"请求超时事件",REQUEST_NETWORK_ERROR:"网络错误事件",UI_SHOW_LOADING:"显示加载事件",UI_HIDE_LOADING:"隐藏加载事件",UI_SHOW_MESSAGE:"显示消息事件"};class x{static instance=null;listeners={};debugMode;constructor(t=!1){this.debugMode=t,Object.keys(M).forEach(e=>{this.listeners[e]=new Set})}static getInstance(t){return x.instance||(x.instance=new x(t)),x.instance}on(t,e){this.debugLog(`添加事件监听: ${M[t]}`),this.listeners[t].add(e)}emit(t,e){this.debugLog(`触发事件: ${M[t]}`,e),this.listeners[t].forEach(s=>{try{s(e)}catch(r){console.error(`事件 ${M[t]} 处理出错:`,r)}})}off(t,e){this.debugLog(`移除事件监听: ${M[t]}`),this.listeners[t].delete(e)}once(t,e){this.debugLog(`添加一次性事件监听: ${M[t]}`);const s=r=>{e(r),this.off(t,s)};this.on(t,s)}clear(){this.debugLog("清除所有事件监听器"),Object.values(this.listeners).forEach(t=>t.clear())}getListenerCount(t){return this.listeners[t].size}debugLog(t,e){this.debugMode&&console.log(`[EventEmitter] ${t}`,e||"")}}class b{static OPERATORS=new Set(["+","-","*","/"]);static VALID_CHARS_REG=/^[0-9+\-*/().\s]+$/;static PRIORITY_MAP=new Map([["+",1],["-",1],["*",2],["/",2],["(",0],[")",0]]);static getPriority(t){return this.PRIORITY_MAP.get(t)??0}static validateExpression(t){if(!t)throw new Error("Expression cannot be empty");if(!this.VALID_CHARS_REG.test(t))throw new Error("Expression contains invalid characters")}static processClosingParenthesis(t,e){for(;!t.isEmpty();){if(t.peek()==="("){t.pop();break}const r=t.pop();r&&e.push(r)}}static processOperator(t,e,s){for(;!e.isEmpty();){const r=e.peek();if(!r||r==="(")break;if(this.getPriority(t)<=this.getPriority(r)){const i=e.pop();i&&s.push(i)}else break}e.push(t)}static applyOperator(t,e,s){switch(s){case"+":return t+e;case"-":return t-e;case"*":return t*e;case"/":if(e===0)throw new Error("Division by zero");return t/e;default:throw new Error("Invalid operator")}}static FLOAT_NUM_REG=/^-?\d*\.?\d+$/;static EXPRESSION_REG=new RegExp("(?<!\\d)-?\\d*\\.?\\d+|[+\\-*/()]","g");static toArr(t){this.validateExpression(t);const e=t.match(b.EXPRESSION_REG);if(!e)throw new Error("Invalid expression format");return e.filter(s=>s.trim()!=="").map(s=>{if(this.FLOAT_NUM_REG.test(s)||this.OPERATORS.has(s)||s==="("||s===")")return s;throw new Error(`Invalid token: ${s}`)})}static infixToPostfix(t){if(!t?.trim())throw new Error("Expression cannot be empty");const e=new P,s=this.toArr(t);console.log(s);const r=[];for(const i of s)this.FLOAT_NUM_REG.test(i)?r.push(i):i==="("?e.push(i):i===")"?this.processClosingParenthesis(e,r):this.OPERATORS.has(i)&&this.processOperator(i,e,r);for(;!e.isEmpty();){const i=e.pop();i&&i!=="("&&r.push(i)}return{postfix:r.join(" "),postfixArr:r}}static evaluatePostfix(t){if(!t.length)throw new Error("Postfix expression cannot be empty");typeof t=="string"&&(t=b.toArr(t));const e=new P;for(const s of t)if(this.FLOAT_NUM_REG.test(s))e.push(parseFloat(s));else if(this.OPERATORS.has(s)){const r=e.pop(),i=e.pop();if(i===void 0||r===void 0)throw new Error("Invalid postfix expression");e.push(this.applyOperator(i,r,s))}return e.pop()??0}}class N{static isMatchingPair(t,e){return t==="("&&e===")"||t==="{"&&e==="}"||t==="["&&e==="]"}static arr_2d_init(t,e,s=!1){return typeof s=="boolean"?Array.from({length:t},()=>Array(e).fill(s)):Array.from({length:t},()=>Array(e).fill(s))}static isvalidBrackets(t){const e=new P;for(let s=0,r=t.length;s<r;s++){const i=t[s];if(["{","[","("].includes(i))e.push(i);else if(["}","]",")"].includes(i)){if(e.isEmpty())return!1;const n=e.pop();if(!n||!this.isMatchingPair(n,i))return!1}}return e.isEmpty()}static findPath(t,e,s){const r=t.length,i=t[0].length,n=N.arr_2d_init(r,i,!1),a=new P,u=[[-1,0],[0,1],[1,0],[0,-1]];function m(l,h){if(l<0||l>=r||h<0||h>=i||t[l][h]===1||n[l][h])return!1;if(t[l][h]===2)return a.push([l,h]),!0;n[l][h]=!0,a.push([l,h]);for(const[f,g]of u){const O=l+f,C=h+g;if(m(O,C))return!0}return a.pop(),!1}return m(e,s),a}}o.Arr=Y,o.ArrQueue=R,o.ArrStack=P,o.BitPerm=st,o.Color=rt,o.DateEx=A,o.Dictionary=H,o.Emitter=x,o.Expression=b,o.Func=J,o.Graph=W,o.LRU=j,o.Line=y,o.LinkedList=Q,o.Matrix=S,o.MaxHeap=G,o.MemoizeMap=Z,o.MinHeap=$,o.MinStack=_,o.Num=w,o.Obj=K,o.ObjQueue=F,o.ObjStack=V,o.Point=p,o.Reg=tt,o.Roman=et,o.StackApplication=N,o.Str=v,o.TrafficLight=L,o.Triangle=d,o.Vector=E,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
|
package/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ declare module "jc-structure" {
|
|
|
12
12
|
peek(): T | undefined;
|
|
13
13
|
isEmpty(): boolean;
|
|
14
14
|
size(): number;
|
|
15
|
-
|
|
15
|
+
cleanup(): void;
|
|
16
16
|
toString(): string;
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -23,7 +23,7 @@ declare module "jc-structure" {
|
|
|
23
23
|
peek(): T | undefined;
|
|
24
24
|
isEmpty(): boolean;
|
|
25
25
|
size(): number;
|
|
26
|
-
|
|
26
|
+
cleanup(): void;
|
|
27
27
|
toString(): string;
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -37,7 +37,7 @@ declare module "jc-structure" {
|
|
|
37
37
|
front(): T | undefined;
|
|
38
38
|
isEmpty(): boolean;
|
|
39
39
|
size(): number;
|
|
40
|
-
|
|
40
|
+
cleanup(): void;
|
|
41
41
|
toString(): string;
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -62,7 +62,7 @@ declare module "jc-structure" {
|
|
|
62
62
|
removeAt(index: number): T | null;
|
|
63
63
|
isEmpty(): boolean;
|
|
64
64
|
size(): number;
|
|
65
|
-
|
|
65
|
+
cleanup(): void;
|
|
66
66
|
toString(): string;
|
|
67
67
|
toArray(): T[];
|
|
68
68
|
[Symbol.iterator](): Iterator<T>;
|
|
@@ -76,7 +76,7 @@ declare module "jc-structure" {
|
|
|
76
76
|
find(): T | undefined;
|
|
77
77
|
isEmpty(): boolean;
|
|
78
78
|
size(): number;
|
|
79
|
-
|
|
79
|
+
cleanup(): void;
|
|
80
80
|
toString(): string;
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -107,7 +107,7 @@ declare module "jc-structure" {
|
|
|
107
107
|
forEach(callbackFunc: (key: K, value: V) => boolean | void): void;
|
|
108
108
|
isEmpty(): boolean;
|
|
109
109
|
size(): number;
|
|
110
|
-
|
|
110
|
+
cleanup(): void;
|
|
111
111
|
toString(): string;
|
|
112
112
|
}
|
|
113
113
|
|
|
@@ -566,6 +566,13 @@ declare module "jc-structure" {
|
|
|
566
566
|
* @param n
|
|
567
567
|
*/
|
|
568
568
|
consecutivecubesSum(n: number): number;
|
|
569
|
+
/**
|
|
570
|
+
* #### 获取勾股数,也叫毕达哥拉斯三元组
|
|
571
|
+
* - 勾股数是指满足勾股定理的三个正整数a、b、c,即a² + b² = c²
|
|
572
|
+
* - 偶数半方加减一,奇数平方写连续;
|
|
573
|
+
* @param n 正整数
|
|
574
|
+
*/
|
|
575
|
+
getPythagoreanTriple(n: number): [number, number, number];
|
|
569
576
|
}
|
|
570
577
|
var Num: NumConstructor;
|
|
571
578
|
|
package/package.json
CHANGED
package/types/global.d.ts
CHANGED