jc-structure 0.2.4 → 0.2.6

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 U {
1
+ class q {
2
2
  items = {};
3
3
  count = 0;
4
4
  lowestCount = 0;
@@ -49,7 +49,7 @@ class U {
49
49
  return this.isEmpty() ? "" : `Queue(size: ${this.size()}):[${this.items[this.lowestCount]},...rest]`;
50
50
  }
51
51
  }
52
- class V {
52
+ class U {
53
53
  items = {};
54
54
  count = 0;
55
55
  constructor() {
@@ -100,7 +100,7 @@ class V {
100
100
  return this.isEmpty() ? "" : `Stack(count: ${this.count}):[${this.items[this.count - 1]},...rest]`;
101
101
  }
102
102
  }
103
- class q {
103
+ class V {
104
104
  stack = [];
105
105
  minStack = [];
106
106
  push(t) {
@@ -129,13 +129,13 @@ class q {
129
129
  return this.isEmpty() ? "" : `MinStack(count: ${this.size()}):[${this.getMin()},...rest]`;
130
130
  }
131
131
  }
132
- function L(h, t) {
132
+ function N(h, t) {
133
133
  return h === t ? 0 : h < t ? -1 : 1;
134
134
  }
135
- class E {
135
+ class x {
136
136
  heap = [];
137
137
  compareFn;
138
- constructor(t = L) {
138
+ constructor(t = N) {
139
139
  this.compareFn = t;
140
140
  }
141
141
  static getLeftIndex(t) {
@@ -166,7 +166,7 @@ class E {
166
166
  return this.heap.toString();
167
167
  }
168
168
  }
169
- class D extends E {
169
+ class $ extends x {
170
170
  insert(t) {
171
171
  return t ? !1 : (this.heap.push(t), this.siftUp(this.heap.length - 1), !0);
172
172
  }
@@ -177,21 +177,21 @@ class D extends E {
177
177
  return this.heap[0] = this.heap.pop(), this.siftDown(0), t;
178
178
  }
179
179
  siftUp(t) {
180
- let e = t, s = E.getLeftIndex(e), r = E.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 && (E.swap(this.heap, t, e), this.siftUp(e));
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));
182
182
  }
183
183
  siftDown(t) {
184
- let e = E.getParentIndex(t);
184
+ let e = x.getParentIndex(t);
185
185
  for (; t > 0 && e && this.compareFn(this.heap[e], this.heap[t]) === 1; )
186
- E.swap(this.heap, e, t), t = e, e = E.getParentIndex(t);
186
+ x.swap(this.heap, e, t), t = e, e = x.getParentIndex(t);
187
187
  }
188
188
  }
189
- class F extends D {
190
- constructor(t = (e, s) => L(s, e)) {
189
+ class F extends $ {
190
+ constructor(t = (e, s) => N(s, e)) {
191
191
  super(t);
192
192
  }
193
193
  }
194
- function T(h) {
194
+ function D(h) {
195
195
  return { value: h };
196
196
  }
197
197
  class B {
@@ -224,75 +224,104 @@ class B {
224
224
  }
225
225
  update(t, e) {
226
226
  let s = this.lookup.get(t);
227
- s ? (this.detach(s), this.prepend(s), s.value = e) : (s = T(e), this.length++, this.prepend(s), this.trimCache(), this.lookup.set(t, s), this.reverseLookup);
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);
228
228
  }
229
229
  }
230
230
  class b {
231
- value;
232
- next = void 0;
231
+ constructor(t, e = null) {
232
+ this.value = t, this.next = e;
233
+ }
233
234
  }
234
235
  class G {
235
236
  count = 0;
236
- head = void 0;
237
- constructor() {
237
+ head = null;
238
+ tail = null;
239
+ // 添加尾指针优化
240
+ constructor(t) {
241
+ t && t.forEach((e) => this.push(e));
242
+ }
243
+ [Symbol.iterator]() {
244
+ let t = this.head;
245
+ return {
246
+ next() {
247
+ if (t) {
248
+ const e = t.value;
249
+ return t = t.next, { value: e, done: !1 };
250
+ }
251
+ return { value: void 0, done: !0 };
252
+ }
253
+ };
254
+ }
255
+ equals(t, e) {
256
+ if (t === e) return !0;
257
+ if (t == null || e == null) return !1;
258
+ if (typeof t == "object" && typeof e == "object") {
259
+ if (t.equals && typeof t.equals == "function")
260
+ return t.equals(e);
261
+ const s = Object.keys(t), r = Object.keys(e);
262
+ return s.length !== r.length ? !1 : s.every((i) => t[i] === e[i]);
263
+ }
264
+ return !1;
238
265
  }
239
266
  indexOf(t) {
240
- let e = this.head, s = 0, r = !1;
267
+ let e = this.head, s = 0;
241
268
  for (; e; ) {
242
- if (this.equals(e.value, t)) {
243
- r = !0;
244
- break;
245
- }
269
+ if (this.equals(e.value, t))
270
+ return s;
246
271
  s++, e = e.next;
247
272
  }
248
- return r ? s : -1;
249
- }
250
- equals(t, e) {
251
- return t === e ? !0 : t == null || e == null ? !1 : typeof t == "object" && typeof e == "object" ? JSON.stringify(t) === JSON.stringify(e) : !1;
273
+ return -1;
252
274
  }
253
275
  getElementAt(t) {
254
276
  if (t < 0 || t >= this.count)
255
- return;
256
- if (t === 0)
257
- return this.head;
277
+ return null;
278
+ if (t > this.count / 2) {
279
+ let s = this.tail, r = this.count - 1;
280
+ for (; r > t && s; )
281
+ s = s.next, r--;
282
+ return s;
283
+ }
258
284
  let e = this.head;
259
- for (let s = 0; s < t; s++)
260
- e = e?.next;
285
+ for (let s = 0; s < t && e; s++)
286
+ e = e.next;
261
287
  return e;
262
288
  }
263
289
  getValueAt(t) {
264
290
  return this.getElementAt(t)?.value;
265
291
  }
266
292
  insert(t, e) {
267
- let s = new b();
268
- if (s.value = t, e > this.count || e < 0)
269
- throw new Error("index error");
270
- this.count++;
271
- let r, i;
272
- if (e === 0) {
273
- s.next = this.head, this.head = s;
274
- return;
293
+ if (e < 0 || e > this.count)
294
+ throw new Error(`Index out of bounds: ${e}`);
295
+ const s = new b(t);
296
+ if (e === 0)
297
+ s.next = this.head, this.head = s, this.count === 0 && (this.tail = s);
298
+ else if (e === this.count)
299
+ this.tail && (this.tail.next = s, this.tail = s);
300
+ else {
301
+ const r = this.getElementAt(e - 1);
302
+ r && (s.next = r.next, r.next = s);
275
303
  }
276
- r = this.getElementAt(e - 1), i = r.next, r.next = s, s.next = i;
304
+ return this.count++, !0;
277
305
  }
278
306
  push(t) {
279
- let e = new b();
280
- if (e.value = t, this.count++, this.isEmpty()) {
281
- this.head = e;
282
- return;
283
- }
284
- let s = this.getElementAt(this.count - 1);
285
- s.next = e;
307
+ const e = new b(t);
308
+ this.head ? this.tail && (this.tail.next = e, this.tail = e) : (this.head = e, this.tail = e), this.count++;
286
309
  }
287
310
  remove(t) {
288
311
  const e = this.indexOf(t);
289
- return e === -1 ? void 0 : this.removeAt(e);
312
+ return e === -1 ? null : this.removeAt(e);
290
313
  }
291
314
  removeAt(t) {
292
- if (this.isEmpty() || t < 0 || t >= this.count)
293
- return;
294
- let e = this.getElementAt(t), s = this.getElementAt(t - 1), r = e?.next;
295
- return t === 0 && (this.head = r), s && (s.next = r), this.count--, e?.value;
315
+ if (t < 0 || t >= this.count)
316
+ return null;
317
+ let e = this.head;
318
+ if (t === 0)
319
+ this.head = e?.next || null, this.count === 1 && (this.tail = null);
320
+ else {
321
+ const s = this.getElementAt(t - 1);
322
+ s && (e = s.next, s.next = e?.next || null, t === this.count - 1 && (this.tail = s));
323
+ }
324
+ return this.count--, e?.value || null;
296
325
  }
297
326
  isEmpty() {
298
327
  return this.count === 0;
@@ -301,16 +330,25 @@ class G {
301
330
  return this.count;
302
331
  }
303
332
  clear() {
304
- this.count = 0, this.head = void 0;
333
+ this.head = null, this.tail = null, this.count = 0;
305
334
  }
306
335
  toString() {
336
+ if (this.isEmpty())
337
+ return "";
307
338
  let t = "", e = this.head;
308
339
  for (; e; )
309
- t += e.value, t += ",", e = e.next;
310
- return t = t.slice(0, -1), t;
340
+ t += JSON.stringify(e.value), e.next && (t += ","), e = e.next;
341
+ return t;
342
+ }
343
+ toArray() {
344
+ const t = [];
345
+ let e = this.head;
346
+ for (; e; )
347
+ t.push(e.value), e = e.next;
348
+ return t;
311
349
  }
312
350
  }
313
- class $ {
351
+ class T {
314
352
  key;
315
353
  value;
316
354
  constructor(t, e) {
@@ -339,7 +377,7 @@ class H {
339
377
  let s = this.getItemIndex(t);
340
378
  this.table[s].value = e;
341
379
  } else {
342
- const s = new $(t, e);
380
+ const s = new T(t, e);
343
381
  this.table.push(s);
344
382
  }
345
383
  }
@@ -640,14 +678,14 @@ class g {
640
678
  return this.p2;
641
679
  }
642
680
  }
643
- class P {
681
+ class k {
644
682
  static EPSILON = 1e-10;
645
683
  name;
646
684
  constructor(t) {
647
685
  this.name = t;
648
686
  }
649
687
  }
650
- class p extends P {
688
+ class p extends k {
651
689
  static isValid(t, e, s) {
652
690
  return t <= 0 || e <= 0 || s <= 0 ? !1 : t + e > s && t + s > e && e + s > t;
653
691
  }
@@ -680,7 +718,7 @@ class p extends P {
680
718
  areCollinear() {
681
719
  return Math.abs(
682
720
  (this.p2.x - this.p1.x) * (this.p3.y - this.p1.y) - (this.p3.x - this.p1.x) * (this.p2.y - this.p1.y)
683
- ) < P.EPSILON;
721
+ ) < k.EPSILON;
684
722
  }
685
723
  get side() {
686
724
  return [
@@ -762,7 +800,7 @@ class X {
762
800
  return t.prototype.constructor = s, s;
763
801
  }
764
802
  }
765
- class Q {
803
+ class j {
766
804
  static groupBy(t, e) {
767
805
  if (!e)
768
806
  throw new Error("generateKey is required");
@@ -811,7 +849,7 @@ class Q {
811
849
  function O(h) {
812
850
  return h !== null && (typeof h == "object" || typeof h == "function");
813
851
  }
814
- class _ {
852
+ class Q {
815
853
  map = /* @__PURE__ */ new Map();
816
854
  weakMap = /* @__PURE__ */ new WeakMap();
817
855
  set(t, e) {
@@ -824,7 +862,7 @@ class _ {
824
862
  return O(t) ? this.weakMap.has(t) : this.map.has(t);
825
863
  }
826
864
  }
827
- class j {
865
+ class J {
828
866
  static jsonClone(t) {
829
867
  try {
830
868
  return JSON.parse(JSON.stringify(t));
@@ -894,7 +932,7 @@ class j {
894
932
  return r;
895
933
  }
896
934
  }
897
- const k = {
935
+ const P = {
898
936
  date: "yyyy-MM-dd",
899
937
  datetime: "yyyy-MM-dd HH:mm:ss",
900
938
  time: "HH:mm:ss",
@@ -936,7 +974,7 @@ class M {
936
974
  return t;
937
975
  if (typeof t != "string")
938
976
  throw new Error("Formatter must be a string or function");
939
- t in k && (t = k[t]);
977
+ t in P && (t = P[t]);
940
978
  const e = {
941
979
  yyyy: "yyyy",
942
980
  MM: "MM",
@@ -961,7 +999,7 @@ class M {
961
999
  return o > 0 ? s > 0 ? `${o}天后` : `${o}天前` : a > 0 ? s > 0 ? `${a}小时后` : `${a}小时前` : n > 0 ? s > 0 ? `${n}分钟后` : `${n}分钟前` : s > 0 ? "刚刚" : "";
962
1000
  }
963
1001
  }
964
- class N {
1002
+ class L {
965
1003
  lights;
966
1004
  currentIndex;
967
1005
  switchTime;
@@ -971,7 +1009,7 @@ class N {
971
1009
  { color: "green", latest: 10 },
972
1010
  { color: "yellow", latest: 3 }
973
1011
  ];
974
- constructor(t = N.DEFAULT_LIGHTS) {
1012
+ constructor(t = L.DEFAULT_LIGHTS) {
975
1013
  this.lights = t, this.currentIndex = 0, this.switchTime = Date.now();
976
1014
  }
977
1015
  render(t) {
@@ -996,12 +1034,12 @@ class N {
996
1034
  };
997
1035
  }
998
1036
  }
999
- class J {
1037
+ class Z {
1000
1038
  static escape(t) {
1001
1039
  return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1002
1040
  }
1003
1041
  }
1004
- class Z {
1042
+ class Y {
1005
1043
  static ROMAN_MAP = /* @__PURE__ */ new Map([
1006
1044
  ["M", 1e3],
1007
1045
  ["CM", 900],
@@ -1220,7 +1258,7 @@ class y {
1220
1258
  return (t - e[0]) * ((s[1] - s[0]) / r) + s[0];
1221
1259
  }
1222
1260
  }
1223
- class Y {
1261
+ class K {
1224
1262
  static READ = 1;
1225
1263
  static WRITE = 2;
1226
1264
  static SHARE = 4;
@@ -1347,7 +1385,7 @@ class S {
1347
1385
  return t.replace(/[A-Z]/g, (e) => `_${e.toLowerCase()}`);
1348
1386
  }
1349
1387
  }
1350
- class K {
1388
+ class _ {
1351
1389
  static isValidHex(t) {
1352
1390
  return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t);
1353
1391
  }
@@ -1355,7 +1393,7 @@ class K {
1355
1393
  return /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.test(t);
1356
1394
  }
1357
1395
  }
1358
- const x = {
1396
+ const E = {
1359
1397
  AUTH_UNAUTHORIZED: "未授权事件",
1360
1398
  AUTH_LOGIN_SUCCESS: "登录成功事件",
1361
1399
  AUTH_LOGOUT: "注销事件",
@@ -1372,7 +1410,7 @@ class A {
1372
1410
  listeners = {};
1373
1411
  debugMode;
1374
1412
  constructor(t = !1) {
1375
- this.debugMode = t, Object.keys(x).forEach(
1413
+ this.debugMode = t, Object.keys(E).forEach(
1376
1414
  (e) => {
1377
1415
  this.listeners[e] = /* @__PURE__ */ new Set();
1378
1416
  }
@@ -1382,22 +1420,22 @@ class A {
1382
1420
  return A.instance || (A.instance = new A(t)), A.instance;
1383
1421
  }
1384
1422
  on(t, e) {
1385
- this.debugLog(`添加事件监听: ${x[t]}`), this.listeners[t].add(e);
1423
+ this.debugLog(`添加事件监听: ${E[t]}`), this.listeners[t].add(e);
1386
1424
  }
1387
1425
  emit(t, e) {
1388
- this.debugLog(`触发事件: ${x[t]}`, e), this.listeners[t].forEach((s) => {
1426
+ this.debugLog(`触发事件: ${E[t]}`, e), this.listeners[t].forEach((s) => {
1389
1427
  try {
1390
1428
  s(e);
1391
1429
  } catch (r) {
1392
- console.error(`事件 ${x[t]} 处理出错:`, r);
1430
+ console.error(`事件 ${E[t]} 处理出错:`, r);
1393
1431
  }
1394
1432
  });
1395
1433
  }
1396
1434
  off(t, e) {
1397
- this.debugLog(`移除事件监听: ${x[t]}`), this.listeners[t].delete(e);
1435
+ this.debugLog(`移除事件监听: ${E[t]}`), this.listeners[t].delete(e);
1398
1436
  }
1399
1437
  once(t, e) {
1400
- this.debugLog(`添加一次性事件监听: ${x[t]}`);
1438
+ this.debugLog(`添加一次性事件监听: ${E[t]}`);
1401
1439
  const s = (r) => {
1402
1440
  e(r), this.off(t, s);
1403
1441
  };
@@ -1414,9 +1452,9 @@ class A {
1414
1452
  }
1415
1453
  }
1416
1454
  export {
1417
- Q as Arr,
1418
- Y as BitPerm,
1419
- K as Color,
1455
+ j as Arr,
1456
+ K as BitPerm,
1457
+ _ as Color,
1420
1458
  M as DateEx,
1421
1459
  H as Dictionary,
1422
1460
  A as Emitter,
@@ -1427,18 +1465,18 @@ export {
1427
1465
  G as LinkedList,
1428
1466
  I as Matrix,
1429
1467
  F as MaxHeap,
1430
- _ as MemoizeMap,
1431
- D as MinHeap,
1432
- q as MinStack,
1468
+ Q as MemoizeMap,
1469
+ $ as MinHeap,
1470
+ V as MinStack,
1433
1471
  y as Num,
1434
- j as Obj,
1472
+ J as Obj,
1435
1473
  u as Point,
1436
- U as Queue,
1437
- J as Reg,
1438
- Z as Roman,
1439
- V as Stack,
1474
+ q as Queue,
1475
+ Z as Reg,
1476
+ Y as Roman,
1477
+ U as Stack,
1440
1478
  S as Str,
1441
- N as TrafficLight,
1479
+ L as TrafficLight,
1442
1480
  p as Triangle,
1443
1481
  w as Vector
1444
1482
  };
@@ -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 k(h,t){return h===t?0:h<t?-1:1}class I{heap=[];compareFn;constructor(t=k){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)=>k(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{value;next=void 0}class F{count=0;head=void 0;constructor(){}indexOf(t){let e=this.head,s=0,r=!1;for(;e;){if(this.equals(e.value,t)){r=!0;break}s++,e=e.next}return r?s:-1}equals(t,e){return t===e?!0:t==null||e==null?!1:typeof t=="object"&&typeof e=="object"?JSON.stringify(t)===JSON.stringify(e):!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 N;if(s.value=t,e>this.count||e<0)throw new Error("index error");this.count++;let r,i;if(e===0){s.next=this.head,this.head=s;return}r=this.getElementAt(e-1),i=r.next,r.next=s,s.next=i}push(t){let e=new N;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),r=e?.next;return t===0&&(this.head=r),s&&(s.next=r),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 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 M{_matrix;static zero(t,e){return new M(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 M(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 M(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 M(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=M.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 K=r+y*(n-r),tt=i+y*(a-i);return new l(K,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 S{static defaultOptions={paddingZero:!1,locale:"en-US"};static setDefaultOptions(t){S.defaultOptions={...S.defaultOptions,...t}}static format(t,e,s={}){const r={...S.defaultOptions,...s},i=S.getDateInfo(t,r);return S.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 P{lights;currentIndex;switchTime;static DEFAULT_LIGHTS=[{color:"red",latest:7},{color:"yellow",latest:3},{color:"green",latest:10},{color:"yellow",latest:3}];constructor(t=P.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 _{static escape(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}}class J{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 Z{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 Y{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=Z,o.Color=Y,o.DateEx=S,o.Dictionary=T,o.Emitter=v,o.Func=j,o.Graph=G,o.LRU=q,o.Line=g,o.LinkedList=F,o.Matrix=M,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=_,o.Roman=J,o.Stack=H,o.Str=x,o.TrafficLight=P,o.Triangle=d,o.Vector=E,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(o,O){typeof exports=="object"&&typeof module<"u"?O(exports):typeof define=="function"&&define.amd?define(["exports"],O):(o=typeof globalThis<"u"?globalThis:o||self,O(o["jc-structure"]={}))})(this,(function(o){"use strict";class O{items={};count=0;lowestCount=0;constructor(){}dequeue(){if(this.isEmpty())return;const t=this.items[this.lowestCount];return delete this.items[this.lowestCount],this.lowestCount++,t}enqueue(...t){if(t.length===0)return this;if(t.length===1){const e=t[0];return Array.isArray(e)?this.batchEnqueue(e):this.enqueueItem(e)}for(const e of t)Array.isArray(e)?this.batchEnqueue(e):this.enqueueItem(e);return this}batchEnqueue(t){return t.filter(s=>this.isValidItem(s)).forEach(s=>{this.isValidItem(s)&&(this.items[this.count]=s,this.count++)}),this}enqueueItem(t){if(!this.isValidItem(t))throw new Error("Invalid item");return this.items[this.count]=t,this.count++,this}isValidItem(t){return t!=null}front(){return this.isEmpty()?void 0:this.items[this.lowestCount]}isEmpty(){return this.size()===0}size(){return this.count-this.lowestCount}clear(){this.items={},this.count=0,this.lowestCount=0}toString(){return this.isEmpty()?"":`Queue(size: ${this.size()}):[${this.items[this.lowestCount]},...rest]`}}class H{items={};count=0;constructor(){}pop(){if(this.isEmpty())return;this.count--;const t=this.items[this.count];return delete this.items[this.count],t}push(...t){if(t.length===0)return this;if(t.length===1){const e=t[0];return Array.isArray(e)?this.addItems(e):this.addItem(e)}for(const e of t)Array.isArray(e)?this.addItems(e):this.addItem(e);return this}addItem(t){if(!this.isValidItem(t))throw new Error("Invalid item: item cannot be null or undefined");return this.items[this.count]=t,this.count++,this}addItems(t){return t.filter(s=>this.isValidItem(s)).forEach(s=>{this.items[this.count]=s,this.count++}),this}isValidItem(t){return t!=null}peek(){return this.isEmpty()?void 0:this.items[this.count-1]}isEmpty(){return this.count===0}size(){return this.count}clear(){this.items={},this.count=0}toString(){return this.isEmpty()?"":`Stack(count: ${this.count}):[${this.items[this.count-1]},...rest]`}}class ${stack=[];minStack=[];push(t){this.stack.push(t),(this.minStack.length===0||t<=this.minStack[this.minStack.length-1])&&this.minStack.push(t)}pop(){const t=this.stack.pop();return t===this.minStack[this.minStack.length-1]&&this.minStack.pop(),t}peek(){return this.stack[this.stack.length-1]}getMin(){return this.minStack[this.minStack.length-1]}isEmpty(){return this.size()===0}size(){return this.stack.length}clear(){this.stack=[],this.minStack=[]}toString(){return this.isEmpty()?"":`MinStack(count: ${this.size()}):[${this.getMin()},...rest]`}}function P(h,t){return h===t?0:h<t?-1:1}class 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){this.value=t,this.next=e}}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.next,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"})}));
package/index.d.ts CHANGED
@@ -1,55 +1,60 @@
1
1
  declare module "jc-structure" {
2
+ export * from "./types/index";
3
+
2
4
  //#region data structure
3
5
  /**
4
6
  * #### 数据结构接口
5
7
  */
6
- interface DataStructure {
7
- /**
8
- * 判断数据结构是否为空
9
- */
10
- isEmpty(): boolean;
11
- /**
12
- * 数据结构元素长度
13
- */
14
- size(): number;
15
- /**
16
- * 清除数据结构元素
17
- */
18
- clear(): void;
19
- /**
20
- * 重写 toString 方法
21
- */
22
- toString(): string;
23
- }
8
+ // interface DataStructure {
9
+ // /**
10
+ // * 判断数据结构是否为空
11
+ // */
12
+ // isEmpty(): boolean;
13
+ // /**
14
+ // * 数据结构元素长度
15
+ // */
16
+ // size(): number;
17
+ // /**
18
+ // * 清除数据结构元素
19
+ // */
20
+ // clear(): void;
21
+ // /**
22
+ // * 重写 toString 方法
23
+ // */
24
+ // toString(): string;
25
+ // }
24
26
 
25
27
  /**
26
28
  * 栈类,采用object实现
27
29
  */
28
- interface Stack<T> extends DataStructure {
29
- /**
30
- * #### 移除栈顶元素并返回该元素
31
- */
32
- pop(): T | undefined;
33
-
34
- /**
35
- * #### 向栈顶添加元素
36
- * @param args 要添加的元素,key可以是多个或一个元素。
37
- */
38
- push(item: T): this;
39
- push(items: Array<T>): this;
40
- push(...items: T[]): this;
41
- push(itemOrItems: T | Array<T>): this;
42
-
43
- /**
44
- * #### 返回栈顶元素,但不移除
45
- */
46
- peek(): T | undefined;
47
- }
48
- interface StackConstructor {
49
- new <T>(): Stack<T>;
50
- readonly prototype: Stack<T>;
30
+ export class Stack<T> implements IStack<T> {
31
+ constructor();
51
32
  }
52
- var Stack: StackConstructor;
33
+ // interface Stack<T> extends DataStructure {
34
+ // /**
35
+ // * #### 移除栈顶元素并返回该元素
36
+ // */
37
+ // pop(): T | undefined;
38
+
39
+ // /**
40
+ // * #### 向栈顶添加元素
41
+ // * @param args 要添加的元素,key可以是多个或一个元素。
42
+ // */
43
+ // push(item: T): this;
44
+ // push(items: Array<T>): this;
45
+ // push(...items: T[]): this;
46
+ // push(itemOrItems: T | Array<T>): this;
47
+
48
+ // /**
49
+ // * #### 返回栈顶元素,但不移除
50
+ // */
51
+ // peek(): T | undefined;
52
+ // }
53
+ // interface StackConstructor {
54
+ // new <T>(): Stack<T>;
55
+ // readonly prototype: Stack<T>;
56
+ // }
57
+ // var Stack: StackConstructor;
53
58
 
54
59
  /**
55
60
  * 队列类,采用object实现
@@ -109,7 +114,7 @@ declare module "jc-structure" {
109
114
  }
110
115
  interface MinHeapConstructor {
111
116
  new <T>(fn?: CompareFn<T>): MinHeap<T>;
112
- readonly prototype: MinHeap<T>;
117
+ readonly prototype: MinHeap;
113
118
  }
114
119
  var MinHeap: MinHeapConstructor;
115
120
 
@@ -140,75 +145,38 @@ declare module "jc-structure" {
140
145
  }
141
146
  interface LRUConstructor {
142
147
  new <K, V>(capacity?: number): LRU<K, V>;
143
- readonly prototype: LRU<K, V>;
148
+ readonly prototype: LRU;
144
149
  }
145
150
  var LRU: LRUConstructor;
146
151
 
147
- /**
148
- * 链表节点类
149
- */
150
- export class LinkedList<T> {
151
- constructor();
152
- /**
153
- * #### 向链表中添加元素
154
- * @param element 要添加的元素
155
- */
156
- push(element: T): void;
157
-
158
- /**
159
- * #### 在指定位置插入元素
160
- * @param element 要插入的元素
161
- * @param index 插入的位置索引
162
- */
163
- insert(element: T, index: number): void;
164
-
165
- /**
166
- * #### 获取指定位置的节点
167
- * @param index 指定位置索引
168
- */
169
- getElementAt(index: number): Node<T> | undefined;
170
-
171
- /**
172
- * #### 获取指定位置的值
173
- * @param index 指定位置索引
174
- */
175
- getValueAt(index: number): T | undefined;
176
-
177
- /**
178
- * #### 移除指定位置的元素
179
- * @param index 指定位置索引
180
- */
181
- removeAt(index: number): T | undefined;
182
-
183
- /**
184
- * #### 移除指定元素
185
- * @param element 指定元素
186
- */
187
- remove(element: T): T | undefined;
188
-
189
- /**
190
- * #### 获取指定元素的索引
191
- * @param element 指定元素
192
- */
193
- indexOf(element: T): number | undefined;
194
-
195
- /**
196
- * 判断数据结构是否为空
197
- */
198
- isEmpty(): boolean;
199
- /**
200
- * 数据结构元素长度
201
- */
202
- size(): number;
203
- /**
204
- * 重写 toString 方法
205
- */
206
- toString(): string;
207
- /**
208
- * 清除数据结构元素
209
- */
210
- clear(): void;
211
- }
152
+ // export class JcNode<T> {
153
+ // value: T;
154
+ // next: JcNode<T> | null;
155
+ // constructor(value: T, next: JcNode<T> | null = null): void;
156
+ // }
157
+
158
+ // export interface ILinkedList<T> {
159
+ // indexOf(element: T): number;
160
+ // getElementAt(index: number): JcNode<T> | null;
161
+ // getValueAt(index: number): T | undefined;
162
+ // insert(element: T, index: number): boolean;
163
+ // push(element: T): void;
164
+ // remove(element: T): T | null;
165
+ // removeAt(index: number): T | null;
166
+ // isEmpty(): boolean;
167
+ // size(): number;
168
+ // clear(): void;
169
+ // toString(): string;
170
+ // toArray(): T[];
171
+ // [Symbol.iterator](): Iterator<T>;
172
+ // }
173
+
174
+ // export class LinkedList<T> implements ILinkedList<T> {
175
+ // constructor(elements?: T[]);
176
+ // }
177
+
178
+ export type NodeType<T> = JcNode<T>;
179
+ export type ListType<T> = LinkedList<T>;
212
180
 
213
181
  /**
214
182
  * 字典类
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "jc-structure",
3
3
  "private": false,
4
- "version": "0.2.4",
4
+ "version": "0.2.6",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
8
+ "types",
8
9
  "index.d.ts",
9
10
  "README.md",
10
11
  "LICENSE"
@@ -0,0 +1,50 @@
1
+ /**
2
+ * #### 字典接口
3
+ */
4
+ interface IDictionary<K, V> extends Structure {
5
+ /**
6
+ * #### 设置键值对
7
+ * @param key 键
8
+ * @param value 值
9
+ */
10
+ set(key: K, value: V): void;
11
+
12
+ /**
13
+ * #### 删除键值对
14
+ * @param key 键
15
+ */
16
+ remove(key: K): ValuePair<K, V> | undefined;
17
+
18
+ /**
19
+ * #### 判断键是否存在
20
+ * @param key 键
21
+ */
22
+ has(key: K): boolean;
23
+
24
+ /**
25
+ * #### 获取键值对
26
+ * @param key 键
27
+ */
28
+ get(key: K): ValuePair<K, V> | undefined;
29
+
30
+ /**
31
+ * #### 获取键数组
32
+ */
33
+ keys(): Array<K>;
34
+
35
+ /**
36
+ * #### 获取值数组
37
+ */
38
+ values(): Array<V>;
39
+
40
+ /**
41
+ * #### 获取键值对数组
42
+ */
43
+ keyValues(): Array<[K, V]>;
44
+
45
+ /**
46
+ * 遍历键值对
47
+ * @param callbackFunc 回调函数
48
+ */
49
+ forEach(callbackFunc: (key: K, value: V) => boolean | void): void;
50
+ }
@@ -0,0 +1,75 @@
1
+ interface Structure {
2
+ /**
3
+ * 判断数据结构是否为空
4
+ */
5
+ isEmpty(): boolean;
6
+ /**
7
+ * 数据结构元素长度
8
+ */
9
+ size(): number;
10
+ /**
11
+ * 清除数据结构元素
12
+ */
13
+ clear(): void;
14
+ /**
15
+ * 重写 toString 方法
16
+ */
17
+ toString(): string;
18
+ }
19
+
20
+ type CompareResult = -1 | 0 | 1;
21
+
22
+ /**
23
+ * #### 比较函数接口
24
+ */
25
+ interface CompareFn<T> {
26
+ (a: T, b: T): CompareResult;
27
+ }
28
+
29
+ /**
30
+ * #### 对象接口,用于存储数据结构元素,值类型默认为 any
31
+ */
32
+ interface Obj<V = any> {
33
+ [key: string]: V;
34
+ }
35
+
36
+ interface RegExpConstructor {
37
+ /**
38
+ * #### 转义正则表达式中的特殊字符
39
+ * @param str 字符串
40
+ */
41
+ escape(str: string): string;
42
+ }
43
+
44
+ interface Element {
45
+ /**
46
+ * #### 获取最深元素集合中的第一个元素
47
+ */
48
+ readonly firstElement: Element | null;
49
+ /**
50
+ * #### 获取最深元素集合中的最后一个元素
51
+ */
52
+ readonly lastElement: Element | null;
53
+ /**
54
+ * #### 最祖先的匹配元素
55
+ * @param this element
56
+ * @param selector 选择器
57
+ */
58
+ farthest<E extends Element = Element>(this: E, selector: string): E | null;
59
+ }
60
+
61
+ interface Text {
62
+ /**
63
+ * #### 将文本节点包裹在指定标签中
64
+ * @param this Text 该文本节点
65
+ * @param selector 要包裹的元素标签,默认为:'strong'
66
+ * @param text 要包裹的文本,默认为:''
67
+ */
68
+ surround(this: Text, selector?: string, text?: string): HTMLElement | null;
69
+ }
70
+
71
+ interface Array<T> {
72
+ groupBy<K extends string | number | symbol>(
73
+ generateKey: string | ((item: T, index: number, arr: T[]) => K)
74
+ ): Record<K, T[]>;
75
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * #### 图接口
3
+ */
4
+ interface IGraph<T> {
5
+ /**
6
+ * #### 添加顶点的方法
7
+ * @param v 顶点
8
+ */
9
+ addVertex(v: T): void;
10
+ /**
11
+ * #### 添加边的方法
12
+ * @param v 顶点
13
+ * @param w
14
+ */
15
+ addEdge(v: T, w: T): void;
16
+ /**
17
+ * #### 获取顶点集合的方法
18
+ */
19
+ getVertices(): Array<T>;
20
+ /**
21
+ * #### 获取邻接表的方法
22
+ */
23
+ getAdjacencyList(): IDictionary<T, Array<T>>;
24
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * #### 堆
3
+ */
4
+ interface IHeap<T> extends Structure {
5
+ /**
6
+ * #### 插入一个值,返回一个布尔值
7
+ * @param value 要插入的值
8
+ */
9
+ insert(value: T): boolean;
10
+
11
+ /**
12
+ * #### 移除最小值或最大值,返回该值
13
+ */
14
+ extract(): T | undefined;
15
+
16
+ /**
17
+ * 查找一个值
18
+ * @param value 要查找的值
19
+ */
20
+ find(): T | undefined;
21
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./global";
2
+ export * from "./linkedList";
3
+ export * from "./stack";
4
+ export * from "./queue";
@@ -0,0 +1,28 @@
1
+ class JcNode<T> {
2
+ value: T;
3
+ next: JcNode<T> | null;
4
+ constructor(value: T, next: JcNode<T> | null = null): void;
5
+ }
6
+
7
+ /**
8
+ * #### 链表接口
9
+ */
10
+ interface ILinkedList<T> {
11
+ indexOf(element: T): number;
12
+ getElementAt(index: number): JcNode<T> | null;
13
+ getValueAt(index: number): T | undefined;
14
+ insert(element: T, index: number): boolean;
15
+ push(element: T): void;
16
+ remove(element: T): T | null;
17
+ removeAt(index: number): T | null;
18
+ isEmpty(): boolean;
19
+ size(): number;
20
+ clear(): void;
21
+ toString(): string;
22
+ toArray(): T[];
23
+ [Symbol.iterator](): Iterator<T>;
24
+ }
25
+
26
+ class LinkedList<T> implements ILinkedList<T> {
27
+ constructor(elements?: T[]);
28
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * #### 队列接口
3
+ */
4
+ interface IQueue<T> extends Structure {
5
+ /**
6
+ * #### 移除队列头部元素并返回该元素
7
+ */
8
+ dequeue(): T | undefined;
9
+
10
+ /**
11
+ * #### 向队列末尾添加元素
12
+ * @param args 要添加的元素
13
+ */
14
+ enqueue(...args: (T | T[])[]): this;
15
+
16
+ /**
17
+ * #### 返回队列头部元素,但不移除
18
+ */
19
+ front(): T | undefined;
20
+ }
@@ -0,0 +1,11 @@
1
+ interface Point {
2
+ x: number;
3
+ y: number;
4
+ }
5
+ type Coord = Point;
6
+ type Coord3D = Point & { z: number };
7
+
8
+ interface Rect extends Point {
9
+ w: number;
10
+ h: number;
11
+ }
@@ -0,0 +1,24 @@
1
+ interface StructureObj<T> {
2
+ [key: number]: T;
3
+ }
4
+
5
+ /**
6
+ * #### 栈接口
7
+ */
8
+ interface IStack<T> extends Structure {
9
+ /**
10
+ * #### 移除栈顶元素并返回该元素
11
+ */
12
+ pop(): T | undefined;
13
+
14
+ /**
15
+ * #### 添加一个或多个元素
16
+ * @param items
17
+ */
18
+ push(...items: (T | T[])[]): this;
19
+
20
+ /**
21
+ * #### 返回栈顶元素,但不移除
22
+ */
23
+ peek(): T | undefined;
24
+ }
@@ -0,0 +1,20 @@
1
+ interface Vector {
2
+ get dimension(): number;
3
+ get norm(): number;
4
+ getItem(index: number): number;
5
+ normalize(): Vector;
6
+ add(vector: Vector): Vector;
7
+ sub(vector: Vector): Vector;
8
+ mul(scalar: number): Vector;
9
+ dot(vector: Vector): number;
10
+ pos(): Vector;
11
+ neg(): Vector;
12
+ }
13
+
14
+ interface VectorConstructor {
15
+ new (...args: number[]): Vector;
16
+ readonly prototype: Vector;
17
+ zero(dimension: number): Vector;
18
+ }
19
+
20
+ declare var Vector: VectorConstructor;