jc-structure 0.2.10 → 0.2.12
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 +104 -71
- package/dist/jc-structure.umd.cjs +2 -2
- package/index.d.ts +2 -1
- package/package.json +1 -1
package/dist/jc-structure.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class H {
|
|
2
2
|
items = {};
|
|
3
3
|
count = 0;
|
|
4
4
|
lowestCount = 0;
|
|
@@ -129,13 +129,13 @@ class V {
|
|
|
129
129
|
return this.isEmpty() ? "" : `MinStack(count: ${this.size()}):[${this.getMin()},...rest]`;
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
function
|
|
132
|
+
function P(h, t) {
|
|
133
133
|
return h === t ? 0 : h < t ? -1 : 1;
|
|
134
134
|
}
|
|
135
135
|
class x {
|
|
136
136
|
heap = [];
|
|
137
137
|
compareFn;
|
|
138
|
-
constructor(t =
|
|
138
|
+
constructor(t = P) {
|
|
139
139
|
this.compareFn = t;
|
|
140
140
|
}
|
|
141
141
|
static getLeftIndex(t) {
|
|
@@ -166,7 +166,7 @@ class x {
|
|
|
166
166
|
return this.heap.toString();
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
|
-
class
|
|
169
|
+
class T extends x {
|
|
170
170
|
insert(t) {
|
|
171
171
|
return t ? !1 : (this.heap.push(t), this.siftUp(this.heap.length - 1), !0);
|
|
172
172
|
}
|
|
@@ -186,12 +186,12 @@ class $ extends x {
|
|
|
186
186
|
x.swap(this.heap, e, t), t = e, e = x.getParentIndex(t);
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
class F extends
|
|
190
|
-
constructor(t = (e, s) =>
|
|
189
|
+
class F extends T {
|
|
190
|
+
constructor(t = (e, s) => P(s, e)) {
|
|
191
191
|
super(t);
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
-
function
|
|
194
|
+
function $(h) {
|
|
195
195
|
return { value: h };
|
|
196
196
|
}
|
|
197
197
|
class B {
|
|
@@ -224,12 +224,12 @@ class B {
|
|
|
224
224
|
}
|
|
225
225
|
update(t, e) {
|
|
226
226
|
let s = this.lookup.get(t);
|
|
227
|
-
s ? (this.detach(s), this.prepend(s), s.value = e) : (s =
|
|
227
|
+
s ? (this.detach(s), this.prepend(s), s.value = e) : (s = $(e), this.length++, this.prepend(s), this.trimCache(), this.lookup.set(t, s), this.reverseLookup);
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
class b {
|
|
231
|
-
constructor(t, e = null) {
|
|
232
|
-
this.value = t, this.next = e;
|
|
231
|
+
constructor(t, e = null, s = null) {
|
|
232
|
+
this.value = t, this.next = e, this.prev = s;
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
235
|
class G {
|
|
@@ -277,7 +277,7 @@ class G {
|
|
|
277
277
|
if (t > this.count / 2) {
|
|
278
278
|
let s = this.tail, r = this.count - 1;
|
|
279
279
|
for (; r > t && s; )
|
|
280
|
-
s = s.
|
|
280
|
+
s = s.prev, r--;
|
|
281
281
|
return s;
|
|
282
282
|
}
|
|
283
283
|
let e = this.head;
|
|
@@ -293,32 +293,65 @@ class G {
|
|
|
293
293
|
throw new Error(`Index out of bounds: ${e}`);
|
|
294
294
|
const s = new b(t);
|
|
295
295
|
if (e === 0)
|
|
296
|
-
s.next = this.head, this.head = s, this.count === 0 && (this.tail = s);
|
|
296
|
+
s.next = this.head, this.head && (this.head.prev = s), this.head = s, this.count === 0 && (this.tail = s);
|
|
297
297
|
else if (e === this.count)
|
|
298
|
-
this.tail && (this.tail.next = s, this.tail = s
|
|
298
|
+
s.prev = this.tail, this.tail && (this.tail.next = s), this.tail = s;
|
|
299
299
|
else {
|
|
300
|
-
|
|
301
|
-
|
|
300
|
+
let r;
|
|
301
|
+
if (e < this.count / 2) {
|
|
302
|
+
r = this.head;
|
|
303
|
+
for (let i = 0; i < e - 1 && r; i++)
|
|
304
|
+
r = r.next;
|
|
305
|
+
} else {
|
|
306
|
+
r = this.tail;
|
|
307
|
+
for (let i = this.count - 1; i > e - 1 && r; i--)
|
|
308
|
+
r = r.prev;
|
|
309
|
+
}
|
|
310
|
+
if (r) {
|
|
311
|
+
const i = r.next;
|
|
312
|
+
s.prev = r, s.next = i, r.next = s, i && (i.prev = s);
|
|
313
|
+
}
|
|
302
314
|
}
|
|
303
315
|
return this.count++, !0;
|
|
304
316
|
}
|
|
305
317
|
push(t) {
|
|
306
318
|
const e = new b(t);
|
|
307
|
-
this.head ? this.tail && (this.tail.next = e, this.tail = e) : (this.head = e, this.tail = e), this.count++;
|
|
319
|
+
this.head ? this.tail && (this.tail.next = e, e.prev = this.tail, this.tail = e) : (this.head = e, this.tail = e), this.count++;
|
|
308
320
|
}
|
|
309
321
|
remove(t) {
|
|
310
|
-
|
|
311
|
-
|
|
322
|
+
let e = this.head, s = this.tail, r = 0, i = this.count - 1;
|
|
323
|
+
for (; e && s; ) {
|
|
324
|
+
if (this.equals(e.value, t))
|
|
325
|
+
return this.removeAt(r);
|
|
326
|
+
if (this.equals(s.value, t))
|
|
327
|
+
return this.removeAt(i);
|
|
328
|
+
if (e = e.next, s = s.prev, r++, i--, r > i)
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
return null;
|
|
312
332
|
}
|
|
313
333
|
removeAt(t) {
|
|
314
334
|
if (t < 0 || t >= this.count)
|
|
315
335
|
return null;
|
|
316
|
-
let e
|
|
336
|
+
let e;
|
|
317
337
|
if (t === 0)
|
|
318
|
-
this.head = e
|
|
338
|
+
e = this.head, e && (this.head = e.next, this.head && (this.head.prev = null), this.count === 1 && (this.tail = null));
|
|
339
|
+
else if (t === this.count - 1)
|
|
340
|
+
e = this.tail, e && (this.tail = e.prev, this.tail && (this.tail.next = null), this.count === 1 && (this.head = null));
|
|
319
341
|
else {
|
|
320
|
-
|
|
321
|
-
|
|
342
|
+
if (t < this.count / 2) {
|
|
343
|
+
e = this.head;
|
|
344
|
+
for (let s = 0; s < t && e; s++)
|
|
345
|
+
e = e.next;
|
|
346
|
+
} else {
|
|
347
|
+
e = this.tail;
|
|
348
|
+
for (let s = this.count - 1; s > t && e; s--)
|
|
349
|
+
e = e.prev;
|
|
350
|
+
}
|
|
351
|
+
if (e) {
|
|
352
|
+
const s = e.prev, r = e.next;
|
|
353
|
+
s && (s.next = r), r && (r.prev = s);
|
|
354
|
+
}
|
|
322
355
|
}
|
|
323
356
|
return this.count--, e?.value || null;
|
|
324
357
|
}
|
|
@@ -347,7 +380,7 @@ class G {
|
|
|
347
380
|
return t;
|
|
348
381
|
}
|
|
349
382
|
}
|
|
350
|
-
class
|
|
383
|
+
class q {
|
|
351
384
|
key;
|
|
352
385
|
value;
|
|
353
386
|
constructor(t, e) {
|
|
@@ -357,7 +390,7 @@ class T {
|
|
|
357
390
|
function R(h, t = { emptyString: !1, zeroNumber: !1 }) {
|
|
358
391
|
return h == null ? !(t.emptyString && h === "" || t.zeroNumber && h === 0) : !1;
|
|
359
392
|
}
|
|
360
|
-
class
|
|
393
|
+
class D {
|
|
361
394
|
table = [];
|
|
362
395
|
constructor() {
|
|
363
396
|
}
|
|
@@ -376,7 +409,7 @@ class H {
|
|
|
376
409
|
let s = this.getItemIndex(t);
|
|
377
410
|
this.table[s].value = e;
|
|
378
411
|
} else {
|
|
379
|
-
const s = new
|
|
412
|
+
const s = new q(t, e);
|
|
380
413
|
this.table.push(s);
|
|
381
414
|
}
|
|
382
415
|
}
|
|
@@ -432,7 +465,7 @@ class W {
|
|
|
432
465
|
vertices;
|
|
433
466
|
adjList;
|
|
434
467
|
constructor(t = !1) {
|
|
435
|
-
this.isDirected = t, this.vertices = [], this.adjList = new
|
|
468
|
+
this.isDirected = t, this.vertices = [], this.adjList = new D();
|
|
436
469
|
}
|
|
437
470
|
addVertex(t) {
|
|
438
471
|
this.vertices.includes(t) || (this.vertices.push(t), this.adjList.set(t, []));
|
|
@@ -512,10 +545,10 @@ class w {
|
|
|
512
545
|
return this.mul(-1);
|
|
513
546
|
}
|
|
514
547
|
}
|
|
515
|
-
class
|
|
548
|
+
class E {
|
|
516
549
|
_matrix;
|
|
517
550
|
static zero(t, e) {
|
|
518
|
-
return new
|
|
551
|
+
return new E(
|
|
519
552
|
Array.from({ length: t }, () => Array.from({ length: e }, () => 0))
|
|
520
553
|
);
|
|
521
554
|
}
|
|
@@ -556,7 +589,7 @@ class I {
|
|
|
556
589
|
return this._matrix[t[0]][t[1]] = e, this;
|
|
557
590
|
}
|
|
558
591
|
mul(t) {
|
|
559
|
-
return new
|
|
592
|
+
return new E(this._matrix.map((e) => e.map((s) => s * t)));
|
|
560
593
|
}
|
|
561
594
|
div(t) {
|
|
562
595
|
return this.mul(1 / t);
|
|
@@ -564,7 +597,7 @@ class I {
|
|
|
564
597
|
add(t) {
|
|
565
598
|
if (this.row !== t.row || this.col !== t.col)
|
|
566
599
|
throw new Error("Matrix dimensions do not match");
|
|
567
|
-
return new
|
|
600
|
+
return new E(
|
|
568
601
|
this._matrix.map(
|
|
569
602
|
(e, s) => e.map((r, i) => r + t.getItem([s, i]))
|
|
570
603
|
)
|
|
@@ -582,14 +615,14 @@ class I {
|
|
|
582
615
|
mulVector(t) {
|
|
583
616
|
if (this.col !== t.dimension)
|
|
584
617
|
throw new Error("Matrix dimensions do not match");
|
|
585
|
-
return new
|
|
618
|
+
return new E(
|
|
586
619
|
this._matrix.map((e) => e.map((s, r) => s * t.getItem(r)))
|
|
587
620
|
);
|
|
588
621
|
}
|
|
589
622
|
mulMatrix(t) {
|
|
590
623
|
if (this.col !== t.row)
|
|
591
624
|
throw new Error("Matrix dimensions do not match");
|
|
592
|
-
const e =
|
|
625
|
+
const e = E.zero(this.row, t.col);
|
|
593
626
|
for (let s = 0; s < this.row; s++) {
|
|
594
627
|
const r = this.rowVector(s);
|
|
595
628
|
for (let i = 0; i < this.col; i++)
|
|
@@ -623,10 +656,10 @@ class g {
|
|
|
623
656
|
}
|
|
624
657
|
static getIntersection(t, e, s = g.EPSILON) {
|
|
625
658
|
if (g.isParallel(t, e)) return null;
|
|
626
|
-
const r = t.p1.x, i = t.p1.y, n = t.p2.x, a = t.p2.y, o = e.p1.x,
|
|
659
|
+
const r = t.p1.x, i = t.p1.y, n = t.p2.x, a = t.p2.y, o = e.p1.x, f = e.p1.y, d = e.p2.x, c = e.p2.y, l = (r - n) * (f - c) - (i - a) * (o - d);
|
|
627
660
|
if (Math.abs(l) < s) return null;
|
|
628
|
-
const m = ((r - o) * (
|
|
629
|
-
if (m >= 0 && m <= 1 &&
|
|
661
|
+
const m = ((r - o) * (f - c) - (i - f) * (o - d)) / l, A = -((r - n) * (i - f) - (i - a) * (r - o)) / l;
|
|
662
|
+
if (m >= 0 && m <= 1 && A >= 0 && A <= 1) {
|
|
630
663
|
const C = r + m * (n - r), z = i + m * (a - i);
|
|
631
664
|
return new u(C, z);
|
|
632
665
|
}
|
|
@@ -636,13 +669,13 @@ class g {
|
|
|
636
669
|
return g.getIntersection(t, e) !== null;
|
|
637
670
|
}
|
|
638
671
|
static distanceToPoint(t, e, s = g.EPSILON) {
|
|
639
|
-
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, o = r * n + i * a,
|
|
640
|
-
let
|
|
641
|
-
|
|
672
|
+
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, o = r * n + i * a, f = n * n + a * a;
|
|
673
|
+
let d = -1;
|
|
674
|
+
f > s && (d = o / f);
|
|
642
675
|
let c, l;
|
|
643
|
-
|
|
644
|
-
const m = e.x - c,
|
|
645
|
-
return Math.hypot(m +
|
|
676
|
+
d < 0 ? (c = t.p1.x, l = t.p1.y) : d > 1 ? (c = t.p2.x, l = t.p2.y) : (c = t.p1.x + d * n, l = t.p1.y + d * a);
|
|
677
|
+
const m = e.x - c, A = e.y - l;
|
|
678
|
+
return Math.hypot(m + A);
|
|
646
679
|
}
|
|
647
680
|
p1;
|
|
648
681
|
p2;
|
|
@@ -697,7 +730,7 @@ class p extends k {
|
|
|
697
730
|
static getType(t, e, s) {
|
|
698
731
|
if (!p.isValid(t, e, s))
|
|
699
732
|
throw new Error("Invalid triangle sides");
|
|
700
|
-
const r = [t, e, s].sort((o,
|
|
733
|
+
const r = [t, e, s].sort((o, f) => o - f), [i, n, a] = r;
|
|
701
734
|
return Math.abs(i - n) < p.EPSILON && Math.abs(n - a) < p.EPSILON ? "equilateral" : Math.abs(i - n) < p.EPSILON || Math.abs(n - a) < p.EPSILON ? "isosceles" : "scalene";
|
|
702
735
|
}
|
|
703
736
|
static getAngles(t, e, s) {
|
|
@@ -931,7 +964,7 @@ class J {
|
|
|
931
964
|
return r;
|
|
932
965
|
}
|
|
933
966
|
}
|
|
934
|
-
const
|
|
967
|
+
const N = {
|
|
935
968
|
date: "yyyy-MM-dd",
|
|
936
969
|
datetime: "yyyy-MM-dd HH:mm:ss",
|
|
937
970
|
time: "HH:mm:ss",
|
|
@@ -951,21 +984,21 @@ class M {
|
|
|
951
984
|
}
|
|
952
985
|
// 获取日期信息
|
|
953
986
|
static getDateInfo(t, e) {
|
|
954
|
-
const s = (c, l = 2) => e.paddingZero ? c.toString().padStart(l, "0") : c.toString(), r = t.getFullYear(), i = t.getMonth() + 1, n = t.getDate(), a = t.getHours(), o = t.getMinutes(),
|
|
987
|
+
const s = (c, l = 2) => e.paddingZero ? c.toString().padStart(l, "0") : c.toString(), r = t.getFullYear(), i = t.getMonth() + 1, n = t.getDate(), a = t.getHours(), o = t.getMinutes(), f = t.getSeconds(), d = t.getMilliseconds();
|
|
955
988
|
return {
|
|
956
989
|
year: r,
|
|
957
990
|
month: i,
|
|
958
991
|
day: n,
|
|
959
992
|
hour: a,
|
|
960
993
|
minute: o,
|
|
961
|
-
second:
|
|
962
|
-
millisecond:
|
|
994
|
+
second: f,
|
|
995
|
+
millisecond: d,
|
|
963
996
|
yyyy: s(r, 4),
|
|
964
997
|
MM: s(i),
|
|
965
998
|
dd: s(n),
|
|
966
999
|
HH: s(a),
|
|
967
1000
|
mm: s(o),
|
|
968
|
-
ss: s(
|
|
1001
|
+
ss: s(f)
|
|
969
1002
|
};
|
|
970
1003
|
}
|
|
971
1004
|
static normalizeFormatter(t) {
|
|
@@ -973,7 +1006,7 @@ class M {
|
|
|
973
1006
|
return t;
|
|
974
1007
|
if (typeof t != "string")
|
|
975
1008
|
throw new Error("Formatter must be a string or function");
|
|
976
|
-
t in
|
|
1009
|
+
t in N && (t = N[t]);
|
|
977
1010
|
const e = {
|
|
978
1011
|
yyyy: "yyyy",
|
|
979
1012
|
MM: "MM",
|
|
@@ -1156,13 +1189,13 @@ class y {
|
|
|
1156
1189
|
if (s === 0)
|
|
1157
1190
|
return t.map(() => "0%");
|
|
1158
1191
|
const i = 100 * Math.pow(10, e), n = t.map((c) => c / s * i), a = n.map((c) => Math.floor(c)), o = n.map((c, l) => c - a[l]);
|
|
1159
|
-
let
|
|
1160
|
-
for (;
|
|
1192
|
+
let f = a.reduce((c, l) => c + l, 0), d = i - f;
|
|
1193
|
+
for (; d > 0; ) {
|
|
1161
1194
|
let c = -1, l = -1;
|
|
1162
1195
|
for (let m = 0; m < o.length; m++)
|
|
1163
1196
|
o[m] > l && (l = o[m], c = m);
|
|
1164
1197
|
if (c === -1) break;
|
|
1165
|
-
a[c]++, o[c] = 0,
|
|
1198
|
+
a[c]++, o[c] = 0, d--;
|
|
1166
1199
|
}
|
|
1167
1200
|
return a.map((c) => `${(c / i * 100).toFixed(e)}%`);
|
|
1168
1201
|
}
|
|
@@ -1276,7 +1309,7 @@ class K {
|
|
|
1276
1309
|
return t ^ e;
|
|
1277
1310
|
}
|
|
1278
1311
|
}
|
|
1279
|
-
class
|
|
1312
|
+
class v {
|
|
1280
1313
|
static frequencyStatistics(t) {
|
|
1281
1314
|
return [...t].reduce(
|
|
1282
1315
|
(e, s) => (e[s] = (e[s] || 0) + 1, e),
|
|
@@ -1345,7 +1378,7 @@ class S {
|
|
|
1345
1378
|
return e;
|
|
1346
1379
|
}
|
|
1347
1380
|
static pointAt(t, e) {
|
|
1348
|
-
if (e >=
|
|
1381
|
+
if (e >= v.pointLength(t)) return;
|
|
1349
1382
|
let s = 0;
|
|
1350
1383
|
for (let r = 0, i = t.length; r < i; ) {
|
|
1351
1384
|
const n = t.codePointAt(r);
|
|
@@ -1355,10 +1388,10 @@ class S {
|
|
|
1355
1388
|
r += n > 65535 ? 2 : 1, s++;
|
|
1356
1389
|
}
|
|
1357
1390
|
}
|
|
1358
|
-
static sliceByPoint(t, e, s =
|
|
1391
|
+
static sliceByPoint(t, e, s = v.pointLength(t)) {
|
|
1359
1392
|
let r = "";
|
|
1360
1393
|
for (let i = e; i < s; i++)
|
|
1361
|
-
r +=
|
|
1394
|
+
r += v.pointAt(t, i);
|
|
1362
1395
|
return r;
|
|
1363
1396
|
}
|
|
1364
1397
|
static capitalize(t) {
|
|
@@ -1371,7 +1404,7 @@ class S {
|
|
|
1371
1404
|
return t.length <= e ? this : t.slice(0, e - s.length) + s;
|
|
1372
1405
|
}
|
|
1373
1406
|
static isPalindrome(t) {
|
|
1374
|
-
return t.toLowerCase().replace(/[^a-z0-9]/g, "") ===
|
|
1407
|
+
return t.toLowerCase().replace(/[^a-z0-9]/g, "") === v.reverse(t);
|
|
1375
1408
|
}
|
|
1376
1409
|
static count(t, e) {
|
|
1377
1410
|
const s = e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -1392,7 +1425,7 @@ class _ {
|
|
|
1392
1425
|
return /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.test(t);
|
|
1393
1426
|
}
|
|
1394
1427
|
}
|
|
1395
|
-
const
|
|
1428
|
+
const I = {
|
|
1396
1429
|
AUTH_UNAUTHORIZED: "未授权事件",
|
|
1397
1430
|
AUTH_LOGIN_SUCCESS: "登录成功事件",
|
|
1398
1431
|
AUTH_LOGOUT: "注销事件",
|
|
@@ -1404,37 +1437,37 @@ const E = {
|
|
|
1404
1437
|
UI_HIDE_LOADING: "隐藏加载事件",
|
|
1405
1438
|
UI_SHOW_MESSAGE: "显示消息事件"
|
|
1406
1439
|
};
|
|
1407
|
-
class
|
|
1440
|
+
class S {
|
|
1408
1441
|
static instance = null;
|
|
1409
1442
|
listeners = {};
|
|
1410
1443
|
debugMode;
|
|
1411
1444
|
constructor(t = !1) {
|
|
1412
|
-
this.debugMode = t, Object.keys(
|
|
1445
|
+
this.debugMode = t, Object.keys(I).forEach(
|
|
1413
1446
|
(e) => {
|
|
1414
1447
|
this.listeners[e] = /* @__PURE__ */ new Set();
|
|
1415
1448
|
}
|
|
1416
1449
|
);
|
|
1417
1450
|
}
|
|
1418
1451
|
static getInstance(t) {
|
|
1419
|
-
return
|
|
1452
|
+
return S.instance || (S.instance = new S(t)), S.instance;
|
|
1420
1453
|
}
|
|
1421
1454
|
on(t, e) {
|
|
1422
|
-
this.debugLog(`添加事件监听: ${
|
|
1455
|
+
this.debugLog(`添加事件监听: ${I[t]}`), this.listeners[t].add(e);
|
|
1423
1456
|
}
|
|
1424
1457
|
emit(t, e) {
|
|
1425
|
-
this.debugLog(`触发事件: ${
|
|
1458
|
+
this.debugLog(`触发事件: ${I[t]}`, e), this.listeners[t].forEach((s) => {
|
|
1426
1459
|
try {
|
|
1427
1460
|
s(e);
|
|
1428
1461
|
} catch (r) {
|
|
1429
|
-
console.error(`事件 ${
|
|
1462
|
+
console.error(`事件 ${I[t]} 处理出错:`, r);
|
|
1430
1463
|
}
|
|
1431
1464
|
});
|
|
1432
1465
|
}
|
|
1433
1466
|
off(t, e) {
|
|
1434
|
-
this.debugLog(`移除事件监听: ${
|
|
1467
|
+
this.debugLog(`移除事件监听: ${I[t]}`), this.listeners[t].delete(e);
|
|
1435
1468
|
}
|
|
1436
1469
|
once(t, e) {
|
|
1437
|
-
this.debugLog(`添加一次性事件监听: ${
|
|
1470
|
+
this.debugLog(`添加一次性事件监听: ${I[t]}`);
|
|
1438
1471
|
const s = (r) => {
|
|
1439
1472
|
e(r), this.off(t, s);
|
|
1440
1473
|
};
|
|
@@ -1455,26 +1488,26 @@ export {
|
|
|
1455
1488
|
K as BitPerm,
|
|
1456
1489
|
_ as Color,
|
|
1457
1490
|
M as DateEx,
|
|
1458
|
-
|
|
1459
|
-
|
|
1491
|
+
D as Dictionary,
|
|
1492
|
+
S as Emitter,
|
|
1460
1493
|
X as Func,
|
|
1461
1494
|
W as Graph,
|
|
1462
1495
|
B as LRU,
|
|
1463
1496
|
g as Line,
|
|
1464
1497
|
G as LinkedList,
|
|
1465
|
-
|
|
1498
|
+
E as Matrix,
|
|
1466
1499
|
F as MaxHeap,
|
|
1467
1500
|
Q as MemoizeMap,
|
|
1468
|
-
|
|
1501
|
+
T as MinHeap,
|
|
1469
1502
|
V as MinStack,
|
|
1470
1503
|
y as Num,
|
|
1471
1504
|
J as Obj,
|
|
1472
1505
|
u as Point,
|
|
1473
|
-
|
|
1506
|
+
H as Queue,
|
|
1474
1507
|
Z as Reg,
|
|
1475
1508
|
Y as Roman,
|
|
1476
1509
|
U as Stack,
|
|
1477
|
-
|
|
1510
|
+
v as Str,
|
|
1478
1511
|
L as TrafficLight,
|
|
1479
1512
|
p as Triangle,
|
|
1480
1513
|
w as Vector
|
|
@@ -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 H{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 ${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]`}}function P(h,t){return h===t?0:h<t?-1:1}class
|
|
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 x{_matrix;static zero(t,e){return new x(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 x(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 x(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 x(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=x.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,f=e.p1.y,m=e.p2.x,u=e.p2.y,p=(r-n)*(f-u)-(i-a)*(c-m);if(Math.abs(p)<s)return null;const y=((r-c)*(f-u)-(i-f)*(c-m))/p,b=-((r-n)*(i-f)-(i-a)*(r-c))/p;if(y>=0&&y<=1&&b>=0&&b<=1){const _=r+y*(n-r),tt=i+y*(a-i);return new l(_,tt)}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,f=n*n+a*a;let m=-1;f>s&&(m=c/f);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 z{static EPSILON=1e-10;name;constructor(t){this.name=t}}class d extends z{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((c,f)=>c-f),[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))<z.EPSILON}get side(){return[l.distance(this.p1,this.p2),l.distance(this.p2,this.p3),l.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 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)<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 l(e,s)}containsPoint(t){const e=d.area(l.distance(t,this.p1),l.distance(t,this.p2),l.distance(this.p1,this.p2)),s=d.area(l.distance(t,this.p2),l.distance(t,this.p3),l.distance(this.p2,this.p3)),r=d.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())<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 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 R(h){return h!==null&&(typeof h=="object"||typeof h=="function")}class X{map=new Map;weakMap=new WeakMap;set(t,e){R(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return R(t)?this.weakMap.get(t):this.map.get(t)}has(t){return R(t)?this.weakMap.has(t):this.map.has(t)}}class Q{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 D={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(),f=t.getSeconds(),m=t.getMilliseconds();return{year:r,month:i,day:n,hour:a,minute:c,second:f,millisecond:m,yyyy:s(r,4),MM:s(i),dd:s(n),HH:s(a),mm:s(c),ss:s(f)}}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 D&&(t=D[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 k{lights;currentIndex;switchTime;static DEFAULT_LIGHTS=[{color:"red",latest:7},{color:"yellow",latest:3},{color:"green",latest:10},{color:"yellow",latest:3}];constructor(t=k.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 J{static escape(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}}class Z{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 f=a.reduce((u,p)=>u+p,0),m=i-f;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 Y{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 S{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>=S.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=S.pointLength(t)){let r="";for(let i=e;i<s;i++)r+=S.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,"")===S.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 K{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 A={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 v{static instance=null;listeners={};debugMode;constructor(t=!1){this.debugMode=t,Object.keys(A).forEach(e=>{this.listeners[e]=new Set})}static getInstance(t){return v.instance||(v.instance=new v(t)),v.instance}on(t,e){this.debugLog(`添加事件监听: ${A[t]}`),this.listeners[t].add(e)}emit(t,e){this.debugLog(`触发事件: ${A[t]}`,e),this.listeners[t].forEach(s=>{try{s(e)}catch(r){console.error(`事件 ${A[t]} 处理出错:`,r)}})}off(t,e){this.debugLog(`移除事件监听: ${A[t]}`),this.listeners[t].delete(e)}once(t,e){this.debugLog(`添加一次性事件监听: ${A[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||"")}}o.Arr=W,o.BitPerm=Y,o.Color=K,o.DateEx=M,o.Dictionary=T,o.Emitter=v,o.Func=j,o.Graph=G,o.LRU=q,o.Line=g,o.LinkedList=F,o.Matrix=x,o.MaxHeap=U,o.MemoizeMap=X,o.MinHeap=L,o.MinStack=$,o.Num=w,o.Obj=Q,o.Point=l,o.Queue=O,o.Reg=J,o.Roman=Z,o.Stack=H,o.Str=S,o.TrafficLight=k,o.Triangle=d,o.Vector=E,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
|
|
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 H{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 ${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]`}}function P(h,t){return h===t?0:h<t?-1:1}class E{heap=[];compareFn;constructor(t=P){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 L extends E{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=E.getLeftIndex(e),r=E.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&&(E.swap(this.heap,t,e),this.siftUp(e))}siftDown(t){let e=E.getParentIndex(t);for(;t>0&&e&&this.compareFn(this.heap[e],this.heap[t])===1;)E.swap(this.heap,e,t),t=e,e=E.getParentIndex(t)}}class q extends L{constructor(t=(e,s)=>P(s,e)){super(t)}}function U(h){return{value:h}}class V{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=U(e),this.length++,this.prepend(s),this.trimCache(),this.lookup.set(t,s),this.reverseLookup)}}class N{constructor(t,e=null,s=null){this.value=t,this.next=e,this.prev=s}}class F{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 N(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 N(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 C(h,t={emptyString:!1,zeroNumber:!1}){return h==null?!(t.emptyString&&h===""||t.zeroNumber&&h===0):!1}class T{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(C(t))throw new Error("key is required");if(C(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 G{isDirected;vertices;adjList;constructor(t=!1){this.isDirected=t,this.vertices=[],this.adjList=new T}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 I{_data;static zero(t){return new I(...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 I(...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 I(...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 I(...e)}mul(t){return new I(...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 x{_matrix;static zero(t,e){return new x(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 I(...this._matrix[t])}colVector(t){return new I(...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 x(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 x(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 x(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=x.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 _=r+y*(n-r),tt=i+y*(a-i);return new l(_,tt)}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 z{static EPSILON=1e-10;name;constructor(t){this.name=t}}class f extends z{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))<z.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 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 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 R(h){return h!==null&&(typeof h=="object"||typeof h=="function")}class X{map=new Map;weakMap=new WeakMap;set(t,e){R(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return R(t)?this.weakMap.get(t):this.map.get(t)}has(t){return R(t)?this.weakMap.has(t):this.map.has(t)}}class Q{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 D={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 D&&(t=D[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 k{lights;currentIndex;switchTime;static DEFAULT_LIGHTS=[{color:"red",latest:7},{color:"yellow",latest:3},{color:"green",latest:10},{color:"yellow",latest:3}];constructor(t=k.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 J{static escape(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}}class Z{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 Y{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 S{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>=S.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=S.pointLength(t)){let r="";for(let i=e;i<s;i++)r+=S.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,"")===S.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 K{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||"")}}o.Arr=W,o.BitPerm=Y,o.Color=K,o.DateEx=M,o.Dictionary=T,o.Emitter=A,o.Func=j,o.Graph=G,o.LRU=V,o.Line=g,o.LinkedList=F,o.Matrix=x,o.MaxHeap=q,o.MemoizeMap=X,o.MinHeap=L,o.MinStack=$,o.Num=w,o.Obj=Q,o.Point=l,o.Queue=O,o.Reg=J,o.Roman=Z,o.Stack=H,o.Str=S,o.TrafficLight=k,o.Triangle=f,o.Vector=I,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
|
package/index.d.ts
CHANGED
|
@@ -33,7 +33,8 @@ declare module "jc-structure" {
|
|
|
33
33
|
export class JcNode<T> {
|
|
34
34
|
value: T;
|
|
35
35
|
next: JcNode<T> | null;
|
|
36
|
-
|
|
36
|
+
prev: JcNode<T> | null;
|
|
37
|
+
constructor(value: T, next?: JcNode<T> | null, prev?: JcNode<T> | null);
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
/**
|