data-structure-typed 2.0.0 → 2.0.2

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/cjs/data-structures/binary-tree/binary-tree.js +8 -9
  3. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  4. package/dist/cjs/data-structures/graph/abstract-graph.js +14 -14
  5. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  6. package/dist/cjs/data-structures/hash/hash-map.d.ts +46 -0
  7. package/dist/cjs/data-structures/hash/hash-map.js +46 -0
  8. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  9. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +66 -0
  10. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +66 -0
  11. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  12. package/dist/cjs/data-structures/queue/queue.d.ts +47 -0
  13. package/dist/cjs/data-structures/queue/queue.js +47 -0
  14. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  15. package/dist/cjs/data-structures/stack/stack.d.ts +121 -0
  16. package/dist/cjs/data-structures/stack/stack.js +121 -0
  17. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  18. package/dist/cjs/types/utils/utils.d.ts +1 -7
  19. package/dist/cjs/utils/utils.d.ts +3 -49
  20. package/dist/cjs/utils/utils.js +13 -82
  21. package/dist/cjs/utils/utils.js.map +1 -1
  22. package/dist/esm/data-structures/binary-tree/binary-tree.js +8 -9
  23. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -1
  24. package/dist/esm/data-structures/graph/abstract-graph.js +14 -14
  25. package/dist/esm/data-structures/graph/abstract-graph.js.map +1 -1
  26. package/dist/esm/data-structures/hash/hash-map.d.ts +46 -0
  27. package/dist/esm/data-structures/hash/hash-map.js +46 -0
  28. package/dist/esm/data-structures/hash/hash-map.js.map +1 -1
  29. package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +66 -0
  30. package/dist/esm/data-structures/linked-list/singly-linked-list.js +66 -0
  31. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -1
  32. package/dist/esm/data-structures/queue/queue.d.ts +47 -0
  33. package/dist/esm/data-structures/queue/queue.js +47 -0
  34. package/dist/esm/data-structures/queue/queue.js.map +1 -1
  35. package/dist/esm/data-structures/stack/stack.d.ts +121 -0
  36. package/dist/esm/data-structures/stack/stack.js +121 -0
  37. package/dist/esm/data-structures/stack/stack.js.map +1 -1
  38. package/dist/esm/types/utils/utils.d.ts +1 -7
  39. package/dist/esm/utils/utils.d.ts +3 -49
  40. package/dist/esm/utils/utils.js +10 -68
  41. package/dist/esm/utils/utils.js.map +1 -1
  42. package/dist/umd/data-structure-typed.js +32 -80
  43. package/dist/umd/data-structure-typed.min.js +2 -2
  44. package/dist/umd/data-structure-typed.min.js.map +1 -1
  45. package/package.json +2 -2
  46. package/src/data-structures/binary-tree/binary-tree.ts +9 -10
  47. package/src/data-structures/graph/abstract-graph.ts +14 -14
  48. package/src/data-structures/hash/hash-map.ts +46 -0
  49. package/src/data-structures/linked-list/singly-linked-list.ts +66 -0
  50. package/src/data-structures/queue/queue.ts +47 -0
  51. package/src/data-structures/stack/stack.ts +121 -0
  52. package/src/types/utils/utils.ts +1 -6
  53. package/src/utils/utils.ts +11 -83
  54. package/test/unit/data-structures/graph/directed-graph.test.ts +37 -37
  55. package/test/unit/data-structures/graph/undirected-graph.test.ts +2 -2
  56. package/test/unit/data-structures/hash/hash-map.test.ts +135 -0
  57. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +72 -1
  58. package/test/unit/data-structures/queue/queue.test.ts +214 -0
  59. package/test/unit/data-structures/stack/stack.test.ts +165 -0
  60. package/test/unit/utils/utils.test.ts +35 -2
@@ -39,26 +39,6 @@ var dataStructureTyped = (() => {
39
39
  };
40
40
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
41
41
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
42
- var __async = (__this, __arguments, generator) => {
43
- return new Promise((resolve, reject) => {
44
- var fulfilled = (value) => {
45
- try {
46
- step(generator.next(value));
47
- } catch (e) {
48
- reject(e);
49
- }
50
- };
51
- var rejected = (value) => {
52
- try {
53
- step(generator.throw(value));
54
- } catch (e) {
55
- reject(e);
56
- }
57
- };
58
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
59
- step((generator = generator.apply(__this, __arguments)).next());
60
- });
61
- };
62
42
  var __await = function(promise, isYieldStar) {
63
43
  this[0] = promise;
64
44
  this[1] = isYieldStar;
@@ -146,7 +126,6 @@ var dataStructureTyped = (() => {
146
126
  SkipList: () => SkipList,
147
127
  SkipListNode: () => SkipListNode,
148
128
  Stack: () => Stack,
149
- THUNK_SYMBOL: () => THUNK_SYMBOL,
150
129
  TreeCounter: () => TreeCounter,
151
130
  TreeCounterNode: () => TreeCounterNode,
152
131
  TreeMultiMap: () => TreeMultiMap,
@@ -167,9 +146,7 @@ var dataStructureTyped = (() => {
167
146
  roundFixed: () => roundFixed,
168
147
  throwRangeError: () => throwRangeError,
169
148
  toBinaryString: () => toBinaryString,
170
- toThunk: () => toThunk,
171
149
  trampoline: () => trampoline,
172
- trampolineAsync: () => trampolineAsync,
173
150
  uuidV4: () => uuidV4
174
151
  });
175
152
 
@@ -623,41 +600,16 @@ var dataStructureTyped = (() => {
623
600
  }
624
601
  return result;
625
602
  };
626
- var THUNK_SYMBOL = Symbol("thunk");
627
- var isThunk = (fnOrValue) => {
628
- return typeof fnOrValue === "function" && fnOrValue.__THUNK__ === THUNK_SYMBOL;
629
- };
630
- var toThunk = (fn) => {
631
- const thunk = () => fn();
632
- thunk.__THUNK__ = THUNK_SYMBOL;
633
- return thunk;
634
- };
635
- var trampoline = (fn) => {
636
- const cont = (...args) => toThunk(() => fn(...args));
637
- return Object.assign(
638
- (...args) => {
639
- let result = fn(...args);
640
- while (isThunk(result) && typeof result === "function") {
641
- result = result();
642
- }
643
- return result;
644
- },
645
- { cont }
646
- );
647
- };
648
- var trampolineAsync = (fn) => {
649
- const cont = (...args) => toThunk(() => fn(...args));
650
- return Object.assign(
651
- (...args) => __async(void 0, null, function* () {
652
- let result = yield fn(...args);
653
- while (isThunk(result) && typeof result === "function") {
654
- result = yield result();
655
- }
656
- return result;
657
- }),
658
- { cont }
659
- );
660
- };
603
+ function isThunk(result) {
604
+ return typeof result === "function";
605
+ }
606
+ function trampoline(thunk) {
607
+ let result = thunk;
608
+ while (isThunk(result)) {
609
+ result = result();
610
+ }
611
+ return result;
612
+ }
661
613
  var getMSB = (value) => {
662
614
  if (value <= 0) {
663
615
  return 0;
@@ -6256,7 +6208,7 @@ var dataStructureTyped = (() => {
6256
6208
  if (isWeight === void 0) isWeight = false;
6257
6209
  if (isWeight) {
6258
6210
  const allPaths = this.getAllPathsBetween(v1, v2);
6259
- let min = Infinity;
6211
+ let min = Number.MAX_SAFE_INTEGER;
6260
6212
  for (const path of allPaths) {
6261
6213
  min = Math.min(this.getPathSumWeight(path), min);
6262
6214
  }
@@ -6317,7 +6269,7 @@ var dataStructureTyped = (() => {
6317
6269
  if (isWeight) {
6318
6270
  if (isDFS) {
6319
6271
  const allPaths = this.getAllPathsBetween(v1, v2, 1e4);
6320
- let min = Infinity;
6272
+ let min = Number.MAX_SAFE_INTEGER;
6321
6273
  let minIndex = -1;
6322
6274
  let index = 0;
6323
6275
  for (const path of allPaths) {
@@ -6377,7 +6329,7 @@ var dataStructureTyped = (() => {
6377
6329
  * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
6378
6330
  */
6379
6331
  dijkstraWithoutHeap(src, dest = void 0, getMinDist = false, genPaths = false) {
6380
- let minDist = Infinity;
6332
+ let minDist = Number.MAX_SAFE_INTEGER;
6381
6333
  let minDest = void 0;
6382
6334
  let minPath = [];
6383
6335
  const paths = [];
@@ -6392,12 +6344,12 @@ var dataStructureTyped = (() => {
6392
6344
  }
6393
6345
  for (const vertex of vertexMap) {
6394
6346
  const vertexOrKey = vertex[1];
6395
- if (vertexOrKey instanceof AbstractVertex) distMap.set(vertexOrKey, Infinity);
6347
+ if (vertexOrKey instanceof AbstractVertex) distMap.set(vertexOrKey, Number.MAX_SAFE_INTEGER);
6396
6348
  }
6397
6349
  distMap.set(srcVertex, 0);
6398
6350
  preMap.set(srcVertex, void 0);
6399
6351
  const getMinOfNoSeen = () => {
6400
- let min = Infinity;
6352
+ let min = Number.MAX_SAFE_INTEGER;
6401
6353
  let minV = void 0;
6402
6354
  for (const [key, value] of distMap) {
6403
6355
  if (!seen.has(key)) {
@@ -6431,7 +6383,7 @@ var dataStructureTyped = (() => {
6431
6383
  seen.add(cur);
6432
6384
  if (destVertex && destVertex === cur) {
6433
6385
  if (getMinDist) {
6434
- minDist = distMap.get(destVertex) || Infinity;
6386
+ minDist = distMap.get(destVertex) || Number.MAX_SAFE_INTEGER;
6435
6387
  }
6436
6388
  if (genPaths) {
6437
6389
  getPaths(destVertex);
@@ -6490,7 +6442,7 @@ var dataStructureTyped = (() => {
6490
6442
  */
6491
6443
  dijkstra(src, dest = void 0, getMinDist = false, genPaths = false) {
6492
6444
  var _a;
6493
- let minDist = Infinity;
6445
+ let minDist = Number.MAX_SAFE_INTEGER;
6494
6446
  let minDest = void 0;
6495
6447
  let minPath = [];
6496
6448
  const paths = [];
@@ -6503,7 +6455,7 @@ var dataStructureTyped = (() => {
6503
6455
  if (!srcVertex) return void 0;
6504
6456
  for (const vertex of vertexMap) {
6505
6457
  const vertexOrKey = vertex[1];
6506
- if (vertexOrKey instanceof AbstractVertex) distMap.set(vertexOrKey, Infinity);
6458
+ if (vertexOrKey instanceof AbstractVertex) distMap.set(vertexOrKey, Number.MAX_SAFE_INTEGER);
6507
6459
  }
6508
6460
  const heap = new Heap([], { comparator: (a, b) => a.key - b.key });
6509
6461
  heap.add({ key: 0, value: srcVertex });
@@ -6534,7 +6486,7 @@ var dataStructureTyped = (() => {
6534
6486
  seen.add(cur);
6535
6487
  if (destVertex && destVertex === cur) {
6536
6488
  if (getMinDist) {
6537
- minDist = distMap.get(destVertex) || Infinity;
6489
+ minDist = distMap.get(destVertex) || Number.MAX_SAFE_INTEGER;
6538
6490
  }
6539
6491
  if (genPaths) {
6540
6492
  getPaths(destVertex);
@@ -6600,7 +6552,7 @@ var dataStructureTyped = (() => {
6600
6552
  const paths = [];
6601
6553
  const distMap = /* @__PURE__ */ new Map();
6602
6554
  const preMap = /* @__PURE__ */ new Map();
6603
- let min = Infinity;
6555
+ let min = Number.MAX_SAFE_INTEGER;
6604
6556
  let minPath = [];
6605
6557
  let hasNegativeCycle;
6606
6558
  if (scanNegativeCycle) hasNegativeCycle = false;
@@ -6610,7 +6562,7 @@ var dataStructureTyped = (() => {
6610
6562
  const edgeMap = this.edgeSet();
6611
6563
  const numOfEdges = edgeMap.length;
6612
6564
  this._vertexMap.forEach((vertex) => {
6613
- distMap.set(vertex, Infinity);
6565
+ distMap.set(vertex, Number.MAX_SAFE_INTEGER);
6614
6566
  });
6615
6567
  distMap.set(srcVertex, 0);
6616
6568
  for (let i = 1; i < numOfVertices; ++i) {
@@ -6622,7 +6574,7 @@ var dataStructureTyped = (() => {
6622
6574
  const sWeight = distMap.get(s);
6623
6575
  const dWeight = distMap.get(d);
6624
6576
  if (sWeight !== void 0 && dWeight !== void 0) {
6625
- if (distMap.get(s) !== Infinity && sWeight + weight < dWeight) {
6577
+ if (distMap.get(s) !== Number.MAX_SAFE_INTEGER && sWeight + weight < dWeight) {
6626
6578
  distMap.set(d, sWeight + weight);
6627
6579
  if (genPath) preMap.set(d, s);
6628
6580
  }
@@ -6664,7 +6616,7 @@ var dataStructureTyped = (() => {
6664
6616
  const weight = edgeMap[j].weight;
6665
6617
  const sWeight = distMap.get(s);
6666
6618
  if (sWeight) {
6667
- if (sWeight !== Infinity && sWeight + weight < sWeight) hasNegativeCycle = true;
6619
+ if (sWeight !== Number.MAX_SAFE_INTEGER && sWeight + weight < sWeight) hasNegativeCycle = true;
6668
6620
  }
6669
6621
  }
6670
6622
  }
@@ -6712,7 +6664,7 @@ var dataStructureTyped = (() => {
6712
6664
  }
6713
6665
  for (let i = 0; i < n; i++) {
6714
6666
  for (let j = 0; j < n; j++) {
6715
- costs[i][j] = ((_a = this.getEdge(idAndVertices[i][1], idAndVertices[j][1])) == null ? void 0 : _a.weight) || Infinity;
6667
+ costs[i][j] = ((_a = this.getEdge(idAndVertices[i][1], idAndVertices[j][1])) == null ? void 0 : _a.weight) || Number.MAX_SAFE_INTEGER;
6716
6668
  }
6717
6669
  }
6718
6670
  for (let k = 0; k < n; k++) {
@@ -8914,11 +8866,11 @@ var dataStructureTyped = (() => {
8914
8866
  };
8915
8867
  return callback(dfs(startNode));
8916
8868
  } else {
8917
- const dfs = trampoline((cur) => {
8869
+ const dfs = (cur) => {
8918
8870
  if (!this.isRealNode(cur.left)) return cur;
8919
- return dfs.cont(cur.left);
8920
- });
8921
- return callback(dfs(startNode));
8871
+ return () => dfs(cur.left);
8872
+ };
8873
+ return callback(trampoline(() => dfs(startNode)));
8922
8874
  }
8923
8875
  }
8924
8876
  /**
@@ -8954,11 +8906,11 @@ var dataStructureTyped = (() => {
8954
8906
  };
8955
8907
  return callback(dfs(startNode));
8956
8908
  } else {
8957
- const dfs = trampoline((cur) => {
8909
+ const dfs = (cur) => {
8958
8910
  if (!this.isRealNode(cur.right)) return cur;
8959
- return dfs.cont(cur.right);
8960
- });
8961
- return callback(dfs(startNode));
8911
+ return () => dfs(cur.right);
8912
+ };
8913
+ return callback(trampoline(() => dfs(startNode)));
8962
8914
  }
8963
8915
  }
8964
8916
  /**