jc-structure 0.2.11 → 0.2.13

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.
@@ -1,4 +1,4 @@
1
- class q {
1
+ class V {
2
2
  items = {};
3
3
  count = 0;
4
4
  lowestCount = 0;
@@ -49,7 +49,7 @@ class q {
49
49
  return this.isEmpty() ? "" : `Queue(size: ${this.size()}):[${this.items[this.lowestCount]},...rest]`;
50
50
  }
51
51
  }
52
- class U {
52
+ class F {
53
53
  items = {};
54
54
  count = 0;
55
55
  constructor() {
@@ -100,7 +100,7 @@ class U {
100
100
  return this.isEmpty() ? "" : `Stack(count: ${this.count}):[${this.items[this.count - 1]},...rest]`;
101
101
  }
102
102
  }
103
- class V {
103
+ class _ {
104
104
  stack = [];
105
105
  minStack = [];
106
106
  push(t) {
@@ -129,13 +129,42 @@ class V {
129
129
  return this.isEmpty() ? "" : `MinStack(count: ${this.size()}):[${this.getMin()},...rest]`;
130
130
  }
131
131
  }
132
- function N(h, t) {
132
+ class R {
133
+ _arr;
134
+ constructor() {
135
+ this._arr = [];
136
+ }
137
+ isEmpty() {
138
+ return this._arr.length === 0;
139
+ }
140
+ clear() {
141
+ this._arr = [];
142
+ }
143
+ size() {
144
+ return this._arr.length;
145
+ }
146
+ toString() {
147
+ return this.isEmpty() ? "Stack: (0) []" : `Stack: (${this.size()}) [${this.peek()}, ...]`;
148
+ }
149
+ pop() {
150
+ return this._arr.pop();
151
+ }
152
+ push(...t) {
153
+ for (const e of t)
154
+ Array.isArray(e) ? this._arr.push(...e) : this._arr.push(e);
155
+ return this;
156
+ }
157
+ peek() {
158
+ return this._arr[this._arr.length - 1];
159
+ }
160
+ }
161
+ function C(h, t) {
133
162
  return h === t ? 0 : h < t ? -1 : 1;
134
163
  }
135
- class x {
164
+ class E {
136
165
  heap = [];
137
166
  compareFn;
138
- constructor(t = N) {
167
+ constructor(t = C) {
139
168
  this.compareFn = t;
140
169
  }
141
170
  static getLeftIndex(t) {
@@ -166,7 +195,7 @@ class x {
166
195
  return this.heap.toString();
167
196
  }
168
197
  }
169
- class $ extends x {
198
+ class D extends E {
170
199
  insert(t) {
171
200
  return t ? !1 : (this.heap.push(t), this.siftUp(this.heap.length - 1), !0);
172
201
  }
@@ -177,21 +206,21 @@ class $ extends x {
177
206
  return this.heap[0] = this.heap.pop(), this.siftDown(0), t;
178
207
  }
179
208
  siftUp(t) {
180
- let e = t, s = x.getLeftIndex(e), r = x.getRightIndex(e), i = this.size();
181
- 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 && (x.swap(this.heap, t, e), this.siftUp(e));
209
+ let e = t, s = E.getLeftIndex(e), r = E.getRightIndex(e), i = this.size();
210
+ 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));
182
211
  }
183
212
  siftDown(t) {
184
- let e = x.getParentIndex(t);
213
+ let e = E.getParentIndex(t);
185
214
  for (; t > 0 && e && this.compareFn(this.heap[e], this.heap[t]) === 1; )
186
- x.swap(this.heap, e, t), t = e, e = x.getParentIndex(t);
215
+ E.swap(this.heap, e, t), t = e, e = E.getParentIndex(t);
187
216
  }
188
217
  }
189
- class F extends $ {
190
- constructor(t = (e, s) => N(s, e)) {
218
+ class G extends D {
219
+ constructor(t = (e, s) => C(s, e)) {
191
220
  super(t);
192
221
  }
193
222
  }
194
- function D(h) {
223
+ function U(h) {
195
224
  return { value: h };
196
225
  }
197
226
  class B {
@@ -224,7 +253,7 @@ class B {
224
253
  }
225
254
  update(t, e) {
226
255
  let s = this.lookup.get(t);
227
- s ? (this.detach(s), this.prepend(s), s.value = e) : (s = D(e), this.length++, this.prepend(s), this.trimCache(), this.lookup.set(t, s), this.reverseLookup);
256
+ 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);
228
257
  }
229
258
  }
230
259
  class b {
@@ -232,7 +261,7 @@ class b {
232
261
  this.value = t, this.next = e, this.prev = s;
233
262
  }
234
263
  }
235
- class G {
264
+ class X {
236
265
  count = 0;
237
266
  head = null;
238
267
  tail = null;
@@ -293,32 +322,65 @@ class G {
293
322
  throw new Error(`Index out of bounds: ${e}`);
294
323
  const s = new b(t);
295
324
  if (e === 0)
296
- s.next = this.head, this.head = s, this.count === 0 && (this.tail = s);
325
+ s.next = this.head, this.head && (this.head.prev = s), this.head = s, this.count === 0 && (this.tail = s);
297
326
  else if (e === this.count)
298
- this.tail && (this.tail.next = s, this.tail = s);
327
+ s.prev = this.tail, this.tail && (this.tail.next = s), this.tail = s;
299
328
  else {
300
- const r = this.getElementAt(e - 1);
301
- r && (s.next = r.next, r.next = s);
329
+ let r;
330
+ if (e < this.count / 2) {
331
+ r = this.head;
332
+ for (let i = 0; i < e - 1 && r; i++)
333
+ r = r.next;
334
+ } else {
335
+ r = this.tail;
336
+ for (let i = this.count - 1; i > e - 1 && r; i--)
337
+ r = r.prev;
338
+ }
339
+ if (r) {
340
+ const i = r.next;
341
+ s.prev = r, s.next = i, r.next = s, i && (i.prev = s);
342
+ }
302
343
  }
303
344
  return this.count++, !0;
304
345
  }
305
346
  push(t) {
306
347
  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++;
348
+ this.head ? this.tail && (this.tail.next = e, e.prev = this.tail, this.tail = e) : (this.head = e, this.tail = e), this.count++;
308
349
  }
309
350
  remove(t) {
310
- const e = this.indexOf(t);
311
- return e === -1 ? null : this.removeAt(e);
351
+ let e = this.head, s = this.tail, r = 0, i = this.count - 1;
352
+ for (; e && s; ) {
353
+ if (this.equals(e.value, t))
354
+ return this.removeAt(r);
355
+ if (this.equals(s.value, t))
356
+ return this.removeAt(i);
357
+ if (e = e.next, s = s.prev, r++, i--, r > i)
358
+ break;
359
+ }
360
+ return null;
312
361
  }
313
362
  removeAt(t) {
314
363
  if (t < 0 || t >= this.count)
315
364
  return null;
316
- let e = this.head;
365
+ let e;
317
366
  if (t === 0)
318
- this.head = e?.next || null, this.count === 1 && (this.tail = null);
367
+ e = this.head, e && (this.head = e.next, this.head && (this.head.prev = null), this.count === 1 && (this.tail = null));
368
+ else if (t === this.count - 1)
369
+ e = this.tail, e && (this.tail = e.prev, this.tail && (this.tail.next = null), this.count === 1 && (this.head = null));
319
370
  else {
320
- const s = this.getElementAt(t - 1);
321
- s && (e = s.next, s.next = e?.next || null, t === this.count - 1 && (this.tail = s));
371
+ if (t < this.count / 2) {
372
+ e = this.head;
373
+ for (let s = 0; s < t && e; s++)
374
+ e = e.next;
375
+ } else {
376
+ e = this.tail;
377
+ for (let s = this.count - 1; s > t && e; s--)
378
+ e = e.prev;
379
+ }
380
+ if (e) {
381
+ const s = e.prev, r = e.next;
382
+ s && (s.next = r), r && (r.prev = s);
383
+ }
322
384
  }
323
385
  return this.count--, e?.value || null;
324
386
  }
@@ -347,17 +409,17 @@ class G {
347
409
  return t;
348
410
  }
349
411
  }
350
- class T {
412
+ class H {
351
413
  key;
352
414
  value;
353
415
  constructor(t, e) {
354
416
  this.key = t, this.value = e;
355
417
  }
356
418
  }
357
- function R(h, t = { emptyString: !1, zeroNumber: !1 }) {
419
+ function k(h, t = { emptyString: !1, zeroNumber: !1 }) {
358
420
  return h == null ? !(t.emptyString && h === "" || t.zeroNumber && h === 0) : !1;
359
421
  }
360
- class H {
422
+ class q {
361
423
  table = [];
362
424
  constructor() {
363
425
  }
@@ -368,15 +430,15 @@ class H {
368
430
  return -1;
369
431
  }
370
432
  set(t, e) {
371
- if (R(t))
433
+ if (k(t))
372
434
  throw new Error("key is required");
373
- if (R(e))
435
+ if (k(e))
374
436
  throw new Error("value is required");
375
437
  if (this.has(t)) {
376
438
  let s = this.getItemIndex(t);
377
439
  this.table[s].value = e;
378
440
  } else {
379
- const s = new T(t, e);
441
+ const s = new H(t, e);
380
442
  this.table.push(s);
381
443
  }
382
444
  }
@@ -427,12 +489,12 @@ class H {
427
489
  return t = t.slice(0, -1), t;
428
490
  }
429
491
  }
430
- class W {
492
+ class j {
431
493
  isDirected;
432
494
  vertices;
433
495
  adjList;
434
496
  constructor(t = !1) {
435
- this.isDirected = t, this.vertices = [], this.adjList = new H();
497
+ this.isDirected = t, this.vertices = [], this.adjList = new q();
436
498
  }
437
499
  addVertex(t) {
438
500
  this.vertices.includes(t) || (this.vertices.push(t), this.adjList.set(t, []));
@@ -623,12 +685,12 @@ class g {
623
685
  }
624
686
  static getIntersection(t, e, s = g.EPSILON) {
625
687
  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, d = e.p1.y, f = e.p2.x, c = e.p2.y, l = (r - n) * (d - c) - (i - a) * (o - f);
688
+ 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
689
  if (Math.abs(l) < s) return null;
628
- const m = ((r - o) * (d - c) - (i - d) * (o - f)) / l, v = -((r - n) * (i - d) - (i - a) * (r - o)) / l;
629
- if (m >= 0 && m <= 1 && v >= 0 && v <= 1) {
630
- const C = r + m * (n - r), z = i + m * (a - i);
631
- return new u(C, z);
690
+ const m = ((r - o) * (f - c) - (i - f) * (o - d)) / l, M = -((r - n) * (i - f) - (i - a) * (r - o)) / l;
691
+ if (m >= 0 && m <= 1 && M >= 0 && M <= 1) {
692
+ const z = r + m * (n - r), $ = i + m * (a - i);
693
+ return new u(z, $);
632
694
  }
633
695
  return null;
634
696
  }
@@ -636,13 +698,13 @@ class g {
636
698
  return g.getIntersection(t, e) !== null;
637
699
  }
638
700
  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, d = n * n + a * a;
640
- let f = -1;
641
- d > s && (f = o / d);
701
+ const r = e.x - t.p1.x, i = e.y - t.p1.y, n = t.p2.x - t.p1.x, a = t.p2.y - t.p1.y, o = r * n + i * a, f = n * n + a * a;
702
+ let d = -1;
703
+ f > s && (d = o / f);
642
704
  let c, l;
643
- f < 0 ? (c = t.p1.x, l = t.p1.y) : f > 1 ? (c = t.p2.x, l = t.p2.y) : (c = t.p1.x + f * n, l = t.p1.y + f * a);
644
- const m = e.x - c, v = e.y - l;
645
- return Math.hypot(m + v);
705
+ 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);
706
+ const m = e.x - c, M = e.y - l;
707
+ return Math.hypot(m + M);
646
708
  }
647
709
  p1;
648
710
  p2;
@@ -677,14 +739,14 @@ class g {
677
739
  return this.p2;
678
740
  }
679
741
  }
680
- class k {
742
+ class N {
681
743
  static EPSILON = 1e-10;
682
744
  name;
683
745
  constructor(t) {
684
746
  this.name = t;
685
747
  }
686
748
  }
687
- class p extends k {
749
+ class p extends N {
688
750
  static isValid(t, e, s) {
689
751
  return t <= 0 || e <= 0 || s <= 0 ? !1 : t + e > s && t + s > e && e + s > t;
690
752
  }
@@ -697,7 +759,7 @@ class p extends k {
697
759
  static getType(t, e, s) {
698
760
  if (!p.isValid(t, e, s))
699
761
  throw new Error("Invalid triangle sides");
700
- const r = [t, e, s].sort((o, d) => o - d), [i, n, a] = r;
762
+ const r = [t, e, s].sort((o, f) => o - f), [i, n, a] = r;
701
763
  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
764
  }
703
765
  static getAngles(t, e, s) {
@@ -717,7 +779,7 @@ class p extends k {
717
779
  areCollinear() {
718
780
  return Math.abs(
719
781
  (this.p2.x - this.p1.x) * (this.p3.y - this.p1.y) - (this.p3.x - this.p1.x) * (this.p2.y - this.p1.y)
720
- ) < k.EPSILON;
782
+ ) < N.EPSILON;
721
783
  }
722
784
  get side() {
723
785
  return [
@@ -775,7 +837,7 @@ class p extends k {
775
837
  return Math.abs(e + s + r - this.area()) < p.EPSILON;
776
838
  }
777
839
  }
778
- class X {
840
+ class W {
779
841
  static sleep(t) {
780
842
  return new Promise((e) => setTimeout(e, t));
781
843
  }
@@ -799,7 +861,7 @@ class X {
799
861
  return t.prototype.constructor = s, s;
800
862
  }
801
863
  }
802
- class j {
864
+ class Q {
803
865
  static groupBy(t, e) {
804
866
  if (!e)
805
867
  throw new Error("generateKey is required");
@@ -848,7 +910,7 @@ class j {
848
910
  function O(h) {
849
911
  return h !== null && (typeof h == "object" || typeof h == "function");
850
912
  }
851
- class Q {
913
+ class J {
852
914
  map = /* @__PURE__ */ new Map();
853
915
  weakMap = /* @__PURE__ */ new WeakMap();
854
916
  set(t, e) {
@@ -861,7 +923,7 @@ class Q {
861
923
  return O(t) ? this.weakMap.has(t) : this.map.has(t);
862
924
  }
863
925
  }
864
- class J {
926
+ class Z {
865
927
  static jsonClone(t) {
866
928
  try {
867
929
  return JSON.parse(JSON.stringify(t));
@@ -931,41 +993,41 @@ class J {
931
993
  return r;
932
994
  }
933
995
  }
934
- const P = {
996
+ const L = {
935
997
  date: "yyyy-MM-dd",
936
998
  datetime: "yyyy-MM-dd HH:mm:ss",
937
999
  time: "HH:mm:ss",
938
1000
  iso: "yyyy-MM-ddTHH:mm:ss.SSS"
939
1001
  };
940
- class M {
1002
+ class S {
941
1003
  static defaultOptions = {
942
1004
  paddingZero: !1,
943
1005
  locale: "en-US"
944
1006
  };
945
1007
  static setDefaultOptions(t) {
946
- M.defaultOptions = { ...M.defaultOptions, ...t };
1008
+ S.defaultOptions = { ...S.defaultOptions, ...t };
947
1009
  }
948
1010
  static format(t, e, s = {}) {
949
- const r = { ...M.defaultOptions, ...s }, i = M.getDateInfo(t, r);
950
- return M.normalizeFormatter(e)(i);
1011
+ const r = { ...S.defaultOptions, ...s }, i = S.getDateInfo(t, r);
1012
+ return S.normalizeFormatter(e)(i);
951
1013
  }
952
1014
  // 获取日期信息
953
1015
  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(), d = t.getSeconds(), f = t.getMilliseconds();
1016
+ 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
1017
  return {
956
1018
  year: r,
957
1019
  month: i,
958
1020
  day: n,
959
1021
  hour: a,
960
1022
  minute: o,
961
- second: d,
962
- millisecond: f,
1023
+ second: f,
1024
+ millisecond: d,
963
1025
  yyyy: s(r, 4),
964
1026
  MM: s(i),
965
1027
  dd: s(n),
966
1028
  HH: s(a),
967
1029
  mm: s(o),
968
- ss: s(d)
1030
+ ss: s(f)
969
1031
  };
970
1032
  }
971
1033
  static normalizeFormatter(t) {
@@ -973,7 +1035,7 @@ class M {
973
1035
  return t;
974
1036
  if (typeof t != "string")
975
1037
  throw new Error("Formatter must be a string or function");
976
- t in P && (t = P[t]);
1038
+ t in L && (t = L[t]);
977
1039
  const e = {
978
1040
  yyyy: "yyyy",
979
1041
  MM: "MM",
@@ -998,7 +1060,7 @@ class M {
998
1060
  return o > 0 ? s > 0 ? `${o}天后` : `${o}天前` : a > 0 ? s > 0 ? `${a}小时后` : `${a}小时前` : n > 0 ? s > 0 ? `${n}分钟后` : `${n}分钟前` : s > 0 ? "刚刚" : "";
999
1061
  }
1000
1062
  }
1001
- class L {
1063
+ class T {
1002
1064
  lights;
1003
1065
  currentIndex;
1004
1066
  switchTime;
@@ -1008,7 +1070,7 @@ class L {
1008
1070
  { color: "green", latest: 10 },
1009
1071
  { color: "yellow", latest: 3 }
1010
1072
  ];
1011
- constructor(t = L.DEFAULT_LIGHTS) {
1073
+ constructor(t = T.DEFAULT_LIGHTS) {
1012
1074
  this.lights = t, this.currentIndex = 0, this.switchTime = Date.now();
1013
1075
  }
1014
1076
  render(t) {
@@ -1033,12 +1095,12 @@ class L {
1033
1095
  };
1034
1096
  }
1035
1097
  }
1036
- class Z {
1098
+ class Y {
1037
1099
  static escape(t) {
1038
1100
  return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1039
1101
  }
1040
1102
  }
1041
- class Y {
1103
+ class K {
1042
1104
  static ROMAN_MAP = /* @__PURE__ */ new Map([
1043
1105
  ["M", 1e3],
1044
1106
  ["CM", 900],
@@ -1156,13 +1218,13 @@ class y {
1156
1218
  if (s === 0)
1157
1219
  return t.map(() => "0%");
1158
1220
  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 d = a.reduce((c, l) => c + l, 0), f = i - d;
1160
- for (; f > 0; ) {
1221
+ let f = a.reduce((c, l) => c + l, 0), d = i - f;
1222
+ for (; d > 0; ) {
1161
1223
  let c = -1, l = -1;
1162
1224
  for (let m = 0; m < o.length; m++)
1163
1225
  o[m] > l && (l = o[m], c = m);
1164
1226
  if (c === -1) break;
1165
- a[c]++, o[c] = 0, f--;
1227
+ a[c]++, o[c] = 0, d--;
1166
1228
  }
1167
1229
  return a.map((c) => `${(c / i * 100).toFixed(e)}%`);
1168
1230
  }
@@ -1257,7 +1319,7 @@ class y {
1257
1319
  return (t - e[0]) * ((s[1] - s[0]) / r) + s[0];
1258
1320
  }
1259
1321
  }
1260
- class K {
1322
+ class tt {
1261
1323
  static READ = 1;
1262
1324
  static WRITE = 2;
1263
1325
  static SHARE = 4;
@@ -1276,7 +1338,7 @@ class K {
1276
1338
  return t ^ e;
1277
1339
  }
1278
1340
  }
1279
- class S {
1341
+ class v {
1280
1342
  static frequencyStatistics(t) {
1281
1343
  return [...t].reduce(
1282
1344
  (e, s) => (e[s] = (e[s] || 0) + 1, e),
@@ -1345,7 +1407,7 @@ class S {
1345
1407
  return e;
1346
1408
  }
1347
1409
  static pointAt(t, e) {
1348
- if (e >= S.pointLength(t)) return;
1410
+ if (e >= v.pointLength(t)) return;
1349
1411
  let s = 0;
1350
1412
  for (let r = 0, i = t.length; r < i; ) {
1351
1413
  const n = t.codePointAt(r);
@@ -1355,10 +1417,10 @@ class S {
1355
1417
  r += n > 65535 ? 2 : 1, s++;
1356
1418
  }
1357
1419
  }
1358
- static sliceByPoint(t, e, s = S.pointLength(t)) {
1420
+ static sliceByPoint(t, e, s = v.pointLength(t)) {
1359
1421
  let r = "";
1360
1422
  for (let i = e; i < s; i++)
1361
- r += S.pointAt(t, i);
1423
+ r += v.pointAt(t, i);
1362
1424
  return r;
1363
1425
  }
1364
1426
  static capitalize(t) {
@@ -1371,7 +1433,7 @@ class S {
1371
1433
  return t.length <= e ? this : t.slice(0, e - s.length) + s;
1372
1434
  }
1373
1435
  static isPalindrome(t) {
1374
- return t.toLowerCase().replace(/[^a-z0-9]/g, "") === S.reverse(t);
1436
+ return t.toLowerCase().replace(/[^a-z0-9]/g, "") === v.reverse(t);
1375
1437
  }
1376
1438
  static count(t, e) {
1377
1439
  const s = e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -1384,7 +1446,7 @@ class S {
1384
1446
  return t.replace(/[A-Z]/g, (e) => `_${e.toLowerCase()}`);
1385
1447
  }
1386
1448
  }
1387
- class _ {
1449
+ class et {
1388
1450
  static isValidHex(t) {
1389
1451
  return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t);
1390
1452
  }
@@ -1392,7 +1454,7 @@ class _ {
1392
1454
  return /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.test(t);
1393
1455
  }
1394
1456
  }
1395
- const E = {
1457
+ const x = {
1396
1458
  AUTH_UNAUTHORIZED: "未授权事件",
1397
1459
  AUTH_LOGIN_SUCCESS: "登录成功事件",
1398
1460
  AUTH_LOGOUT: "注销事件",
@@ -1409,7 +1471,7 @@ class A {
1409
1471
  listeners = {};
1410
1472
  debugMode;
1411
1473
  constructor(t = !1) {
1412
- this.debugMode = t, Object.keys(E).forEach(
1474
+ this.debugMode = t, Object.keys(x).forEach(
1413
1475
  (e) => {
1414
1476
  this.listeners[e] = /* @__PURE__ */ new Set();
1415
1477
  }
@@ -1419,22 +1481,22 @@ class A {
1419
1481
  return A.instance || (A.instance = new A(t)), A.instance;
1420
1482
  }
1421
1483
  on(t, e) {
1422
- this.debugLog(`添加事件监听: ${E[t]}`), this.listeners[t].add(e);
1484
+ this.debugLog(`添加事件监听: ${x[t]}`), this.listeners[t].add(e);
1423
1485
  }
1424
1486
  emit(t, e) {
1425
- this.debugLog(`触发事件: ${E[t]}`, e), this.listeners[t].forEach((s) => {
1487
+ this.debugLog(`触发事件: ${x[t]}`, e), this.listeners[t].forEach((s) => {
1426
1488
  try {
1427
1489
  s(e);
1428
1490
  } catch (r) {
1429
- console.error(`事件 ${E[t]} 处理出错:`, r);
1491
+ console.error(`事件 ${x[t]} 处理出错:`, r);
1430
1492
  }
1431
1493
  });
1432
1494
  }
1433
1495
  off(t, e) {
1434
- this.debugLog(`移除事件监听: ${E[t]}`), this.listeners[t].delete(e);
1496
+ this.debugLog(`移除事件监听: ${x[t]}`), this.listeners[t].delete(e);
1435
1497
  }
1436
1498
  once(t, e) {
1437
- this.debugLog(`添加一次性事件监听: ${E[t]}`);
1499
+ this.debugLog(`添加一次性事件监听: ${x[t]}`);
1438
1500
  const s = (r) => {
1439
1501
  e(r), this.off(t, s);
1440
1502
  };
@@ -1450,32 +1512,163 @@ class A {
1450
1512
  this.debugMode && console.log(`[EventEmitter] ${t}`, e || "");
1451
1513
  }
1452
1514
  }
1515
+ class P {
1516
+ //#region private static members
1517
+ static OPERATORS = /* @__PURE__ */ new Set(["+", "-", "*", "/"]);
1518
+ static VALID_CHARS_REG = /^[0-9+\-*/().\s]+$/;
1519
+ static PRIORITY_MAP = /* @__PURE__ */ new Map([
1520
+ ["+", 1],
1521
+ ["-", 1],
1522
+ ["*", 2],
1523
+ ["/", 2],
1524
+ ["(", 0],
1525
+ [")", 0]
1526
+ ]);
1527
+ static getPriority(t) {
1528
+ return this.PRIORITY_MAP.get(t) ?? 0;
1529
+ }
1530
+ static validateExpression(t) {
1531
+ if (!t)
1532
+ throw new Error("Expression cannot be empty");
1533
+ if (!this.VALID_CHARS_REG.test(t))
1534
+ throw new Error("Expression contains invalid characters");
1535
+ }
1536
+ static processClosingParenthesis(t, e) {
1537
+ for (; !t.isEmpty(); ) {
1538
+ if (t.peek() === "(") {
1539
+ t.pop();
1540
+ break;
1541
+ }
1542
+ const r = t.pop();
1543
+ r && e.push(r);
1544
+ }
1545
+ }
1546
+ static processOperator(t, e, s) {
1547
+ for (; !e.isEmpty(); ) {
1548
+ const r = e.peek();
1549
+ if (!r || r === "(") break;
1550
+ if (this.getPriority(t) <= this.getPriority(r)) {
1551
+ const i = e.pop();
1552
+ i && s.push(i);
1553
+ } else
1554
+ break;
1555
+ }
1556
+ e.push(t);
1557
+ }
1558
+ static applyOperator(t, e, s) {
1559
+ switch (s) {
1560
+ case "+":
1561
+ return t + e;
1562
+ case "-":
1563
+ return t - e;
1564
+ case "*":
1565
+ return t * e;
1566
+ case "/":
1567
+ if (e === 0)
1568
+ throw new Error("Division by zero");
1569
+ return t / e;
1570
+ default:
1571
+ throw new Error("Invalid operator");
1572
+ }
1573
+ }
1574
+ //#endregion
1575
+ static FLOAT_NUM_REG = /^-?\d*\.?\d+$/;
1576
+ static EXPRESSION_REG = new RegExp("(?<!\\d)-?\\d*\\.?\\d+|[+\\-*/()]", "g");
1577
+ static toArr(t) {
1578
+ this.validateExpression(t);
1579
+ const e = t.match(P.EXPRESSION_REG);
1580
+ if (!e)
1581
+ throw new Error("Invalid expression format");
1582
+ return e.filter((s) => s.trim() !== "").map((s) => {
1583
+ if (this.FLOAT_NUM_REG.test(s) || this.OPERATORS.has(s) || s === "(" || s === ")")
1584
+ return s;
1585
+ throw new Error(`Invalid token: ${s}`);
1586
+ });
1587
+ }
1588
+ static infixToPostfix(t) {
1589
+ if (!t?.trim())
1590
+ throw new Error("Expression cannot be empty");
1591
+ const e = new R(), s = this.toArr(t);
1592
+ console.log(s);
1593
+ const r = [];
1594
+ for (const i of s)
1595
+ this.FLOAT_NUM_REG.test(i) ? r.push(i) : i === "(" ? e.push(i) : i === ")" ? this.processClosingParenthesis(e, r) : this.OPERATORS.has(i) && this.processOperator(i, e, r);
1596
+ for (; !e.isEmpty(); ) {
1597
+ const i = e.pop();
1598
+ i && i !== "(" && r.push(i);
1599
+ }
1600
+ return {
1601
+ postfix: r.join(" "),
1602
+ postfixArr: r
1603
+ };
1604
+ }
1605
+ static evaluatePostfix(t) {
1606
+ if (!t.length)
1607
+ throw new Error("Postfix expression cannot be empty");
1608
+ typeof t == "string" && (t = P.toArr(t));
1609
+ const e = new R();
1610
+ for (const s of t)
1611
+ if (this.FLOAT_NUM_REG.test(s))
1612
+ e.push(parseFloat(s));
1613
+ else if (this.OPERATORS.has(s)) {
1614
+ const r = e.pop(), i = e.pop();
1615
+ if (i === void 0 || r === void 0)
1616
+ throw new Error("Invalid postfix expression");
1617
+ e.push(this.applyOperator(i, r, s));
1618
+ }
1619
+ return e.pop() ?? 0;
1620
+ }
1621
+ }
1622
+ class st {
1623
+ static isMatchingPair(t, e) {
1624
+ return t === "(" && e === ")" || t === "{" && e === "}" || t === "[" && e === "]";
1625
+ }
1626
+ static isvalidBrackets(t) {
1627
+ const e = new R();
1628
+ for (let s = 0, r = t.length; s < r; s++) {
1629
+ const i = t[s];
1630
+ if (["{", "[", "("].includes(i))
1631
+ e.push(i);
1632
+ else if (["}", "]", ")"].includes(i)) {
1633
+ if (e.isEmpty())
1634
+ return !1;
1635
+ const n = e.pop();
1636
+ if (!n || !this.isMatchingPair(n, i))
1637
+ return !1;
1638
+ }
1639
+ }
1640
+ return e.isEmpty();
1641
+ }
1642
+ }
1453
1643
  export {
1454
- j as Arr,
1455
- K as BitPerm,
1456
- _ as Color,
1457
- M as DateEx,
1458
- H as Dictionary,
1644
+ Q as Arr,
1645
+ R as ArrStack,
1646
+ tt as BitPerm,
1647
+ et as Color,
1648
+ S as DateEx,
1649
+ q as Dictionary,
1459
1650
  A as Emitter,
1460
- X as Func,
1461
- W as Graph,
1651
+ P as Expression,
1652
+ W as Func,
1653
+ j as Graph,
1462
1654
  B as LRU,
1463
1655
  g as Line,
1464
- G as LinkedList,
1656
+ X as LinkedList,
1465
1657
  I as Matrix,
1466
- F as MaxHeap,
1467
- Q as MemoizeMap,
1468
- $ as MinHeap,
1469
- V as MinStack,
1658
+ G as MaxHeap,
1659
+ J as MemoizeMap,
1660
+ D as MinHeap,
1661
+ _ as MinStack,
1470
1662
  y as Num,
1471
- J as Obj,
1663
+ Z as Obj,
1472
1664
  u as Point,
1473
- q as Queue,
1474
- Z as Reg,
1475
- Y as Roman,
1476
- U as Stack,
1477
- S as Str,
1478
- L as TrafficLight,
1665
+ V as Queue,
1666
+ Y as Reg,
1667
+ K as Roman,
1668
+ F as Stack,
1669
+ st as StackApplication,
1670
+ v as Str,
1671
+ T as TrafficLight,
1479
1672
  p as Triangle,
1480
1673
  w as Vector
1481
1674
  };
@@ -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 I{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 I{insert(t){return t?!1:(this.heap.push(t),this.siftUp(this.heap.length-1),!0)}extract(){if(this.isEmpty())return;if(this.heap.length===1)return this.heap.shift();const t=this.heap[0];return this.heap[0]=this.heap.pop(),this.siftDown(0),t}siftUp(t){let e=t,s=I.getLeftIndex(e),r=I.getRightIndex(e),i=this.size();s<i&&this.compareFn(this.heap[e],this.heap[s])===-1&&(e=s),r<i&&this.compareFn(this.heap[e],this.heap[r])===1&&(e=r),e!==t&&(I.swap(this.heap,t,e),this.siftUp(e))}siftDown(t){let e=I.getParentIndex(t);for(;t>0&&e&&this.compareFn(this.heap[e],this.heap[t])===1;)I.swap(this.heap,e,t),t=e,e=I.getParentIndex(t)}}class U extends L{constructor(t=(e,s)=>P(s,e)){super(t)}}function V(h){return{value:h}}class q{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=V(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=s,this.count===0&&(this.tail=s);else if(e===this.count)this.tail&&(this.tail.next=s,this.tail=s);else{const r=this.getElementAt(e-1);r&&(s.next=r.next,r.next=s)}return this.count++,!0}push(t){const e=new N(t);this.head?this.tail&&(this.tail.next=e,this.tail=e):(this.head=e,this.tail=e),this.count++}remove(t){const e=this.indexOf(t);return e===-1?null:this.removeAt(e)}removeAt(t){if(t<0||t>=this.count)return null;let e=this.head;if(t===0)this.head=e?.next||null,this.count===1&&(this.tail=null);else{const s=this.getElementAt(t-1);s&&(e=s.next,s.next=e?.next||null,t===this.count-1&&(this.tail=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 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={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&apos;"," ":"&nbsp;","±":"&plusmn;","×":"&times;","÷":"&divide;","≠":"&ne;","≤":"&le;","≥":"&ge;"},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 U{items={};count=0;constructor(){}pop(){if(this.isEmpty())return;this.count--;const t=this.items[this.count];return delete this.items[this.count],t}push(...t){if(t.length===0)return this;if(t.length===1){const e=t[0];return Array.isArray(e)?this.addItems(e):this.addItem(e)}for(const e of t)Array.isArray(e)?this.addItems(e):this.addItem(e);return this}addItem(t){if(!this.isValidItem(t))throw new Error("Invalid item: item cannot be null or undefined");return this.items[this.count]=t,this.count++,this}addItems(t){return t.filter(s=>this.isValidItem(s)).forEach(s=>{this.items[this.count]=s,this.count++}),this}isValidItem(t){return t!=null}peek(){return this.isEmpty()?void 0:this.items[this.count-1]}isEmpty(){return this.count===0}size(){return this.count}clear(){this.items={},this.count=0}toString(){return this.isEmpty()?"":`Stack(count: ${this.count}):[${this.items[this.count-1]},...rest]`}}class V{stack=[];minStack=[];push(t){this.stack.push(t),(this.minStack.length===0||t<=this.minStack[this.minStack.length-1])&&this.minStack.push(t)}pop(){const t=this.stack.pop();return t===this.minStack[this.minStack.length-1]&&this.minStack.pop(),t}peek(){return this.stack[this.stack.length-1]}getMin(){return this.minStack[this.minStack.length-1]}isEmpty(){return this.size()===0}size(){return this.stack.length}clear(){this.stack=[],this.minStack=[]}toString(){return this.isEmpty()?"":`MinStack(count: ${this.size()}):[${this.getMin()},...rest]`}}class R{_arr;constructor(){this._arr=[]}isEmpty(){return this._arr.length===0}clear(){this._arr=[]}size(){return this._arr.length}toString(){return this.isEmpty()?"Stack: (0) []":`Stack: (${this.size()}) [${this.peek()}, ...]`}pop(){return this._arr.pop()}push(...t){for(const e of t)Array.isArray(e)?this._arr.push(...e):this._arr.push(e);return this}peek(){return this._arr[this._arr.length-1]}}function N(h,t){return h===t?0:h<t?-1:1}class I{heap=[];compareFn;constructor(t=N){this.compareFn=t}static getLeftIndex(t){return 2*t+1}static getRightIndex(t){return 2*t+2}static getParentIndex(t){return t===0?void 0:Math.floor((t-1)/2)}static swap(t,e,s){[t[e],t[s]]=[t[s],t[e]]}find(){return this.isEmpty()?void 0:this.heap[0]}size(){return this.heap.length}isEmpty(){return this.size()===0}clear(){this.heap=[]}toString(){return this.heap.toString()}}class C extends I{insert(t){return t?!1:(this.heap.push(t),this.siftUp(this.heap.length-1),!0)}extract(){if(this.isEmpty())return;if(this.heap.length===1)return this.heap.shift();const t=this.heap[0];return this.heap[0]=this.heap.pop(),this.siftDown(0),t}siftUp(t){let e=t,s=I.getLeftIndex(e),r=I.getRightIndex(e),i=this.size();s<i&&this.compareFn(this.heap[e],this.heap[s])===-1&&(e=s),r<i&&this.compareFn(this.heap[e],this.heap[r])===1&&(e=r),e!==t&&(I.swap(this.heap,t,e),this.siftUp(e))}siftDown(t){let e=I.getParentIndex(t);for(;t>0&&e&&this.compareFn(this.heap[e],this.heap[t])===1;)I.swap(this.heap,e,t),t=e,e=I.getParentIndex(t)}}class q extends C{constructor(t=(e,s)=>N(s,e)){super(t)}}function F(h){return{value:h}}class _{capacity;length=0;head=null;tail=null;lookup=new Map;reverseLookup=new Map;constructor(t=10){this.capacity=t}prepend(t){this.head?(t.next=this.head,this.head.prev=t,this.head=t):this.head=this.tail=t}detach(t){t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),this.head===t&&(this.head=this.head.next||null),this.tail===t&&(this.tail=this.tail.prev||null),t.next=void 0,t.prev=void 0}trimCache(){if(this.length<=this.capacity)return;const t=this.tail;this.detach(t);const e=this.reverseLookup.get(t);this.lookup.delete(e),this.reverseLookup.delete(t),this.length--}get(t){const e=this.lookup.get(t);if(e)return this.detach(e),this.prepend(e),e.value}update(t,e){let s=this.lookup.get(t);s?(this.detach(s),this.prepend(s),s.value=e):(s=F(e),this.length++,this.prepend(s),this.trimCache(),this.lookup.set(t,s),this.reverseLookup)}}class T{constructor(t,e=null,s=null){this.value=t,this.next=e,this.prev=s}}class G{count=0;head=null;tail=null;constructor(t){t&&t.forEach(e=>this.push(e))}[Symbol.iterator](){let t=this.head;return{next(){if(t){const e=t.value;return t=t.next,{value:e,done:!1}}return{value:void 0,done:!0}}}}equals(t,e){if(t===e)return!0;if(t==null||e==null)return!1;if(typeof t=="object"&&typeof e=="object"){if(t.equals&&typeof t.equals=="function")return t.equals(e);const s=Object.keys(t),r=Object.keys(e);return s.length!==r.length?!1:s.every(i=>t[i]===e[i])}return!1}indexOf(t){let e=this.head,s=0;for(;e;){if(this.equals(e.value,t))return s;s++,e=e.next}return-1}getElementAt(t){if(t<0||t>=this.count)return null;if(t>this.count/2){let s=this.tail,r=this.count-1;for(;r>t&&s;)s=s.prev,r--;return s}let e=this.head;for(let s=0;s<t&&e;s++)e=e.next;return e}getValueAt(t){return this.getElementAt(t)?.value}insert(t,e){if(e<0||e>this.count)throw new Error(`Index out of bounds: ${e}`);const s=new T(t);if(e===0)s.next=this.head,this.head&&(this.head.prev=s),this.head=s,this.count===0&&(this.tail=s);else if(e===this.count)s.prev=this.tail,this.tail&&(this.tail.next=s),this.tail=s;else{let r;if(e<this.count/2){r=this.head;for(let i=0;i<e-1&&r;i++)r=r.next}else{r=this.tail;for(let i=this.count-1;i>e-1&&r;i--)r=r.prev}if(r){const i=r.next;s.prev=r,s.next=i,r.next=s,i&&(i.prev=s)}}return this.count++,!0}push(t){const e=new T(t);this.head?this.tail&&(this.tail.next=e,e.prev=this.tail,this.tail=e):(this.head=e,this.tail=e),this.count++}remove(t){let e=this.head,s=this.tail,r=0,i=this.count-1;for(;e&&s;){if(this.equals(e.value,t))return this.removeAt(r);if(this.equals(s.value,t))return this.removeAt(i);if(e=e.next,s=s.prev,r++,i--,r>i)break}return null}removeAt(t){if(t<0||t>=this.count)return null;let e;if(t===0)e=this.head,e&&(this.head=e.next,this.head&&(this.head.prev=null),this.count===1&&(this.tail=null));else if(t===this.count-1)e=this.tail,e&&(this.tail=e.prev,this.tail&&(this.tail.next=null),this.count===1&&(this.head=null));else{if(t<this.count/2){e=this.head;for(let s=0;s<t&&e;s++)e=e.next}else{e=this.tail;for(let s=this.count-1;s>t&&e;s--)e=e.prev}if(e){const s=e.prev,r=e.next;s&&(s.next=r),r&&(r.prev=s)}}return this.count--,e?.value||null}isEmpty(){return this.count===0}size(){return this.count}clear(){this.head=null,this.tail=null,this.count=0}toString(){if(this.isEmpty())return"";let t="",e=this.head;for(;e;)t+=JSON.stringify(e.value),e.next&&(t+=","),e=e.next;return t}toArray(){const t=[];let e=this.head;for(;e;)t.push(e.value),e=e.next;return t}}class B{key;value;constructor(t,e){this.key=t,this.value=e}}function z(h,t={emptyString:!1,zeroNumber:!1}){return h==null?!(t.emptyString&&h===""||t.zeroNumber&&h===0):!1}class ${table=[];constructor(){}getItemIndex(t){for(let e=0,s=this.table.length;e<s;e++)if(this.table[e].key===t)return e;return-1}set(t,e){if(z(t))throw new Error("key is required");if(z(e))throw new Error("value is required");if(this.has(t)){let s=this.getItemIndex(t);this.table[s].value=e}else{const s=new B(t,e);this.table.push(s)}}remove(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table.splice(e,1)[0]}}has(t){return this.getItemIndex(t)!==-1}get(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table[e]}}keys(){return this.table.map(t=>t.key)}values(){return this.table.map(t=>t.value)}keyValues(){return this.table.map(t=>[t.key,t.value])}forEach(t){for(let e=0,s=this.size();e<s;e++){let r=this.table[e];if(!t(r.key,r.value))break}}isEmpty(){return!this.size()}size(){return this.table.length}clear(){this.table=[]}toString(){let t="";for(let e=0,s=this.table.length;e<s;e++)t+=this.table[e].toString(),t+=",";return t=t.slice(0,-1),t}}class j{isDirected;vertices;adjList;constructor(t=!1){this.isDirected=t,this.vertices=[],this.adjList=new $}addVertex(t){this.vertices.includes(t)||(this.vertices.push(t),this.adjList.set(t,[]))}addEdge(t,e){this.adjList.get(t)||this.addVertex(t),this.adjList.get(e)||this.addVertex(e),this.adjList.get(t)?.value.indexOf(e)===-1&&this.adjList.get(t)?.value.push(e),this.isDirected||this.adjList.get(e)?.value.indexOf(t)===-1&&this.adjList.get(e)?.value.push(t)}getVertices(){return this.vertices}getAdjacencyList(){return this.adjList}toString(){let t="";for(let e=0;e<this.vertices.length;e++)t+=this.vertices[e]+"-->",t+=this.adjList.get(this.vertices[e])?.toString()||"",t+=`
2
+ `;return t}}class E{_data;static zero(t){return new E(...Array(t).fill(0))}constructor(...t){this._data=t}get dimension(){return this._data.length}get norm(){return Math.hypot(...this._data)}getItem(t){return this._data[t]}normalize(){const t=this.norm;if(t===0)throw new Error("Cannot normalize a zero vector");const e=this._data.map(s=>s/t);return new E(...e)}add(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to add");const e=this._data.map((s,r)=>s+t._data[r]);return new E(...e)}sub(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to subtract");const e=this._data.map((s,r)=>s-t._data[r]);return new E(...e)}mul(t){return new E(...this._data.map(e=>e*t))}dot(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to dot product");return this._data.reduce((e,s,r)=>e+s*t._data[r],0)}pos(){return this.mul(1)}neg(){return this.mul(-1)}}class S{_matrix;static zero(t,e){return new S(Array.from({length:t},()=>Array.from({length:e},()=>0)))}static rotate(t){const e=t.length;for(let s=0;s<(e+1)/2;s++)for(let r=s;r<e/2;r++){const i=t[e-1-r][s];t[e-1-r][s]=t[e-1-s][e-1-r],t[e-1-s][e-1-r]=t[r][e-1-s],t[r][e-1-s]=t[s][r],t[s][r]=i}return t}constructor(t){this._matrix=t}get shape(){return[this._matrix.length,this._matrix[0].length]}get row(){return this.shape[0]}get col(){return this.shape[1]}get size(){return this.row*this.col}rowVector(t){return new E(...this._matrix[t])}colVector(t){return new E(...this._matrix.map(e=>e[t]))}getItem(t){return this._matrix[t[0]][t[1]]}setItem(t,e){return this._matrix[t[0]][t[1]]=e,this}mul(t){return new S(this._matrix.map(e=>e.map(s=>s*t)))}div(t){return this.mul(1/t)}add(t){if(this.row!==t.row||this.col!==t.col)throw new Error("Matrix dimensions do not match");return new S(this._matrix.map((e,s)=>e.map((r,i)=>r+t.getItem([s,i]))))}sub(t){return this.add(t.neg())}pos(){return this.mul(1)}neg(){return this.mul(-1)}mulVector(t){if(this.col!==t.dimension)throw new Error("Matrix dimensions do not match");return new S(this._matrix.map(e=>e.map((s,r)=>s*t.getItem(r))))}mulMatrix(t){if(this.col!==t.row)throw new Error("Matrix dimensions do not match");const e=S.zero(this.row,t.col);for(let s=0;s<this.row;s++){const r=this.rowVector(s);for(let i=0;i<this.col;i++)e.setItem([s,i],r.dot(t.colVector(i)))}return e}}class l{static distance(t,e){return Math.hypot(e.x-t.x,e.y-t.y)}x;y;constructor(t,e){this.x=t,this.y=e}distanceTo(t){return l.distance(this,t)}}class g{static EPSILON=1e-10;static sloped(t,e=g.EPSILON){const s=t.p2.x-t.p1.x,r=t.p2.y-t.p1.y;return Math.abs(s)<e?Math.abs(r)<e?0:null:r/s}static isParallel(t,e,s=g.EPSILON){const r=g.sloped(t),i=g.sloped(e);return r===null&&i===null?!0:r===null||i===null?!1:Math.abs(r-i)<s}static getIntersection(t,e,s=g.EPSILON){if(g.isParallel(t,e))return null;const r=t.p1.x,i=t.p1.y,n=t.p2.x,a=t.p2.y,c=e.p1.x,d=e.p1.y,m=e.p2.x,u=e.p2.y,p=(r-n)*(d-u)-(i-a)*(c-m);if(Math.abs(p)<s)return null;const y=((r-c)*(d-u)-(i-d)*(c-m))/p,b=-((r-n)*(i-d)-(i-a)*(r-c))/p;if(y>=0&&y<=1&&b>=0&&b<=1){const st=r+y*(n-r),rt=i+y*(a-i);return new l(st,rt)}return null}static isIntersecting(t,e){return g.getIntersection(t,e)!==null}static distanceToPoint(t,e,s=g.EPSILON){const r=e.x-t.p1.x,i=e.y-t.p1.y,n=t.p2.x-t.p1.x,a=t.p2.y-t.p1.y,c=r*n+i*a,d=n*n+a*a;let m=-1;d>s&&(m=c/d);let u,p;m<0?(u=t.p1.x,p=t.p1.y):m>1?(u=t.p2.x,p=t.p2.y):(u=t.p1.x+m*n,p=t.p1.y+m*a);const y=e.x-u,b=e.y-p;return Math.hypot(y+b)}p1;p2;constructor(t,e){this.p1=t,this.p2=e}get length(){const t=this.p2.x-this.p1.x,e=this.p2.y-this.p1.y;return Math.sqrt(t*t+e*e)}get midpoint(){const t=(this.p1.x+this.p2.x)/2,e=(this.p1.y+this.p2.y)/2;return new l(t,e)}get angle(){return Math.atan2(this.p2.y-this.p1.y,this.p2.x-this.p1.x)}containsPoint(t,e=g.EPSILON){const s=(t.x-this.p1.x)*(this.p2.y-this.p1.y)-(t.y-this.p1.y)*(this.p2.x-this.p1.x);return Math.abs(s)>e?!1:(t.x-this.p1.x)*(t.x-this.p2.x)+(t.y-this.p1.y)*(t.y-this.p2.y)<=e}get direction(){const t=this.length;if(t<g.EPSILON)return new l(0,0);const e=(this.p2.x-this.p1.x)/t,s=(this.p2.y-this.p1.y)/t;return new l(e,s)}get start(){return this.p1}get end(){return this.p2}}class D{static EPSILON=1e-10;name;constructor(t){this.name=t}}class f extends D{static isValid(t,e,s){return t<=0||e<=0||s<=0?!1:t+e>s&&t+s>e&&e+s>t}static area(t,e,s){if(!f.isValid(t,e,s))throw new Error("Invalid triangle");const r=(t+e+s)/2;return Math.sqrt(r*(r-t)*(r-e)*(r-s))}static getType(t,e,s){if(!f.isValid(t,e,s))throw new Error("Invalid triangle sides");const r=[t,e,s].sort((c,d)=>c-d),[i,n,a]=r;return Math.abs(i-n)<f.EPSILON&&Math.abs(n-a)<f.EPSILON?"equilateral":Math.abs(i-n)<f.EPSILON||Math.abs(n-a)<f.EPSILON?"isosceles":"scalene"}static getAngles(t,e,s){if(!f.isValid(t,e,s))throw new Error("Invalid triangle sides");const r=Math.acos((e*e+s*s-t*t)/(2*e*s)),i=Math.acos((t*t+s*s-e*e)/(2*t*s)),n=Math.PI-r-i;return[r,i,n]}p1;p2;p3;constructor(t,e,s,r="triangle"){if(super(r),this.p1=t,this.p2=e,this.p3=s,this.areCollinear())throw new Error("Points are collinear, cannot form a triangle")}areCollinear(){return Math.abs((this.p2.x-this.p1.x)*(this.p3.y-this.p1.y)-(this.p3.x-this.p1.x)*(this.p2.y-this.p1.y))<D.EPSILON}get side(){return[l.distance(this.p1,this.p2),l.distance(this.p2,this.p3),l.distance(this.p3,this.p1)]}perimeter(){return f.isValid(this.side[0],this.side[1],this.side[2]),this.side.reduce((t,e)=>t+e,0)}area(){const[t,e,s]=this.side;return f.area(t,e,s)}get type(){const[t,e,s]=this.side;return f.getType(t,e,s)}get angles(){const[t,e,s]=this.side;return f.getAngles(t,e,s)}get centroid(){return new l((this.p1.x+this.p2.x+this.p3.x)/3,(this.p1.y+this.p2.y+this.p3.y)/3)}get incenter(){const[t,e,s]=this.side,r=this.perimeter()/2,i=(t*this.p1.x+e*this.p2.x+s*this.p3.x)/r,n=(t*this.p1.y+e*this.p2.y+s*this.p3.y)/r;return new l(i,n)}get circumcenter(){const t=2*(this.p1.x*(this.p2.y-this.p3.y)+this.p2.x*(this.p3.y-this.p1.y)+this.p3.x*(this.p1.y-this.p2.y));if(Math.abs(t)<f.EPSILON)throw new Error("Cannot calculate circumcenter for collinear points");const e=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p2.y-this.p3.y)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p3.y-this.p1.y)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p1.y-this.p2.y))/t,s=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p3.x-this.p2.x)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p1.x-this.p3.x)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p2.x-this.p1.x))/t;return new l(e,s)}containsPoint(t){const e=f.area(l.distance(t,this.p1),l.distance(t,this.p2),l.distance(this.p1,this.p2)),s=f.area(l.distance(t,this.p2),l.distance(t,this.p3),l.distance(this.p2,this.p3)),r=f.area(l.distance(t,this.p3),l.distance(t,this.p1),l.distance(this.p3,this.p1));return Math.abs(e+s+r-this.area())<f.EPSILON}}class X{static sleep(t){return new Promise(e=>setTimeout(e,t))}static binarySearchTemplate(t,e,s){let r=-1,i=t.length,n;for(;i-r>1;)n=i-(i-r)>>1,s(t[n],e)?i=n:r=n;return i}static singleton(t){let e;const s=new Proxy(t,{construct(r,i,n){return e||(e=Reflect.construct(r,i,n)),e}});return t.prototype.constructor=s,s}}class W{static groupBy(t,e){if(!e)throw new Error("generateKey is required");const s=typeof e=="string"?i=>i[e]:e,r=new Map;for(const[i,n]of t.entries())try{const a=s(n,i,t);if(a==null){console.warn("Invalid key generated for item:",n);continue}const c=r.get(a)??[];c.push(n),r.set(a,c)}catch(a){console.error("Error generating key for item:",n,a)}return Object.fromEntries(r)}static LIS(t){if(!t.length)return[];const e=[[t[0]]];for(let r=1,i=t.length;r<i;r++){const n=t[r];s(n)}function s(r){for(let i=e.length-1;i>=0;i--){const n=e[i],a=n[e[i].length-1];if(a<r){e[i+1]=[...n,r];break}else a>r&&i===0&&(e[i]=[r])}}return e[e.length-1]}static LCP(t){if(!t.length)return"";let e=t[0];for(let s=1;s<t.length;s++)for(;!t[s].startsWith(e);)if(e=e.slice(0,-1),e==="")return"";return e}}function k(h){return h!==null&&(typeof h=="object"||typeof h=="function")}class Q{map=new Map;weakMap=new WeakMap;set(t,e){k(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return k(t)?this.weakMap.get(t):this.map.get(t)}has(t){return k(t)?this.weakMap.has(t):this.map.has(t)}}class J{static jsonClone(t){try{return JSON.parse(JSON.stringify(t))}catch{throw new Error("Object is not JSON cloneable")}}static structureClone(t){return structuredClone(t)}static deepClone(t,e=new WeakMap){if(t==null||typeof t!="object")return t;if(e.has(t))return e.get(t);if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp)return new RegExp(t.source,t.flags);if(t instanceof Map){const n=new Map;e.set(t,n);for(const[a,c]of t)n.set(this.deepClone(a,e),this.deepClone(c,e));return n}if(t instanceof Set){const n=new Set;e.set(t,n);for(const a of t)n.add(this.deepClone(a,e));return n}if(Array.isArray(t)){const n=new Array(t.length);e.set(t,n);for(let a=0,c=t.length;a<c;a++)n[a]=this.deepClone(t[a],e);return n}if(t instanceof ArrayBuffer)return t.slice(0);const s=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];for(const n of s)if(t instanceof n)return new n(t);if(typeof t=="function")return new Proxy(t,{apply(n,a,c){return n.apply(a,c)},get(n,a){if(a in n)return n[a]}});const r=Object.create(Object.getPrototypeOf(t));e.set(t,r);const i=Object.getOwnPropertyDescriptors(t);for(const[n,a]of Object.entries(i))a.value!==void 0&&(a.value=this.deepClone(a.value,e)),Object.defineProperty(r,n,a);return r}}const H={date:"yyyy-MM-dd",datetime:"yyyy-MM-dd HH:mm:ss",time:"HH:mm:ss",iso:"yyyy-MM-ddTHH:mm:ss.SSS"};class M{static defaultOptions={paddingZero:!1,locale:"en-US"};static setDefaultOptions(t){M.defaultOptions={...M.defaultOptions,...t}}static format(t,e,s={}){const r={...M.defaultOptions,...s},i=M.getDateInfo(t,r);return M.normalizeFormatter(e)(i)}static getDateInfo(t,e){const s=(u,p=2)=>e.paddingZero?u.toString().padStart(p,"0"):u.toString(),r=t.getFullYear(),i=t.getMonth()+1,n=t.getDate(),a=t.getHours(),c=t.getMinutes(),d=t.getSeconds(),m=t.getMilliseconds();return{year:r,month:i,day:n,hour:a,minute:c,second:d,millisecond:m,yyyy:s(r,4),MM:s(i),dd:s(n),HH:s(a),mm:s(c),ss:s(d)}}static normalizeFormatter(t){if(typeof t=="function")return t;if(typeof t!="string")throw new Error("Formatter must be a string or function");t in H&&(t=H[t]);const e={yyyy:"yyyy",MM:"MM",dd:"dd",HH:"HH",mm:"mm",ss:"ss",SSS:"SSS"};return s=>{let r=t;for(const[i,n]of Object.entries(e))r=r.replace(new RegExp(i,"g"),String(s[n]||""));return r}}static formatRelative(t,e=new Date){const s=t.getTime()-e.getTime(),r=Math.abs(s),i=Math.floor(r/1e3),n=Math.floor(i/60),a=Math.floor(n/60),c=Math.floor(a/24);return c>0?s>0?`${c}天后`:`${c}天前`:a>0?s>0?`${a}小时后`:`${a}小时前`:n>0?s>0?`${n}分钟后`:`${n}分钟前`:s>0?"刚刚":""}}class L{lights;currentIndex;switchTime;static DEFAULT_LIGHTS=[{color:"red",latest:7},{color:"yellow",latest:3},{color:"green",latest:10},{color:"yellow",latest:3}];constructor(t=L.DEFAULT_LIGHTS){this.lights=t,this.currentIndex=0,this.switchTime=Date.now()}render(t){requestAnimationFrame(this.render.bind(this,t));const e=this.getCurrentLight();t(e)}get current(){return this.lights[this.currentIndex]}get disTime(){return Date.now()-this.switchTime}update(){for(;!(this.disTime<this.current.latest);)this.switchTime+=this.current.latest*1e3,this.currentIndex=(this.currentIndex+1)%this.lights.length}getCurrentLight(){return this.update(),{color:this.current.color,remain:this.current.latest-this.disTime}}}class Z{static escape(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}}class Y{static ROMAN_MAP=new Map([["M",1e3],["CM",900],["D",500],["CD",400],["C",100],["XC",90],["L",50],["XL",40],["X",10],["IX",9],["V",5],["IV",4],["I",1]]);static toInteger(t){if(t.length===0)throw new Error("Input cannot be empty");const e=new Set(["I","V","X","L","C","D","M"]);for(const n of t)if(!e.has(n))throw new Error(`Invalid Roman numeral character: ${n}`);let s=0,r=0;for(;r<t.length;){const n=t.slice(r,r+2);if(this.ROMAN_MAP.has(n))s+=this.ROMAN_MAP.get(n),r+=2;else{const a=t[r],c=this.ROMAN_MAP.get(a);if(!c)throw new Error(`Invalid Roman numeral sequence at position ${r}`);s+=c,r+=1}}if(this.toRoman(s)!==t)throw new Error("Invalid Roman numeral sequence");return s}static toRoman(t){if(t<=0||t>=4e3)throw new Error("Number must be between 1 and 3999");if(!Number.isInteger(t))throw new Error("Number must be an integer");let e="";for(const[s,r]of this.ROMAN_MAP)for(;t>=r;)e+=s,t-=r;return e}}class w{static handleNumRange(t,e=!1,s=Number.MIN_SAFE_INTEGER,r=Number.MAX_SAFE_INTEGER){if(e&&!Number.isInteger(t))throw new Error("n must be an integer");if(t<s||t>=r)throw new RangeError(`n must be in the range of ${s} to ${r}`)}static consecutiveSum(t){return w.handleNumRange(t,!0,0,1e8),t*(t+1)/2}static consecutiveSquaresSum(t){return w.handleNumRange(t,!0,0,1e6),t*(t+1)*(2*t+1)/6}static consecutivecubesSum(t){return w.handleNumRange(t,!0,0,1e4),t*(t+1)*(2*t+1)*(3*t*t+3*t-1)/30}static clamp(t,e,s){return s==null?Math.min(t,e):Math.min(Math.max(t,e),s)}static factorial(t){if(w.handleNumRange(t,!0,0,1e3),t<2)return 1;let e=1;for(let s=2;s<=t;s++)e*=s;return e}static fibonacci(t,e=1,s=1){return w.handleNumRange(t,!0,0,1e3),t<2?s:this.fibonacci(t-1,s,s+e)}static fibonacciIterative(t){if(w.handleNumRange(t,!0,0,1e3),t<2)return t;let e=0,s=1;for(let r=2;r<=t;r++)[e,s]=[s,(e+s)%1000000007];return s}static floatEqual(t,e,s=1e-6){return Math.abs(t-e)<s}static fastPower(t,e){if(w.handleNumRange(e,!0,0,10),w.handleNumRange(t,!1,0,1e3),t===0)return 0;if(e===0)return 1;const s=this.fastPower(t,e>>1);return e%2===0?s*s:s*s*t}static fastSqrt(t){if(w.handleNumRange(t,!1,0,1e8),typeof BigInt>"u")return Math.sqrt(t);const e=.5*t,s=new ArrayBuffer(8);new Float64Array(s)[0]=t;let r=new BigInt64Array(s)[0];r=0x1ff7a3bea91d9b1bn+(r>>1n);const i=new ArrayBuffer(8);new BigInt64Array(i)[0]=r;let n=new Float64Array(i)[0];return n=n*.5+e/n,n=n*.5+e/n,n=n*.5+e/n,n}static getPercentWithPrecision(t,e=2){if(!Array.isArray(t)||t.length===0)return[];if(e<0||!Number.isInteger(e))throw new Error("Precision must be a non-negative integer");const s=t.reduce((u,p)=>u+p,0);if(s===0)return t.map(()=>"0%");const i=100*Math.pow(10,e),n=t.map(u=>u/s*i),a=n.map(u=>Math.floor(u)),c=n.map((u,p)=>u-a[p]);let d=a.reduce((u,p)=>u+p,0),m=i-d;for(;m>0;){let u=-1,p=-1;for(let y=0;y<c.length;y++)c[y]>p&&(p=c[y],u=y);if(u===-1)break;a[u]++,c[u]=0,m--}return a.map(u=>`${(u/i*100).toFixed(e)}%`)}static gcd(t,e){return e===0?t:this.gcd(e,t%e)}static isValidPositiveInteger(t){return Number.isInteger(t)&&t>0&&t<=Number.MAX_SAFE_INTEGER}static isPowerOfTwo(t){return t>0&&(t&t-1)===0}static isOdd(t){return t%2===1||t%2===-1}static isPrime(t){if(t<=1)return!1;for(let e=2;e<=Math.sqrt(t);e++)if(t%e===0)return!1;return!0}static isPalindrome(t){if(t<0||t%10===0&&t!==0)return!1;let e=0,s=t;for(;t>0;){const r=t%10;e=e*10+r,t=Math.floor(t/10)}return s===e}static isArmstrong(t){const e=t.toString(),s=e.length;let r=0;for(let i=0;i<s;i++)r+=Math.pow(parseInt(e[i]),s);return r===t}static isHappy(t){const e=new Set;for(;t!==1;){if(e.has(t))return!1;e.add(t),t=(t+"").split("").reduce((s,r)=>s+Number(r)*Number(r),0)}return!0}static isPerfect(t){let e=0;for(let s=1;s<t;s++)t%s===0&&(e+=s);return e===t}static isSameSign(t,e){return t>=0&&e>=0||t<=0&&e<=0}static isRange(t,e,s){if(s==null&&(s=e,e=0),e>=s)throw new Error("The maximum value must be greater than the minimum value");return e<=t&&t<s}static lcm(t,e){return t*e/this.gcd(t,e)}static middle(t,e){return e-(e-t>>1)}static random(t,e){if(e==null&&(e=t,t=0),t>=e)throw new Error("The maximum value must be greater than the minimum value");return Math.random()*(e-t)+t}static randomInt(t,e){return Math.floor(this.random(t,e))}static round(t,e=0){if(!Number.isInteger(e))throw new Error("precision must be an integer");const s=Math.pow(10,e);return Math.round(t*s)/s}static scale(t,e,s){if(e[0]>=e[1]||s[0]>=s[1])throw new Error("Invalid range");t=this.clamp(t,e[0],e[1]);const r=e[1]-e[0];return(t-e[0])*((s[1]-s[0])/r)+s[0]}}class K{static READ=1;static WRITE=2;static SHARE=4;static DELETE=8;static CREATE=16;static include(t,e){return(t&e)===e}static add(t,e){return t|e}static remove(t,e){return t&~e}static toggle(t,e){return t^e}}class x{static frequencyStatistics(t){return[...t].reduce((e,s)=>(e[s]=(e[s]||0)+1,e),{})}static isValidBracket(t){const e=[],s={"(":")","[":"]","{":"}"},r=new Set(Object.values(s));for(const i of t)if(i in s)e.push(s[i]);else if(r.has(i)&&i!==e.pop())return!1;return e.length===0}static random(t=8){const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let s="";for(let r=0;r<t;r++)s+=e.charAt(Math.floor(Math.random()*e.length));return s}static template(t,e){return t.replace(/\${(\w+)}/g,(s,r)=>e[r]||"")}static escapeHtml(t){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&apos;"," ":"&nbsp;","±":"&plusmn;","×":"&times;","÷":"&divide;","≠":"&ne;","≤":"&le;","≥":"&ge;"},s=new RegExp(`[${Object.keys(e).join("")}]`,"g");return t.replace(s,r=>e[r])}static isEmail(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}static isUrl(t){try{return new URL(t),!0}catch{return!1}}static pointLength(t){let e=0;for(let s=0,r=t.length;s<r;){const i=t.codePointAt(s);s+=i>65535?2:1,e++}return e}static pointAt(t,e){if(e>=x.pointLength(t))return;let s=0;for(let r=0,i=t.length;r<i;){const n=t.codePointAt(r);if(!n)return;if(s===e)return String.fromCodePoint(n);r+=n>65535?2:1,s++}}static sliceByPoint(t,e,s=x.pointLength(t)){let r="";for(let i=e;i<s;i++)r+=x.pointAt(t,i);return r}static capitalize(t){return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}static reverse(t){return t.split("").reverse().join("")}static truncate(t,e,s="..."){return t.length<=e?this:t.slice(0,e-s.length)+s}static isPalindrome(t){return t.toLowerCase().replace(/[^a-z0-9]/g,"")===x.reverse(t)}static count(t,e){const s=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return(t.match(new RegExp(s,"g"))||[]).length}static toCamelCase(t){return t.replace(/_([a-z])/g,(e,s)=>s.toUpperCase())}static toSnakeCase(t){return t.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`)}}class tt{static isValidHex(t){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t)}static isValidRGB(t){return/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.test(t)}}const v={AUTH_UNAUTHORIZED:"未授权事件",AUTH_LOGIN_SUCCESS:"登录成功事件",AUTH_LOGOUT:"注销事件",AUTH_TOKEN_EXPIRED:"令牌过期事件",REQUEST_ERROR:"请求错误事件",REQUEST_TIMEOUT:"请求超时事件",REQUEST_NETWORK_ERROR:"网络错误事件",UI_SHOW_LOADING:"显示加载事件",UI_HIDE_LOADING:"隐藏加载事件",UI_SHOW_MESSAGE:"显示消息事件"};class A{static instance=null;listeners={};debugMode;constructor(t=!1){this.debugMode=t,Object.keys(v).forEach(e=>{this.listeners[e]=new Set})}static getInstance(t){return A.instance||(A.instance=new A(t)),A.instance}on(t,e){this.debugLog(`添加事件监听: ${v[t]}`),this.listeners[t].add(e)}emit(t,e){this.debugLog(`触发事件: ${v[t]}`,e),this.listeners[t].forEach(s=>{try{s(e)}catch(r){console.error(`事件 ${v[t]} 处理出错:`,r)}})}off(t,e){this.debugLog(`移除事件监听: ${v[t]}`),this.listeners[t].delete(e)}once(t,e){this.debugLog(`添加一次性事件监听: ${v[t]}`);const s=r=>{e(r),this.off(t,s)};this.on(t,s)}clear(){this.debugLog("清除所有事件监听器"),Object.values(this.listeners).forEach(t=>t.clear())}getListenerCount(t){return this.listeners[t].size}debugLog(t,e){this.debugMode&&console.log(`[EventEmitter] ${t}`,e||"")}}class P{static OPERATORS=new Set(["+","-","*","/"]);static VALID_CHARS_REG=/^[0-9+\-*/().\s]+$/;static PRIORITY_MAP=new Map([["+",1],["-",1],["*",2],["/",2],["(",0],[")",0]]);static getPriority(t){return this.PRIORITY_MAP.get(t)??0}static validateExpression(t){if(!t)throw new Error("Expression cannot be empty");if(!this.VALID_CHARS_REG.test(t))throw new Error("Expression contains invalid characters")}static processClosingParenthesis(t,e){for(;!t.isEmpty();){if(t.peek()==="("){t.pop();break}const r=t.pop();r&&e.push(r)}}static processOperator(t,e,s){for(;!e.isEmpty();){const r=e.peek();if(!r||r==="(")break;if(this.getPriority(t)<=this.getPriority(r)){const i=e.pop();i&&s.push(i)}else break}e.push(t)}static applyOperator(t,e,s){switch(s){case"+":return t+e;case"-":return t-e;case"*":return t*e;case"/":if(e===0)throw new Error("Division by zero");return t/e;default:throw new Error("Invalid operator")}}static FLOAT_NUM_REG=/^-?\d*\.?\d+$/;static EXPRESSION_REG=new RegExp("(?<!\\d)-?\\d*\\.?\\d+|[+\\-*/()]","g");static toArr(t){this.validateExpression(t);const e=t.match(P.EXPRESSION_REG);if(!e)throw new Error("Invalid expression format");return e.filter(s=>s.trim()!=="").map(s=>{if(this.FLOAT_NUM_REG.test(s)||this.OPERATORS.has(s)||s==="("||s===")")return s;throw new Error(`Invalid token: ${s}`)})}static infixToPostfix(t){if(!t?.trim())throw new Error("Expression cannot be empty");const e=new R,s=this.toArr(t);console.log(s);const r=[];for(const i of s)this.FLOAT_NUM_REG.test(i)?r.push(i):i==="("?e.push(i):i===")"?this.processClosingParenthesis(e,r):this.OPERATORS.has(i)&&this.processOperator(i,e,r);for(;!e.isEmpty();){const i=e.pop();i&&i!=="("&&r.push(i)}return{postfix:r.join(" "),postfixArr:r}}static evaluatePostfix(t){if(!t.length)throw new Error("Postfix expression cannot be empty");typeof t=="string"&&(t=P.toArr(t));const e=new R;for(const s of t)if(this.FLOAT_NUM_REG.test(s))e.push(parseFloat(s));else if(this.OPERATORS.has(s)){const r=e.pop(),i=e.pop();if(i===void 0||r===void 0)throw new Error("Invalid postfix expression");e.push(this.applyOperator(i,r,s))}return e.pop()??0}}class et{static isMatchingPair(t,e){return t==="("&&e===")"||t==="{"&&e==="}"||t==="["&&e==="]"}static isvalidBrackets(t){const e=new R;for(let s=0,r=t.length;s<r;s++){const i=t[s];if(["{","[","("].includes(i))e.push(i);else if(["}","]",")"].includes(i)){if(e.isEmpty())return!1;const n=e.pop();if(!n||!this.isMatchingPair(n,i))return!1}}return e.isEmpty()}}o.Arr=W,o.ArrStack=R,o.BitPerm=K,o.Color=tt,o.DateEx=M,o.Dictionary=$,o.Emitter=A,o.Expression=P,o.Func=X,o.Graph=j,o.LRU=_,o.Line=g,o.LinkedList=G,o.Matrix=S,o.MaxHeap=q,o.MemoizeMap=Q,o.MinHeap=C,o.MinStack=V,o.Num=w,o.Obj=J,o.Point=l,o.Queue=O,o.Reg=Z,o.Roman=Y,o.Stack=U,o.StackApplication=et,o.Str=x,o.TrafficLight=L,o.Triangle=f,o.Vector=E,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
package/index.d.ts CHANGED
@@ -16,6 +16,17 @@ declare module "jc-structure" {
16
16
  toString(): string;
17
17
  }
18
18
 
19
+ export class ArrStack<T> implements IStack<T> {
20
+ constructor();
21
+ push(...args: (T | T[])[]): this;
22
+ pop(): T | undefined;
23
+ peek(): T | undefined;
24
+ isEmpty(): boolean;
25
+ size(): number;
26
+ clear(): void;
27
+ toString(): string;
28
+ }
29
+
19
30
  /**
20
31
  * 队列类,采用object实现
21
32
  */
@@ -935,4 +946,51 @@ declare module "jc-structure" {
935
946
  * @see https://www.bilibili.com/video/BV1kDZmY4EWM/?spm_id_from=333.337.search-card.all.click&vd_source=9efadbd9bd76b9c14f9589f260a0c1ac
936
947
  */
937
948
  var TrafficLight: TrafficLightConstructor;
949
+
950
+ interface InfixToPostfixResult {
951
+ postfix: string;
952
+ postfixArr: string[];
953
+ }
954
+ /**
955
+ * #### 表达式类
956
+ */
957
+ export class Expression {
958
+ /**
959
+ * #### 浮点数正则表达式
960
+ * - 能匹配 ‘.5’
961
+ * - 不能匹配科学计数法,‘1e-2’
962
+ */
963
+ static readonly FLOAT_NUM_REG: RegExp;
964
+ /**
965
+ * #### 表达式正则表达式
966
+ * - 能匹配负数的表达式,‘-1+2’,‘-1-2’
967
+ */
968
+ static readonly EXPRESSION_REG: RegExp;
969
+ /**
970
+ * #### 将表达式转换为匹配的数组
971
+ * @param expression 表达式
972
+ */
973
+ static toArr(expression: string): string[];
974
+ /**
975
+ * 将中缀表达式转换为后缀表达式,也叫逆波兰表达式
976
+ * @param infixExpression 中缀表达式
977
+ */
978
+ static infixToPostfix(infixExpression: string): InfixToPostfixResult;
979
+ /**
980
+ * #### 计算后缀表达式
981
+ * @param postfix 后缀表达式
982
+ */
983
+ static evaluatePostfix(postfix: string | string[]): number;
984
+ }
985
+
986
+ /**
987
+ * #### 栈应用类
988
+ */
989
+ export class StackApplication {
990
+ /**
991
+ * #### 是否是有效的成对括号
992
+ * @param str
993
+ */
994
+ static isvalidBrackets(str: string): boolean;
995
+ }
938
996
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jc-structure",
3
3
  "private": false,
4
- "version": "0.2.11",
4
+ "version": "0.2.13",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",