jc-structure 0.1.17 → 0.1.18
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 +96 -42
- package/dist/jc-structure.umd.cjs +2 -2
- package/index.d.ts +59 -1
- package/package.json +1 -1
package/dist/jc-structure.js
CHANGED
|
@@ -132,7 +132,7 @@ class D {
|
|
|
132
132
|
function P(r, t) {
|
|
133
133
|
return r === t ? 0 : r < t ? -1 : 1;
|
|
134
134
|
}
|
|
135
|
-
class
|
|
135
|
+
class y {
|
|
136
136
|
heap = [];
|
|
137
137
|
compareFn;
|
|
138
138
|
constructor(t = P) {
|
|
@@ -166,7 +166,7 @@ class w {
|
|
|
166
166
|
return this.heap.toString();
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
|
-
class O extends
|
|
169
|
+
class O extends y {
|
|
170
170
|
insert(t) {
|
|
171
171
|
return t ? !1 : (this.heap.push(t), this.siftUp(this.heap.length - 1), !0);
|
|
172
172
|
}
|
|
@@ -177,13 +177,13 @@ class O extends w {
|
|
|
177
177
|
return this.heap[0] = this.heap.pop(), this.siftDown(0), t;
|
|
178
178
|
}
|
|
179
179
|
siftUp(t) {
|
|
180
|
-
let e = t, s =
|
|
181
|
-
s < n && this.compareFn(this.heap[e], this.heap[s]) === -1 && (e = s), i < n && this.compareFn(this.heap[e], this.heap[i]) === 1 && (e = i), e !== t && (
|
|
180
|
+
let e = t, s = y.getLeftIndex(e), i = y.getRightIndex(e), n = this.size();
|
|
181
|
+
s < n && this.compareFn(this.heap[e], this.heap[s]) === -1 && (e = s), i < n && this.compareFn(this.heap[e], this.heap[i]) === 1 && (e = i), e !== t && (y.swap(this.heap, t, e), this.siftUp(e));
|
|
182
182
|
}
|
|
183
183
|
siftDown(t) {
|
|
184
|
-
let e =
|
|
184
|
+
let e = y.getParentIndex(t);
|
|
185
185
|
for (; t > 0 && e && this.compareFn(this.heap[e], this.heap[t]) === 1; )
|
|
186
|
-
|
|
186
|
+
y.swap(this.heap, e, t), t = e, e = y.getParentIndex(t);
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
class q extends O {
|
|
@@ -227,7 +227,7 @@ class j {
|
|
|
227
227
|
s ? (this.detach(s), this.prepend(s), s.value = e) : (s = L(e), this.length++, this.prepend(s), this.trimCache(), this.lookup.set(t, s), this.reverseLookup);
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
|
-
class
|
|
230
|
+
class S {
|
|
231
231
|
value;
|
|
232
232
|
next = void 0;
|
|
233
233
|
}
|
|
@@ -264,7 +264,7 @@ class U {
|
|
|
264
264
|
return this.getElementAt(t)?.value;
|
|
265
265
|
}
|
|
266
266
|
insert(t, e) {
|
|
267
|
-
let s = new
|
|
267
|
+
let s = new S();
|
|
268
268
|
if (s.value = t, e > this.count || e < 0)
|
|
269
269
|
throw new Error("index error");
|
|
270
270
|
this.count++;
|
|
@@ -276,7 +276,7 @@ class U {
|
|
|
276
276
|
i = this.getElementAt(e - 1), n = i.next, i.next = s, s.next = n;
|
|
277
277
|
}
|
|
278
278
|
push(t) {
|
|
279
|
-
let e = new
|
|
279
|
+
let e = new S();
|
|
280
280
|
if (e.value = t, this.count++, this.isEmpty()) {
|
|
281
281
|
this.head = e;
|
|
282
282
|
return;
|
|
@@ -417,10 +417,10 @@ class $ {
|
|
|
417
417
|
return t;
|
|
418
418
|
}
|
|
419
419
|
}
|
|
420
|
-
class
|
|
420
|
+
class w {
|
|
421
421
|
_data;
|
|
422
422
|
static zero(t) {
|
|
423
|
-
return new
|
|
423
|
+
return new w(...Array(t).fill(0));
|
|
424
424
|
}
|
|
425
425
|
constructor(...t) {
|
|
426
426
|
this._data = t;
|
|
@@ -439,7 +439,7 @@ class y {
|
|
|
439
439
|
if (t === 0)
|
|
440
440
|
throw new Error("Cannot normalize a zero vector");
|
|
441
441
|
const e = this._data.map((s) => s / t);
|
|
442
|
-
return new
|
|
442
|
+
return new w(...e);
|
|
443
443
|
}
|
|
444
444
|
add(t) {
|
|
445
445
|
if (this.dimension !== t.dimension)
|
|
@@ -447,7 +447,7 @@ class y {
|
|
|
447
447
|
const e = this._data.map(
|
|
448
448
|
(s, i) => s + t._data[i]
|
|
449
449
|
);
|
|
450
|
-
return new
|
|
450
|
+
return new w(...e);
|
|
451
451
|
}
|
|
452
452
|
sub(t) {
|
|
453
453
|
if (this.dimension !== t.dimension)
|
|
@@ -455,10 +455,10 @@ class y {
|
|
|
455
455
|
const e = this._data.map(
|
|
456
456
|
(s, i) => s - t._data[i]
|
|
457
457
|
);
|
|
458
|
-
return new
|
|
458
|
+
return new w(...e);
|
|
459
459
|
}
|
|
460
460
|
mul(t) {
|
|
461
|
-
return new
|
|
461
|
+
return new w(...this._data.map((e) => e * t));
|
|
462
462
|
}
|
|
463
463
|
dot(t) {
|
|
464
464
|
if (this.dimension !== t.dimension)
|
|
@@ -475,13 +475,22 @@ class y {
|
|
|
475
475
|
return this.mul(-1);
|
|
476
476
|
}
|
|
477
477
|
}
|
|
478
|
-
class
|
|
478
|
+
class x {
|
|
479
479
|
_matrix;
|
|
480
480
|
static zero(t, e) {
|
|
481
|
-
return new
|
|
481
|
+
return new x(
|
|
482
482
|
Array.from({ length: t }, () => Array.from({ length: e }, () => 0))
|
|
483
483
|
);
|
|
484
484
|
}
|
|
485
|
+
static rotate(t) {
|
|
486
|
+
const e = t.length;
|
|
487
|
+
for (let s = 0; s < (e + 1) / 2; s++)
|
|
488
|
+
for (let i = s; i < e / 2; i++) {
|
|
489
|
+
const n = t[e - 1 - i][s];
|
|
490
|
+
t[e - 1 - i][s] = t[e - 1 - s][e - 1 - i], t[e - 1 - s][e - 1 - i] = t[i][e - 1 - s], t[i][e - 1 - s] = t[s][i], t[s][i] = n;
|
|
491
|
+
}
|
|
492
|
+
return t;
|
|
493
|
+
}
|
|
485
494
|
constructor(t) {
|
|
486
495
|
this._matrix = t;
|
|
487
496
|
}
|
|
@@ -498,10 +507,10 @@ class E {
|
|
|
498
507
|
return this.row * this.col;
|
|
499
508
|
}
|
|
500
509
|
rowVector(t) {
|
|
501
|
-
return new
|
|
510
|
+
return new w(...this._matrix[t]);
|
|
502
511
|
}
|
|
503
512
|
colVector(t) {
|
|
504
|
-
return new
|
|
513
|
+
return new w(...this._matrix.map((e) => e[t]));
|
|
505
514
|
}
|
|
506
515
|
getItem(t) {
|
|
507
516
|
return this._matrix[t[0]][t[1]];
|
|
@@ -510,7 +519,7 @@ class E {
|
|
|
510
519
|
return this._matrix[t[0]][t[1]] = e, this;
|
|
511
520
|
}
|
|
512
521
|
mul(t) {
|
|
513
|
-
return new
|
|
522
|
+
return new x(this._matrix.map((e) => e.map((s) => s * t)));
|
|
514
523
|
}
|
|
515
524
|
div(t) {
|
|
516
525
|
return this.mul(1 / t);
|
|
@@ -518,7 +527,7 @@ class E {
|
|
|
518
527
|
add(t) {
|
|
519
528
|
if (this.row !== t.row || this.col !== t.col)
|
|
520
529
|
throw new Error("Matrix dimensions do not match");
|
|
521
|
-
return new
|
|
530
|
+
return new x(
|
|
522
531
|
this._matrix.map(
|
|
523
532
|
(e, s) => e.map((i, n) => i + t.getItem([s, n]))
|
|
524
533
|
)
|
|
@@ -536,14 +545,14 @@ class E {
|
|
|
536
545
|
mulVector(t) {
|
|
537
546
|
if (this.col !== t.dimension)
|
|
538
547
|
throw new Error("Matrix dimensions do not match");
|
|
539
|
-
return new
|
|
548
|
+
return new x(
|
|
540
549
|
this._matrix.map((e) => e.map((s, i) => s * t.getItem(i)))
|
|
541
550
|
);
|
|
542
551
|
}
|
|
543
552
|
mulMatrix(t) {
|
|
544
553
|
if (this.col !== t.row)
|
|
545
554
|
throw new Error("Matrix dimensions do not match");
|
|
546
|
-
const e =
|
|
555
|
+
const e = x.zero(this.row, t.col);
|
|
547
556
|
for (let s = 0; s < this.row; s++) {
|
|
548
557
|
const i = this.rowVector(s);
|
|
549
558
|
for (let n = 0; n < this.col; n++)
|
|
@@ -580,8 +589,8 @@ class g {
|
|
|
580
589
|
if (g.isParallel(t, e)) return null;
|
|
581
590
|
const i = t.p1.x, n = t.p1.y, h = t.p2.x, o = t.p2.y, c = e.p1.x, f = e.p1.y, m = e.p2.x, a = e.p2.y, l = (i - h) * (f - a) - (n - o) * (c - m);
|
|
582
591
|
if (Math.abs(l) < s) return null;
|
|
583
|
-
const d = ((i - c) * (f - a) - (n - f) * (c - m)) / l,
|
|
584
|
-
if (d >= 0 && d <= 1 &&
|
|
592
|
+
const d = ((i - c) * (f - a) - (n - f) * (c - m)) / l, v = -((i - h) * (n - f) - (n - o) * (i - c)) / l;
|
|
593
|
+
if (d >= 0 && d <= 1 && v >= 0 && v <= 1) {
|
|
585
594
|
const k = i + d * (h - i), N = n + d * (o - n);
|
|
586
595
|
return new u(k, N);
|
|
587
596
|
}
|
|
@@ -596,8 +605,8 @@ class g {
|
|
|
596
605
|
f > s && (m = c / f);
|
|
597
606
|
let a, l;
|
|
598
607
|
m < 0 ? (a = t.p1.x, l = t.p1.y) : m > 1 ? (a = t.p2.x, l = t.p2.y) : (a = t.p1.x + m * h, l = t.p1.y + m * o);
|
|
599
|
-
const d = e.x - a,
|
|
600
|
-
return Math.hypot(d +
|
|
608
|
+
const d = e.x - a, v = e.y - l;
|
|
609
|
+
return Math.hypot(d + v);
|
|
601
610
|
}
|
|
602
611
|
p1;
|
|
603
612
|
p2;
|
|
@@ -750,7 +759,7 @@ function H(r) {
|
|
|
750
759
|
function b(r) {
|
|
751
760
|
return r !== null && (typeof r == "object" || typeof r == "function");
|
|
752
761
|
}
|
|
753
|
-
class
|
|
762
|
+
class T {
|
|
754
763
|
map = /* @__PURE__ */ new Map();
|
|
755
764
|
weakMap = /* @__PURE__ */ new WeakMap();
|
|
756
765
|
set(t, e) {
|
|
@@ -763,7 +772,7 @@ class F {
|
|
|
763
772
|
return b(t) ? this.weakMap.has(t) : this.map.has(t);
|
|
764
773
|
}
|
|
765
774
|
}
|
|
766
|
-
function
|
|
775
|
+
function F(r) {
|
|
767
776
|
if (!r.length) return [];
|
|
768
777
|
const t = [[r[0]]];
|
|
769
778
|
for (let s = 1, i = r.length; s < i; s++) {
|
|
@@ -947,11 +956,31 @@ class G {
|
|
|
947
956
|
const i = e[1] - e[0];
|
|
948
957
|
return (t - e[0]) * ((s[1] - s[0]) / i) + s[0];
|
|
949
958
|
}
|
|
959
|
+
static isRange(t, e, s) {
|
|
960
|
+
if (s == null && (s = e, e = 0), e >= s)
|
|
961
|
+
throw new Error(
|
|
962
|
+
"The maximum value must be greater than the minimum value"
|
|
963
|
+
);
|
|
964
|
+
return e <= t && t < s;
|
|
965
|
+
}
|
|
950
966
|
static clamp(t, e, s) {
|
|
951
|
-
return Math.min(Math.max(t, e), s);
|
|
967
|
+
return s == null ? Math.min(t, e) : Math.min(Math.max(t, e), s);
|
|
968
|
+
}
|
|
969
|
+
static random(t, e) {
|
|
970
|
+
if (e == null && (e = t, t = 0), t >= e)
|
|
971
|
+
throw new Error(
|
|
972
|
+
"The maximum value must be greater than the minimum value"
|
|
973
|
+
);
|
|
974
|
+
return Math.random() * (e - t) + t;
|
|
952
975
|
}
|
|
953
976
|
static randomInt(t, e) {
|
|
954
|
-
return Math.floor(
|
|
977
|
+
return Math.floor(this.random(t, e));
|
|
978
|
+
}
|
|
979
|
+
static round(t, e = 0) {
|
|
980
|
+
if (!Number.isInteger(e))
|
|
981
|
+
throw new Error("precision must be an integer");
|
|
982
|
+
const s = Math.pow(10, e);
|
|
983
|
+
return Math.round(t * s) / s;
|
|
955
984
|
}
|
|
956
985
|
static floatEqual(t, e, s = 1e-6) {
|
|
957
986
|
return Math.abs(t - e) < s;
|
|
@@ -959,6 +988,31 @@ class G {
|
|
|
959
988
|
static isSameSign(t, e) {
|
|
960
989
|
return t >= 0 && e >= 0 || t <= 0 && e <= 0;
|
|
961
990
|
}
|
|
991
|
+
static fastPower(t, e) {
|
|
992
|
+
if (t < 0)
|
|
993
|
+
throw new Error("a must be greater than 0");
|
|
994
|
+
if (e < 0 || !Number.isInteger(e))
|
|
995
|
+
throw new Error("n must be a non-negative integer");
|
|
996
|
+
if (t === 0) return 0;
|
|
997
|
+
if (e === 0) return 1;
|
|
998
|
+
const s = this.fastPower(t, e >> 1);
|
|
999
|
+
return e % 2 === 0 ? s * s : s * s * t;
|
|
1000
|
+
}
|
|
1001
|
+
static consecutiveSum(t) {
|
|
1002
|
+
if (!this.isValidPositiveInteger)
|
|
1003
|
+
throw new Error("n must be a positive integer");
|
|
1004
|
+
return t * (t + 1) / 2;
|
|
1005
|
+
}
|
|
1006
|
+
static consecutiveSquaresSum(t) {
|
|
1007
|
+
if (!this.isValidPositiveInteger)
|
|
1008
|
+
throw new Error("n must be a positive integer");
|
|
1009
|
+
return t * (t + 1) * (2 * t + 1) / 6;
|
|
1010
|
+
}
|
|
1011
|
+
static consecutivecubesSum(t) {
|
|
1012
|
+
if (!this.isValidPositiveInteger)
|
|
1013
|
+
throw new Error("n must be a positive integer");
|
|
1014
|
+
return t * (t + 1) * (2 * t + 1) * (3 * t * t + 3 * t - 1) / 30;
|
|
1015
|
+
}
|
|
962
1016
|
}
|
|
963
1017
|
class W {
|
|
964
1018
|
static READ = 1;
|
|
@@ -1016,7 +1070,7 @@ function K(r) {
|
|
|
1016
1070
|
});
|
|
1017
1071
|
return r.prototype.constructor = e, e;
|
|
1018
1072
|
}
|
|
1019
|
-
const
|
|
1073
|
+
const E = {
|
|
1020
1074
|
AUTH_UNAUTHORIZED: "未授权事件",
|
|
1021
1075
|
AUTH_LOGIN_SUCCESS: "登录成功事件",
|
|
1022
1076
|
AUTH_LOGOUT: "注销事件",
|
|
@@ -1033,7 +1087,7 @@ class I {
|
|
|
1033
1087
|
listeners = {};
|
|
1034
1088
|
debugMode;
|
|
1035
1089
|
constructor(t = !1) {
|
|
1036
|
-
this.debugMode = t, Object.keys(
|
|
1090
|
+
this.debugMode = t, Object.keys(E).forEach(
|
|
1037
1091
|
(e) => {
|
|
1038
1092
|
this.listeners[e] = /* @__PURE__ */ new Set();
|
|
1039
1093
|
}
|
|
@@ -1049,7 +1103,7 @@ class I {
|
|
|
1049
1103
|
* @param listener 监听函数
|
|
1050
1104
|
*/
|
|
1051
1105
|
on(t, e) {
|
|
1052
|
-
this.debugLog(`添加事件监听: ${
|
|
1106
|
+
this.debugLog(`添加事件监听: ${E[t]}`), this.listeners[t].add(e);
|
|
1053
1107
|
}
|
|
1054
1108
|
/**
|
|
1055
1109
|
* 触发事件
|
|
@@ -1057,11 +1111,11 @@ class I {
|
|
|
1057
1111
|
* @param params 事件参数
|
|
1058
1112
|
*/
|
|
1059
1113
|
emit(t, e) {
|
|
1060
|
-
this.debugLog(`触发事件: ${
|
|
1114
|
+
this.debugLog(`触发事件: ${E[t]}`, e), this.listeners[t].forEach((s) => {
|
|
1061
1115
|
try {
|
|
1062
1116
|
s(e);
|
|
1063
1117
|
} catch (i) {
|
|
1064
|
-
console.error(`事件 ${
|
|
1118
|
+
console.error(`事件 ${E[t]} 处理出错:`, i);
|
|
1065
1119
|
}
|
|
1066
1120
|
});
|
|
1067
1121
|
}
|
|
@@ -1071,7 +1125,7 @@ class I {
|
|
|
1071
1125
|
* @param listener 监听函数
|
|
1072
1126
|
*/
|
|
1073
1127
|
off(t, e) {
|
|
1074
|
-
this.debugLog(`移除事件监听: ${
|
|
1128
|
+
this.debugLog(`移除事件监听: ${E[t]}`), this.listeners[t].delete(e);
|
|
1075
1129
|
}
|
|
1076
1130
|
/**
|
|
1077
1131
|
* 添加一次性事件监听器
|
|
@@ -1079,7 +1133,7 @@ class I {
|
|
|
1079
1133
|
* @param listener 监听函数
|
|
1080
1134
|
*/
|
|
1081
1135
|
once(t, e) {
|
|
1082
|
-
this.debugLog(`添加一次性事件监听: ${
|
|
1136
|
+
this.debugLog(`添加一次性事件监听: ${E[t]}`);
|
|
1083
1137
|
const s = (i) => {
|
|
1084
1138
|
e(i), this.off(t, s);
|
|
1085
1139
|
};
|
|
@@ -1181,13 +1235,13 @@ export {
|
|
|
1181
1235
|
R as Dictionary,
|
|
1182
1236
|
I as Emitter,
|
|
1183
1237
|
$ as Graph,
|
|
1184
|
-
|
|
1238
|
+
F as LIS,
|
|
1185
1239
|
j as LRU,
|
|
1186
1240
|
g as Line,
|
|
1187
1241
|
U as LinkedList,
|
|
1188
|
-
|
|
1242
|
+
x as Matrix,
|
|
1189
1243
|
q as MaxHeap,
|
|
1190
|
-
|
|
1244
|
+
T as MemoizeMap,
|
|
1191
1245
|
O as MinHeap,
|
|
1192
1246
|
D as MinStack,
|
|
1193
1247
|
G as Num,
|
|
@@ -1197,7 +1251,7 @@ export {
|
|
|
1197
1251
|
z as Stack,
|
|
1198
1252
|
X as Str,
|
|
1199
1253
|
p as Triangle,
|
|
1200
|
-
|
|
1254
|
+
w as Vector,
|
|
1201
1255
|
Z as binarySearchTemplate,
|
|
1202
1256
|
H as isValidBracket,
|
|
1203
1257
|
K as singleton,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(a,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(a=typeof globalThis<"u"?globalThis:a||self,b(a["jc-structure"]={}))})(this,(function(a){"use strict";class b{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 C{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 R{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
|
|
2
|
-
`;return t}}class w{_data;static zero(t){return new w(...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 w(...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,i)=>s+t._data[i]);return new w(...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,i)=>s-t._data[i]);return new w(...e)}mul(t){return new w(...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,i)=>e+s*t._data[i],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)))}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 w(...this._matrix[t])}colVector(t){return new w(...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((i,n)=>i+t.getItem([s,n]))))}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,i)=>s*t.getItem(i))))}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 i=this.rowVector(s);for(let n=0;n<this.col;n++)e.setItem([s,n],i.dot(t.colVector(n)))}return e}}class u{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 u.distance(this,t)}}class f{static EPSILON=1e-10;static sloped(t,e=f.EPSILON){const s=t.p2.x-t.p1.x,i=t.p2.y-t.p1.y;return Math.abs(s)<e?Math.abs(i)<e?0:null:i/s}static isParallel(t,e,s=f.EPSILON){const i=f.sloped(t),n=f.sloped(e);return i===null&&n===null?!0:i===null||n===null?!1:Math.abs(i-n)<s}static getIntersection(t,e,s=f.EPSILON){if(f.isParallel(t,e))return null;const i=t.p1.x,n=t.p1.y,h=t.p2.x,c=t.p2.y,l=e.p1.x,g=e.p1.y,y=e.p2.x,o=e.p2.y,d=(i-h)*(g-o)-(n-c)*(l-y);if(Math.abs(d)<s)return null;const m=((i-l)*(g-o)-(n-g)*(l-y))/d,M=-((i-h)*(n-g)-(n-c)*(i-l))/d;if(m>=0&&m<=1&&M>=0&&M<=1){const Z=i+m*(h-i),J=n+m*(c-n);return new u(Z,J)}return null}static isIntersecting(t,e){return f.getIntersection(t,e)!==null}static distanceToPoint(t,e,s=f.EPSILON){const i=e.x-t.p1.x,n=e.y-t.p1.y,h=t.p2.x-t.p1.x,c=t.p2.y-t.p1.y,l=i*h+n*c,g=h*h+c*c;let y=-1;g>s&&(y=l/g);let o,d;y<0?(o=t.p1.x,d=t.p1.y):y>1?(o=t.p2.x,d=t.p2.y):(o=t.p1.x+y*h,d=t.p1.y+y*c);const m=e.x-o,M=e.y-d;return Math.hypot(m+M)}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 u(t,e)}get angle(){return Math.atan2(this.p2.y-this.p1.y,this.p2.x-this.p1.x)}containsPoint(t,e=f.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<f.EPSILON)return new u(0,0);const e=(this.p2.x-this.p1.x)/t,s=(this.p2.y-this.p1.y)/t;return new u(e,s)}get start(){return this.p1}get end(){return this.p2}}class O{static EPSILON=1e-10;name;constructor(t){this.name=t}}class p extends O{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(!p.isValid(t,e,s))throw new Error("Invalid triangle");const i=(t+e+s)/2;return Math.sqrt(i*(i-t)*(i-e)*(i-s))}static getType(t,e,s){if(!p.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=[t,e,s].sort((l,g)=>l-g),[n,h,c]=i;return Math.abs(n-h)<p.EPSILON&&Math.abs(h-c)<p.EPSILON?"equilateral":Math.abs(n-h)<p.EPSILON||Math.abs(h-c)<p.EPSILON?"isosceles":"scalene"}static getAngles(t,e,s){if(!p.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=Math.acos((e*e+s*s-t*t)/(2*e*s)),n=Math.acos((t*t+s*s-e*e)/(2*t*s)),h=Math.PI-i-n;return[i,n,h]}p1;p2;p3;constructor(t,e,s,i="triangle"){if(super(i),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))<O.EPSILON}get side(){return[u.distance(this.p1,this.p2),u.distance(this.p2,this.p3),u.distance(this.p3,this.p1)]}perimeter(){return p.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 p.area(t,e,s)}get type(){const[t,e,s]=this.side;return p.getType(t,e,s)}get angles(){const[t,e,s]=this.side;return p.getAngles(t,e,s)}get centroid(){return new u((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,i=this.perimeter()/2,n=(t*this.p1.x+e*this.p2.x+s*this.p3.x)/i,h=(t*this.p1.y+e*this.p2.y+s*this.p3.y)/i;return new u(n,h)}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)<p.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 u(e,s)}containsPoint(t){const e=p.area(u.distance(t,this.p1),u.distance(t,this.p2),u.distance(this.p1,this.p2)),s=p.area(u.distance(t,this.p2),u.distance(t,this.p3),u.distance(this.p2,this.p3)),i=p.area(u.distance(t,this.p3),u.distance(t,this.p1),u.distance(this.p3,this.p1));return Math.abs(e+s+i-this.area())<p.EPSILON}}function $(r){return new Promise(t=>setTimeout(t,r))}function H(r){const t=[],e={"(":")","[":"]","{":"}"},s=new Set(Object.values(e));for(const i of r)if(i in e)t.push(e[i]);else if(s.has(i)&&i!==t.pop())return!1;return t.length===0}function v(r){return r!==null&&(typeof r=="object"||typeof r=="function")}class _{map=new Map;weakMap=new WeakMap;set(t,e){v(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return v(t)?this.weakMap.get(t):this.map.get(t)}has(t){return v(t)?this.weakMap.has(t):this.map.has(t)}}function T(r){if(!r.length)return[];const t=[[r[0]]];for(let s=1,i=r.length;s<i;s++){const n=r[s];e(n)}function e(s){for(let i=t.length-1;i>=0;i--){const n=t[i],h=n[t[i].length-1];if(h<s){t[i+1]=[...n,s];break}else h>s&&i===0&&(t[i]=[s])}}return t[t.length-1]}class B{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 h of t)if(!e.has(h))throw new Error(`Invalid Roman numeral character: ${h}`);let s=0,i=0;for(;i<t.length;){const h=t.slice(i,i+2);if(this.ROMAN_MAP.has(h))s+=this.ROMAN_MAP.get(h),i+=2;else{const c=t[i],l=this.ROMAN_MAP.get(c);if(!l)throw new Error(`Invalid Roman numeral sequence at position ${i}`);s+=l,i+=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,i]of this.ROMAN_MAP)for(;t>=i;)e+=s,t-=i;return e}}class F{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 factorial(t){if(!this.isValidPositiveInteger(t))throw new Error("Input must be a non-negative integer");if(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){if(!this.isValidPositiveInteger(t))throw new Error("Input must be a non-negative integer");return t<2?s:this.fibonacci(t-1,s,s+e)}static fibonacciIterative(t){if(t<2)return t;let e=0,s=1;for(let i=2;i<t;i++)[e,s]=[s,(e+s)%1000000007];return s}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((o,d)=>o+d,0);if(s===0)return t.map(()=>"0%");const n=100*Math.pow(10,e),h=t.map(o=>o/s*n),c=h.map(o=>Math.floor(o)),l=h.map((o,d)=>o-c[d]);let g=c.reduce((o,d)=>o+d,0),y=n-g;for(;y>0;){let o=-1,d=-1;for(let m=0;m<l.length;m++)l[m]>d&&(d=l[m],o=m);if(o===-1)break;c[o]++,l[o]=0,y--}return c.map(o=>`${(o/n*100).toFixed(e)}%`)}static fastSqrt(t){if(t<0)throw new Error("n must be a non-negative number");const e=.5*t;let s=new BigInt64Array(new Float32Array([t]).buffer)[0];s=0x1ff7a3bea91d9b1bn+(s>>1n);let i=new Float64Array(new BigInt64Array([s]).buffer)[0];return i=i*.5+e/i,i=i*.5+e/i,i=i*.5+e/i,i}static gcd(t,e){return e===0?t:this.gcd(e,t%e)}static lcm(t,e){return t*e/this.gcd(t,e)}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 i=t%10;e=e*10+i,t=Math.floor(t/10)}return s===e}static isArmstrong(t){const e=t.toString(),s=e.length;let i=0;for(let n=0;n<s;n++)i+=Math.pow(parseInt(e[n]),s);return i===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,i)=>s+Number(i)*Number(i),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 middle(t,e){return e-(e-t>>1)}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 i=e[1]-e[0];return(t-e[0])*((s[1]-s[0])/i)+s[0]}static clamp(t,e,s){return Math.min(Math.max(t,e),s)}static randomInt(t,e){return Math.floor(Math.random()*(e-t+1))+t}static floatEqual(t,e,s=1e-6){return Math.abs(t-e)<s}static isSameSign(t,e){return t>=0&&e>=0||t<=0&&e<=0}}class G{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 Q{static longestCommonPrefix(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}static uuid(t){return typeof t=="number"?(t^Math.random()*16>>t/4).toString(16):(9987e3+-1e11).toString().replace(/[018]/g,e=>{const s=parseInt(e,10);return this.uuid(s)})}}class W{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)}}function X(r){let t;const e=new Proxy(r,{construct(s,i,n){return t||(t=Reflect.construct(s,i,n)),t}});return r.prototype.constructor=e,e}const I={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 S{static instance=null;listeners={};debugMode;constructor(t=!1){this.debugMode=t,Object.keys(I).forEach(e=>{this.listeners[e]=new Set})}static getInstance(t){return S.instance||(S.instance=new S(t)),S.instance}on(t,e){this.debugLog(`添加事件监听: ${I[t]}`),this.listeners[t].add(e)}emit(t,e){this.debugLog(`触发事件: ${I[t]}`,e),this.listeners[t].forEach(s=>{try{s(e)}catch(i){console.error(`事件 ${I[t]} 处理出错:`,i)}})}off(t,e){this.debugLog(`移除事件监听: ${I[t]}`),this.listeners[t].delete(e)}once(t,e){this.debugLog(`添加一次性事件监听: ${I[t]}`);const s=i=>{e(i),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||"")}}function K(r,t,e){let s=-1,i=r.length,n;for(;i-s>1;)n=i-(i-s)>>1,e(r[n],t)?i=n:s=n;return i}String.prototype.pointLength=function(){let r=0;for(let t=0,e=this.length;t<e;){const s=this.codePointAt(t);t+=s>65535?2:1,r++}return r},String.prototype.pointAt=function(r){if(r>=this.pointLength())return;let t=0;for(let e=0,s=this.length;e<s;){const i=this.codePointAt(e);if(!i)return;if(t===r)return String.fromCodePoint(i);e+=i>65535?2:1,t++}},String.prototype.sliceByPoint=function(r,t=this.pointLength()){let e="";for(let s=r;s<t;s++)e+=this.pointAt(s);return e},RegExp.escape=function(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},Element.prototype.farthest=function(r){if(typeof r!="string"||!r)return null;let t=null,e=this;for(;e;){const s=e.closest(r);if(!s)break;t=s,e=s.parentElement}return t},Object.defineProperties(Element.prototype,{firstElement:{get:function(){if(!this.children.length)return null;let r=this.firstElementChild,t=null;for(;r;)t=r,r=r.firstElementChild;return t}},lastElement:{get:function(){if(!this.children.length)return null;let r=this.lastElementChild,t=null;for(;r;)t=r,r=r.lastElementChild;return t}}}),Text.prototype.surround=function(r="strong",t=""){if(!this.nodeValue||!r||!t)return null;const s=r.split("."),i=s[0],n=s.slice(1).join(" "),h=this.textContent.indexOf(t);if(h<0)return null;const c=document.createRange();c.setStart(this,h),c.setEnd(this,h+t.length);const l=document.createElement(i);return n&&(l.className=n),c.surroundContents(l),l},a.BitPerm=G,a.Color=W,a.Dictionary=N,a.Emitter=S,a.Graph=U,a.LIS=T,a.LRU=D,a.Line=f,a.LinkedList=j,a.Matrix=x,a.MaxHeap=V,a.MemoizeMap=_,a.MinHeap=P,a.MinStack=R,a.Num=F,a.Point=u,a.Queue=b,a.Roman=B,a.Stack=C,a.Str=Q,a.Triangle=p,a.Vector=w,a.binarySearchTemplate=K,a.isValidBracket=H,a.singleton=X,a.sleep=$,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(a,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(a=typeof globalThis<"u"?globalThis:a||self,b(a["jc-structure"]={}))})(this,(function(a){"use strict";class b{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 C{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 R{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(r,t){return r===t?0:r<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 A 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),i=E.getRightIndex(e),n=this.size();s<n&&this.compareFn(this.heap[e],this.heap[s])===-1&&(e=s),i<n&&this.compareFn(this.heap[e],this.heap[i])===1&&(e=i),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 V extends A{constructor(t=(e,s)=>P(s,e)){super(t)}}function z(r){return{value:r}}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=z(e),this.length++,this.prepend(s),this.trimCache(),this.lookup.set(t,s),this.reverseLookup)}}class k{value;next=void 0}class D{count=0;head=void 0;constructor(){}indexOf(t){let e=this.head,s=0,i=!1;for(;e;){if(this.equals(e.value,t)){i=!0;break}s++,e=e.next}return i?s:-1}equals(t,e){return!1}getElementAt(t){if(t<0||t>=this.count)return;if(t===0)return this.head;let e=this.head;for(let s=0;s<t;s++)e=e?.next;return e}getValueAt(t){return this.getElementAt(t)?.value}insert(t,e){let s=new k;if(s.value=t,e>this.count||e<0)throw new Error("index error");this.count++;let i,n;if(e===0){s.next=this.head,this.head=s;return}i=this.getElementAt(e-1),n=i.next,i.next=s,s.next=n}push(t){let e=new k;if(e.value=t,this.count++,this.isEmpty()){this.head=e;return}let s=this.getElementAt(this.count-1);s.next=e}remove(t){const e=this.indexOf(t);return e===-1?void 0:this.removeAt(e)}removeAt(t){if(this.isEmpty()||t<0||t>=this.count)return;let e=this.getElementAt(t),s=this.getElementAt(t-1),i=e?.next;return t===0&&(this.head=i),s&&(s.next=i),this.count--,e?.value}isEmpty(){return this.count===0}size(){return this.count}clear(){this.count=0,this.head=void 0}toString(){let t="",e=this.head;for(;e;)t+=e.value,t+=",",e=e.next;return t=t.slice(0,-1),t}}class q{key;value;constructor(t,e){this.key=t,this.value=e}}function L(r,t={emptyString:!1,zeroNumber:!1}){return r==null?!(t.emptyString&&r===""||t.zeroNumber&&r===0):!1}class N{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(L(t))throw new Error("key is required");if(L(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 q(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 i=this.table[e];if(!t(i.key,i.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 U{isDirected;vertices;adjList;constructor(t=!1){this.isDirected=t,this.vertices=[],this.adjList=new N}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 y{_data;static zero(t){return new y(...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 y(...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,i)=>s+t._data[i]);return new y(...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,i)=>s-t._data[i]);return new y(...e)}mul(t){return new y(...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,i)=>e+s*t._data[i],0)}pos(){return this.mul(1)}neg(){return this.mul(-1)}}class I{_matrix;static zero(t,e){return new I(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 i=s;i<e/2;i++){const n=t[e-1-i][s];t[e-1-i][s]=t[e-1-s][e-1-i],t[e-1-s][e-1-i]=t[i][e-1-s],t[i][e-1-s]=t[s][i],t[s][i]=n}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 y(...this._matrix[t])}colVector(t){return new y(...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 I(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 I(this._matrix.map((e,s)=>e.map((i,n)=>i+t.getItem([s,n]))))}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 I(this._matrix.map(e=>e.map((s,i)=>s*t.getItem(i))))}mulMatrix(t){if(this.col!==t.row)throw new Error("Matrix dimensions do not match");const e=I.zero(this.row,t.col);for(let s=0;s<this.row;s++){const i=this.rowVector(s);for(let n=0;n<this.col;n++)e.setItem([s,n],i.dot(t.colVector(n)))}return e}}class u{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 u.distance(this,t)}}class f{static EPSILON=1e-10;static sloped(t,e=f.EPSILON){const s=t.p2.x-t.p1.x,i=t.p2.y-t.p1.y;return Math.abs(s)<e?Math.abs(i)<e?0:null:i/s}static isParallel(t,e,s=f.EPSILON){const i=f.sloped(t),n=f.sloped(e);return i===null&&n===null?!0:i===null||n===null?!1:Math.abs(i-n)<s}static getIntersection(t,e,s=f.EPSILON){if(f.isParallel(t,e))return null;const i=t.p1.x,n=t.p1.y,h=t.p2.x,c=t.p2.y,l=e.p1.x,g=e.p1.y,w=e.p2.x,o=e.p2.y,d=(i-h)*(g-o)-(n-c)*(l-w);if(Math.abs(d)<s)return null;const m=((i-l)*(g-o)-(n-g)*(l-w))/d,S=-((i-h)*(n-g)-(n-c)*(i-l))/d;if(m>=0&&m<=1&&S>=0&&S<=1){const Z=i+m*(h-i),J=n+m*(c-n);return new u(Z,J)}return null}static isIntersecting(t,e){return f.getIntersection(t,e)!==null}static distanceToPoint(t,e,s=f.EPSILON){const i=e.x-t.p1.x,n=e.y-t.p1.y,h=t.p2.x-t.p1.x,c=t.p2.y-t.p1.y,l=i*h+n*c,g=h*h+c*c;let w=-1;g>s&&(w=l/g);let o,d;w<0?(o=t.p1.x,d=t.p1.y):w>1?(o=t.p2.x,d=t.p2.y):(o=t.p1.x+w*h,d=t.p1.y+w*c);const m=e.x-o,S=e.y-d;return Math.hypot(m+S)}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 u(t,e)}get angle(){return Math.atan2(this.p2.y-this.p1.y,this.p2.x-this.p1.x)}containsPoint(t,e=f.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<f.EPSILON)return new u(0,0);const e=(this.p2.x-this.p1.x)/t,s=(this.p2.y-this.p1.y)/t;return new u(e,s)}get start(){return this.p1}get end(){return this.p2}}class O{static EPSILON=1e-10;name;constructor(t){this.name=t}}class p extends O{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(!p.isValid(t,e,s))throw new Error("Invalid triangle");const i=(t+e+s)/2;return Math.sqrt(i*(i-t)*(i-e)*(i-s))}static getType(t,e,s){if(!p.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=[t,e,s].sort((l,g)=>l-g),[n,h,c]=i;return Math.abs(n-h)<p.EPSILON&&Math.abs(h-c)<p.EPSILON?"equilateral":Math.abs(n-h)<p.EPSILON||Math.abs(h-c)<p.EPSILON?"isosceles":"scalene"}static getAngles(t,e,s){if(!p.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=Math.acos((e*e+s*s-t*t)/(2*e*s)),n=Math.acos((t*t+s*s-e*e)/(2*t*s)),h=Math.PI-i-n;return[i,n,h]}p1;p2;p3;constructor(t,e,s,i="triangle"){if(super(i),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))<O.EPSILON}get side(){return[u.distance(this.p1,this.p2),u.distance(this.p2,this.p3),u.distance(this.p3,this.p1)]}perimeter(){return p.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 p.area(t,e,s)}get type(){const[t,e,s]=this.side;return p.getType(t,e,s)}get angles(){const[t,e,s]=this.side;return p.getAngles(t,e,s)}get centroid(){return new u((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,i=this.perimeter()/2,n=(t*this.p1.x+e*this.p2.x+s*this.p3.x)/i,h=(t*this.p1.y+e*this.p2.y+s*this.p3.y)/i;return new u(n,h)}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)<p.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 u(e,s)}containsPoint(t){const e=p.area(u.distance(t,this.p1),u.distance(t,this.p2),u.distance(this.p1,this.p2)),s=p.area(u.distance(t,this.p2),u.distance(t,this.p3),u.distance(this.p2,this.p3)),i=p.area(u.distance(t,this.p3),u.distance(t,this.p1),u.distance(this.p3,this.p1));return Math.abs(e+s+i-this.area())<p.EPSILON}}function $(r){return new Promise(t=>setTimeout(t,r))}function H(r){const t=[],e={"(":")","[":"]","{":"}"},s=new Set(Object.values(e));for(const i of r)if(i in e)t.push(e[i]);else if(s.has(i)&&i!==t.pop())return!1;return t.length===0}function M(r){return r!==null&&(typeof r=="object"||typeof r=="function")}class T{map=new Map;weakMap=new WeakMap;set(t,e){M(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return M(t)?this.weakMap.get(t):this.map.get(t)}has(t){return M(t)?this.weakMap.has(t):this.map.has(t)}}function _(r){if(!r.length)return[];const t=[[r[0]]];for(let s=1,i=r.length;s<i;s++){const n=r[s];e(n)}function e(s){for(let i=t.length-1;i>=0;i--){const n=t[i],h=n[t[i].length-1];if(h<s){t[i+1]=[...n,s];break}else h>s&&i===0&&(t[i]=[s])}}return t[t.length-1]}class B{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 h of t)if(!e.has(h))throw new Error(`Invalid Roman numeral character: ${h}`);let s=0,i=0;for(;i<t.length;){const h=t.slice(i,i+2);if(this.ROMAN_MAP.has(h))s+=this.ROMAN_MAP.get(h),i+=2;else{const c=t[i],l=this.ROMAN_MAP.get(c);if(!l)throw new Error(`Invalid Roman numeral sequence at position ${i}`);s+=l,i+=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,i]of this.ROMAN_MAP)for(;t>=i;)e+=s,t-=i;return e}}class F{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 factorial(t){if(!this.isValidPositiveInteger(t))throw new Error("Input must be a non-negative integer");if(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){if(!this.isValidPositiveInteger(t))throw new Error("Input must be a non-negative integer");return t<2?s:this.fibonacci(t-1,s,s+e)}static fibonacciIterative(t){if(t<2)return t;let e=0,s=1;for(let i=2;i<t;i++)[e,s]=[s,(e+s)%1000000007];return s}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((o,d)=>o+d,0);if(s===0)return t.map(()=>"0%");const n=100*Math.pow(10,e),h=t.map(o=>o/s*n),c=h.map(o=>Math.floor(o)),l=h.map((o,d)=>o-c[d]);let g=c.reduce((o,d)=>o+d,0),w=n-g;for(;w>0;){let o=-1,d=-1;for(let m=0;m<l.length;m++)l[m]>d&&(d=l[m],o=m);if(o===-1)break;c[o]++,l[o]=0,w--}return c.map(o=>`${(o/n*100).toFixed(e)}%`)}static fastSqrt(t){if(t<0)throw new Error("n must be a non-negative number");const e=.5*t;let s=new BigInt64Array(new Float32Array([t]).buffer)[0];s=0x1ff7a3bea91d9b1bn+(s>>1n);let i=new Float64Array(new BigInt64Array([s]).buffer)[0];return i=i*.5+e/i,i=i*.5+e/i,i=i*.5+e/i,i}static gcd(t,e){return e===0?t:this.gcd(e,t%e)}static lcm(t,e){return t*e/this.gcd(t,e)}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 i=t%10;e=e*10+i,t=Math.floor(t/10)}return s===e}static isArmstrong(t){const e=t.toString(),s=e.length;let i=0;for(let n=0;n<s;n++)i+=Math.pow(parseInt(e[n]),s);return i===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,i)=>s+Number(i)*Number(i),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 middle(t,e){return e-(e-t>>1)}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 i=e[1]-e[0];return(t-e[0])*((s[1]-s[0])/i)+s[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 clamp(t,e,s){return s==null?Math.min(t,e):Math.min(Math.max(t,e),s)}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 floatEqual(t,e,s=1e-6){return Math.abs(t-e)<s}static isSameSign(t,e){return t>=0&&e>=0||t<=0&&e<=0}static fastPower(t,e){if(t<0)throw new Error("a must be greater than 0");if(e<0||!Number.isInteger(e))throw new Error("n must be a non-negative integer");if(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 consecutiveSum(t){if(!this.isValidPositiveInteger)throw new Error("n must be a positive integer");return t*(t+1)/2}static consecutiveSquaresSum(t){if(!this.isValidPositiveInteger)throw new Error("n must be a positive integer");return t*(t+1)*(2*t+1)/6}static consecutivecubesSum(t){if(!this.isValidPositiveInteger)throw new Error("n must be a positive integer");return t*(t+1)*(2*t+1)*(3*t*t+3*t-1)/30}}class G{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 Q{static longestCommonPrefix(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}static uuid(t){return typeof t=="number"?(t^Math.random()*16>>t/4).toString(16):(9987e3+-1e11).toString().replace(/[018]/g,e=>{const s=parseInt(e,10);return this.uuid(s)})}}class W{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)}}function X(r){let t;const e=new Proxy(r,{construct(s,i,n){return t||(t=Reflect.construct(s,i,n)),t}});return r.prototype.constructor=e,e}const x={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(x).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(`添加事件监听: ${x[t]}`),this.listeners[t].add(e)}emit(t,e){this.debugLog(`触发事件: ${x[t]}`,e),this.listeners[t].forEach(s=>{try{s(e)}catch(i){console.error(`事件 ${x[t]} 处理出错:`,i)}})}off(t,e){this.debugLog(`移除事件监听: ${x[t]}`),this.listeners[t].delete(e)}once(t,e){this.debugLog(`添加一次性事件监听: ${x[t]}`);const s=i=>{e(i),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||"")}}function K(r,t,e){let s=-1,i=r.length,n;for(;i-s>1;)n=i-(i-s)>>1,e(r[n],t)?i=n:s=n;return i}String.prototype.pointLength=function(){let r=0;for(let t=0,e=this.length;t<e;){const s=this.codePointAt(t);t+=s>65535?2:1,r++}return r},String.prototype.pointAt=function(r){if(r>=this.pointLength())return;let t=0;for(let e=0,s=this.length;e<s;){const i=this.codePointAt(e);if(!i)return;if(t===r)return String.fromCodePoint(i);e+=i>65535?2:1,t++}},String.prototype.sliceByPoint=function(r,t=this.pointLength()){let e="";for(let s=r;s<t;s++)e+=this.pointAt(s);return e},RegExp.escape=function(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},Element.prototype.farthest=function(r){if(typeof r!="string"||!r)return null;let t=null,e=this;for(;e;){const s=e.closest(r);if(!s)break;t=s,e=s.parentElement}return t},Object.defineProperties(Element.prototype,{firstElement:{get:function(){if(!this.children.length)return null;let r=this.firstElementChild,t=null;for(;r;)t=r,r=r.firstElementChild;return t}},lastElement:{get:function(){if(!this.children.length)return null;let r=this.lastElementChild,t=null;for(;r;)t=r,r=r.lastElementChild;return t}}}),Text.prototype.surround=function(r="strong",t=""){if(!this.nodeValue||!r||!t)return null;const s=r.split("."),i=s[0],n=s.slice(1).join(" "),h=this.textContent.indexOf(t);if(h<0)return null;const c=document.createRange();c.setStart(this,h),c.setEnd(this,h+t.length);const l=document.createElement(i);return n&&(l.className=n),c.surroundContents(l),l},a.BitPerm=G,a.Color=W,a.Dictionary=N,a.Emitter=v,a.Graph=U,a.LIS=_,a.LRU=j,a.Line=f,a.LinkedList=D,a.Matrix=I,a.MaxHeap=V,a.MemoizeMap=T,a.MinHeap=A,a.MinStack=R,a.Num=F,a.Point=u,a.Queue=b,a.Roman=B,a.Stack=C,a.Str=Q,a.Triangle=p,a.Vector=y,a.binarySearchTemplate=K,a.isValidBracket=H,a.singleton=X,a.sleep=$,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
|
package/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ declare module "jc-structure" {
|
|
|
20
20
|
*/
|
|
21
21
|
toString(): string;
|
|
22
22
|
}
|
|
23
|
+
|
|
23
24
|
/**
|
|
24
25
|
* 栈类,采用object实现
|
|
25
26
|
*/
|
|
@@ -119,6 +120,7 @@ declare module "jc-structure" {
|
|
|
119
120
|
readonly prototype: MinHeap<T>;
|
|
120
121
|
}
|
|
121
122
|
declare var MaxHeap: MaxConstructor;
|
|
123
|
+
|
|
122
124
|
/**
|
|
123
125
|
* LRU缓存类
|
|
124
126
|
*/
|
|
@@ -637,7 +639,7 @@ declare module "jc-structure" {
|
|
|
637
639
|
fibonacciIterative(n: number): number;
|
|
638
640
|
|
|
639
641
|
/**
|
|
640
|
-
* ####
|
|
642
|
+
* #### 获取准确的百分比字符串数组
|
|
641
643
|
* - 使用了"最大余数法"(也称为"汉密尔顿方法")来分配百分比
|
|
642
644
|
* - 这种方法可以确保所有百分比加起来正好等于100%,避免由于四舍五入造成的误差
|
|
643
645
|
* @param valueList 数值数组
|
|
@@ -684,18 +686,28 @@ declare module "jc-structure" {
|
|
|
684
686
|
*/
|
|
685
687
|
isPalindrome(n: number): boolean;
|
|
686
688
|
|
|
689
|
+
/**
|
|
690
|
+
* #### 是否是快乐数
|
|
691
|
+
* - 一个“快乐数”是指一个正整数,经过有限次变换后最终会变成1。变换规则是将每个数字的平方和作为下一个数字。
|
|
692
|
+
* @param n
|
|
693
|
+
*/
|
|
694
|
+
isHappy(n: number): boolean;
|
|
687
695
|
/**
|
|
688
696
|
* #### 是否是阿姆斯特朗数
|
|
697
|
+
* - 阿姆斯特朗数(也称水仙花数、自恋数)是指一个n位数(n≥3),它的每个位上的数字的n次幂之和等于它本身。
|
|
689
698
|
* @param n
|
|
690
699
|
*/
|
|
691
700
|
isArmstrong(n: number): boolean;
|
|
692
701
|
|
|
693
702
|
/**
|
|
694
703
|
* #### 是否是完美数
|
|
704
|
+
* - 完美数是指一个数恰好等于它的因子之和(不包括它本身)。
|
|
695
705
|
* @param n
|
|
696
706
|
*/
|
|
697
707
|
isPerfect(n: number): boolean;
|
|
698
708
|
|
|
709
|
+
middle(a: number, b: number);
|
|
710
|
+
|
|
699
711
|
/**
|
|
700
712
|
* #### 线性比例缩放取值
|
|
701
713
|
* @param n
|
|
@@ -708,6 +720,24 @@ declare module "jc-structure" {
|
|
|
708
720
|
target: [number, number]
|
|
709
721
|
): number;
|
|
710
722
|
|
|
723
|
+
isRange(n: number, min: number): boolean;
|
|
724
|
+
isRange(n: number, min: number, max: number): boolean;
|
|
725
|
+
|
|
726
|
+
clamp(n: number, bound1: number): number;
|
|
727
|
+
clamp(n: number, bound1: number, bound2: number): number;
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* #### 获取[0.min)随机数,不包含min
|
|
731
|
+
* @param min
|
|
732
|
+
*/
|
|
733
|
+
random(min: number): number;
|
|
734
|
+
/**
|
|
735
|
+
* #### 获取[min,max)随机数,不包含max
|
|
736
|
+
* @param min 最小数
|
|
737
|
+
* @param max 最大数
|
|
738
|
+
*/
|
|
739
|
+
random(min: number, max: number): number;
|
|
740
|
+
|
|
711
741
|
/**
|
|
712
742
|
* #### 获取随机整数,包含min和max
|
|
713
743
|
* @param min 最小数
|
|
@@ -729,6 +759,34 @@ declare module "jc-structure" {
|
|
|
729
759
|
* @param b
|
|
730
760
|
*/
|
|
731
761
|
isSameSign(a: number, b: number): boolean;
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* #### 快速计算指数幂;
|
|
765
|
+
* - 快速幂算法利用了分治的思想,将大问题分解为小问题;
|
|
766
|
+
* - 核心公式:a^n = (a^(n/2))^2 (当n为偶数)
|
|
767
|
+
* - 当n为奇数时:a^n = (a^(n/2))^2 * a
|
|
768
|
+
* - 使用位运算 exponent >> 1 来代替除以2,提高效率
|
|
769
|
+
* - 时间复杂度为O(log n),比朴素的O(n)方法快很多
|
|
770
|
+
* @param base
|
|
771
|
+
* @param exponent
|
|
772
|
+
*/
|
|
773
|
+
fastPower(a: number, n: number): number;
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* #### 连续自然数之和
|
|
777
|
+
* @param n
|
|
778
|
+
*/
|
|
779
|
+
consecutiveSum(n: number): number;
|
|
780
|
+
/**
|
|
781
|
+
* #### 连续自然数平方和
|
|
782
|
+
* @param n
|
|
783
|
+
*/
|
|
784
|
+
consecutiveSquaresSum(n: number): number;
|
|
785
|
+
/**
|
|
786
|
+
* #### 连续自然数立方和
|
|
787
|
+
* @param n
|
|
788
|
+
*/
|
|
789
|
+
consecutivecubesSum(n: number): number;
|
|
732
790
|
}
|
|
733
791
|
declare var Num: NumConstructor;
|
|
734
792
|
|