data-structure-typed 0.8.18 → 0.9.16

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 (213) hide show
  1. package/.idea/modules.xml +1 -1
  2. package/README.md +197 -2
  3. package/dist/data-structures/binary-tree/aa-tree.js +5 -2
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +1 -5
  5. package/dist/data-structures/binary-tree/avl-tree.js +93 -46
  6. package/dist/data-structures/binary-tree/b-tree.js +5 -2
  7. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -1
  8. package/dist/data-structures/binary-tree/binary-indexed-tree.js +14 -13
  9. package/dist/data-structures/binary-tree/binary-tree.d.ts +20 -32
  10. package/dist/data-structures/binary-tree/binary-tree.js +480 -370
  11. package/dist/data-structures/binary-tree/bst.d.ts +4 -8
  12. package/dist/data-structures/binary-tree/bst.js +152 -107
  13. package/dist/data-structures/binary-tree/rb-tree.js +5 -2
  14. package/dist/data-structures/binary-tree/segment-tree.d.ts +3 -3
  15. package/dist/data-structures/binary-tree/segment-tree.js +91 -61
  16. package/dist/data-structures/binary-tree/splay-tree.js +5 -2
  17. package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -5
  18. package/dist/data-structures/binary-tree/tree-multiset.js +31 -11
  19. package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
  20. package/dist/data-structures/graph/abstract-graph.d.ts +5 -33
  21. package/dist/data-structures/graph/abstract-graph.js +546 -311
  22. package/dist/data-structures/graph/directed-graph.d.ts +5 -13
  23. package/dist/data-structures/graph/directed-graph.js +250 -128
  24. package/dist/data-structures/graph/undirected-graph.d.ts +4 -3
  25. package/dist/data-structures/graph/undirected-graph.js +166 -81
  26. package/dist/data-structures/hash/coordinate-map.d.ts +1 -1
  27. package/dist/data-structures/hash/coordinate-map.js +38 -20
  28. package/dist/data-structures/hash/coordinate-set.js +33 -15
  29. package/dist/data-structures/hash/index.d.ts +5 -0
  30. package/dist/data-structures/hash/index.js +5 -0
  31. package/dist/data-structures/heap/heap.d.ts +2 -8
  32. package/dist/data-structures/heap/heap.js +36 -31
  33. package/dist/data-structures/heap/max-heap.d.ts +3 -2
  34. package/dist/data-structures/heap/max-heap.js +27 -9
  35. package/dist/data-structures/heap/min-heap.d.ts +3 -2
  36. package/dist/data-structures/heap/min-heap.js +27 -9
  37. package/dist/data-structures/index.d.ts +1 -0
  38. package/dist/data-structures/index.js +1 -0
  39. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -1
  40. package/dist/data-structures/linked-list/doubly-linked-list.js +56 -53
  41. package/dist/data-structures/linked-list/singly-linked-list.d.ts +8 -12
  42. package/dist/data-structures/linked-list/singly-linked-list.js +308 -174
  43. package/dist/data-structures/matrix/matrix.js +8 -7
  44. package/dist/data-structures/matrix/matrix2d.d.ts +5 -5
  45. package/dist/data-structures/matrix/matrix2d.js +80 -63
  46. package/dist/data-structures/matrix/navigator.d.ts +2 -16
  47. package/dist/data-structures/matrix/navigator.js +37 -18
  48. package/dist/data-structures/matrix/vector2d.d.ts +18 -18
  49. package/dist/data-structures/matrix/vector2d.js +117 -94
  50. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -2
  51. package/dist/data-structures/priority-queue/max-priority-queue.js +25 -8
  52. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -2
  53. package/dist/data-structures/priority-queue/min-priority-queue.js +25 -8
  54. package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -21
  55. package/dist/data-structures/priority-queue/priority-queue.js +159 -116
  56. package/dist/data-structures/queue/deque.js +82 -56
  57. package/dist/data-structures/queue/queue.d.ts +9 -10
  58. package/dist/data-structures/queue/queue.js +34 -34
  59. package/dist/data-structures/stack/stack.d.ts +9 -10
  60. package/dist/data-structures/stack/stack.js +31 -31
  61. package/dist/data-structures/trampoline.d.ts +14 -23
  62. package/dist/data-structures/trampoline.js +103 -25
  63. package/dist/data-structures/trie/trie.d.ts +13 -3
  64. package/dist/data-structures/trie/trie.js +234 -80
  65. package/dist/data-structures/types/abstract-graph.d.ts +29 -0
  66. package/dist/data-structures/types/abstract-graph.js +2 -0
  67. package/dist/data-structures/types/avl-tree.d.ts +5 -0
  68. package/dist/data-structures/types/avl-tree.js +2 -0
  69. package/dist/data-structures/types/binary-tree.d.ts +16 -0
  70. package/dist/data-structures/types/binary-tree.js +2 -0
  71. package/dist/data-structures/types/bst.d.ts +7 -0
  72. package/dist/data-structures/types/bst.js +2 -0
  73. package/dist/data-structures/types/directed-graph.d.ts +10 -0
  74. package/dist/data-structures/types/directed-graph.js +2 -0
  75. package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
  76. package/dist/data-structures/types/doubly-linked-list.js +2 -0
  77. package/dist/data-structures/types/heap.d.ts +7 -0
  78. package/dist/data-structures/types/heap.js +2 -0
  79. package/dist/data-structures/types/index.d.ts +13 -0
  80. package/dist/data-structures/types/index.js +29 -0
  81. package/dist/data-structures/types/navigator.d.ts +14 -0
  82. package/dist/data-structures/types/navigator.js +2 -0
  83. package/dist/data-structures/types/priority-queue.d.ts +7 -0
  84. package/dist/data-structures/types/priority-queue.js +2 -0
  85. package/dist/data-structures/types/segment-tree.d.ts +1 -0
  86. package/dist/data-structures/types/segment-tree.js +2 -0
  87. package/dist/data-structures/types/singly-linked-list.d.ts +5 -0
  88. package/dist/data-structures/types/singly-linked-list.js +2 -0
  89. package/dist/data-structures/types/tree-multiset.d.ts +5 -0
  90. package/dist/data-structures/types/tree-multiset.js +2 -0
  91. package/dist/{types → data-structures/types}/utils.d.ts +7 -1
  92. package/dist/{types → data-structures/types}/utils.js +20 -19
  93. package/dist/{utils.d.ts → utils/utils.d.ts} +6 -23
  94. package/dist/utils/utils.js +651 -0
  95. package/package.json +20 -42
  96. package/src/data-structures/binary-tree/avl-tree.ts +1 -6
  97. package/src/data-structures/binary-tree/binary-indexed-tree.ts +4 -4
  98. package/src/data-structures/binary-tree/binary-tree.ts +184 -139
  99. package/src/data-structures/binary-tree/bst.ts +15 -24
  100. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  101. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  102. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  103. package/src/data-structures/binary-tree/segment-tree.ts +20 -12
  104. package/src/data-structures/binary-tree/tree-multiset.ts +1 -4
  105. package/src/data-structures/diagrams/README.md +7 -0
  106. package/src/data-structures/graph/abstract-graph.ts +58 -94
  107. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
  108. package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
  109. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
  110. package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
  111. package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
  112. package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
  113. package/src/data-structures/graph/diagrams/edge-list.png +0 -0
  114. package/src/data-structures/graph/diagrams/max-flow.png +0 -0
  115. package/src/data-structures/graph/diagrams/mst.png +0 -0
  116. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  117. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  118. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  119. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  120. package/src/data-structures/graph/directed-graph.ts +12 -28
  121. package/src/data-structures/graph/undirected-graph.ts +11 -10
  122. package/src/data-structures/hash/coordinate-map.ts +1 -1
  123. package/src/data-structures/hash/index.ts +5 -0
  124. package/src/data-structures/heap/heap.ts +2 -11
  125. package/src/data-structures/heap/max-heap.ts +3 -2
  126. package/src/data-structures/heap/min-heap.ts +3 -2
  127. package/src/data-structures/index.ts +1 -0
  128. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -9
  129. package/src/data-structures/linked-list/singly-linked-list.ts +18 -32
  130. package/src/data-structures/matrix/matrix2d.ts +11 -11
  131. package/src/data-structures/matrix/navigator.ts +2 -14
  132. package/src/data-structures/matrix/vector2d.ts +52 -52
  133. package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
  134. package/src/data-structures/priority-queue/min-priority-queue.ts +4 -3
  135. package/src/data-structures/priority-queue/priority-queue.ts +70 -78
  136. package/src/data-structures/queue/deque.ts +2 -2
  137. package/src/data-structures/queue/queue.ts +12 -13
  138. package/src/data-structures/stack/stack.ts +12 -13
  139. package/src/data-structures/trampoline.ts +31 -71
  140. package/src/data-structures/trie/trie.ts +61 -11
  141. package/src/data-structures/types/abstract-graph.ts +51 -0
  142. package/src/data-structures/types/avl-tree.ts +6 -0
  143. package/src/data-structures/types/binary-tree.ts +15 -0
  144. package/src/data-structures/types/bst.ts +5 -0
  145. package/src/data-structures/types/directed-graph.ts +18 -0
  146. package/src/data-structures/types/doubly-linked-list.ts +1 -0
  147. package/src/data-structures/types/heap.ts +8 -0
  148. package/src/data-structures/types/index.ts +13 -0
  149. package/src/data-structures/types/navigator.ts +12 -0
  150. package/src/data-structures/types/priority-queue.ts +9 -0
  151. package/src/data-structures/types/segment-tree.ts +1 -0
  152. package/src/data-structures/types/singly-linked-list.ts +15 -0
  153. package/src/data-structures/types/tree-multiset.ts +3 -0
  154. package/src/{types → data-structures/types}/utils.ts +20 -5
  155. package/src/utils/index.ts +1 -0
  156. package/src/{utils.ts → utils/utils.ts} +32 -132
  157. package/tsconfig.json +9 -6
  158. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  159. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  160. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  161. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  162. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  163. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  164. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  165. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  166. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  167. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  168. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  169. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  170. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  171. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  172. package/dist/types/data-structures/graph/index.d.ts +0 -3
  173. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  174. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  175. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  176. package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
  177. package/dist/types/data-structures/hash/index.d.ts +0 -1
  178. package/dist/types/data-structures/hash/pair.d.ts +0 -1
  179. package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
  180. package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
  181. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  182. package/dist/types/data-structures/heap/index.d.ts +0 -3
  183. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  184. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  185. package/dist/types/data-structures/index.d.ts +0 -9
  186. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  187. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  188. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  189. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
  190. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  191. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  192. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  193. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  194. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  195. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  196. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  197. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  198. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  199. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  200. package/dist/types/data-structures/queue/index.d.ts +0 -1
  201. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  202. package/dist/types/data-structures/stack/index.d.ts +0 -1
  203. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  204. package/dist/types/data-structures/trampoline.d.ts +0 -25
  205. package/dist/types/data-structures/trie/index.d.ts +0 -1
  206. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  207. package/dist/types/types/index.d.ts +0 -1
  208. package/dist/types/types/utils.d.ts +0 -46
  209. package/dist/utils.js +0 -569
  210. package/src/types/index.ts +0 -1
  211. package/src/types/patches/index.d.ts +0 -0
  212. /package/dist/{types → utils}/index.d.ts +0 -0
  213. /package/dist/{types → utils}/index.js +0 -0
@@ -1,142 +1,227 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __values = (this && this.__values) || function(o) {
18
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
19
+ if (m) return m.call(o);
20
+ if (o && typeof o.length === "number") return {
21
+ next: function () {
22
+ if (o && i >= o.length) o = void 0;
23
+ return { value: o && o[i++], done: !o };
24
+ }
25
+ };
26
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
27
+ };
28
+ var __read = (this && this.__read) || function (o, n) {
29
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
30
+ if (!m) return o;
31
+ var i = m.call(o), r, ar = [], e;
32
+ try {
33
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
34
+ }
35
+ catch (error) { e = { error: error }; }
36
+ finally {
37
+ try {
38
+ if (r && !r.done && (m = i["return"])) m.call(i);
39
+ }
40
+ finally { if (e) throw e.error; }
41
+ }
42
+ return ar;
43
+ };
44
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
45
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
46
+ if (ar || !(i in from)) {
47
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
48
+ ar[i] = from[i];
49
+ }
50
+ }
51
+ return to.concat(ar || Array.prototype.slice.call(from));
52
+ };
2
53
  Object.defineProperty(exports, "__esModule", { value: true });
3
54
  exports.UndirectedGraph = exports.UndirectedEdge = exports.UndirectedVertex = void 0;
4
- const utils_1 = require("../../utils");
5
- const abstract_graph_1 = require("./abstract-graph");
6
- class UndirectedVertex extends abstract_graph_1.AbstractVertex {
7
- constructor(id) {
8
- super(id);
55
+ var utils_1 = require("../../utils");
56
+ var abstract_graph_1 = require("./abstract-graph");
57
+ var UndirectedVertex = /** @class */ (function (_super) {
58
+ __extends(UndirectedVertex, _super);
59
+ function UndirectedVertex(id) {
60
+ return _super.call(this, id) || this;
9
61
  }
10
- }
62
+ return UndirectedVertex;
63
+ }(abstract_graph_1.AbstractVertex));
11
64
  exports.UndirectedVertex = UndirectedVertex;
12
- class UndirectedEdge extends abstract_graph_1.AbstractEdge {
13
- get vertices() {
14
- return this._vertices;
65
+ var UndirectedEdge = /** @class */ (function (_super) {
66
+ __extends(UndirectedEdge, _super);
67
+ function UndirectedEdge(v1, v2, weight) {
68
+ var _this = _super.call(this, weight) || this;
69
+ _this._vertices = [v1, v2];
70
+ return _this;
15
71
  }
16
- set vertices(v) {
17
- this._vertices = v;
18
- }
19
- constructor(v1, v2, weight) {
20
- super(weight);
21
- this._vertices = [v1, v2];
22
- }
23
- }
72
+ Object.defineProperty(UndirectedEdge.prototype, "vertices", {
73
+ get: function () {
74
+ return this._vertices;
75
+ },
76
+ set: function (v) {
77
+ this._vertices = v;
78
+ },
79
+ enumerable: false,
80
+ configurable: true
81
+ });
82
+ return UndirectedEdge;
83
+ }(abstract_graph_1.AbstractEdge));
24
84
  exports.UndirectedEdge = UndirectedEdge;
25
- class UndirectedGraph extends abstract_graph_1.AbstractGraph {
26
- constructor() {
27
- super();
28
- this._edges = new Map();
85
+ var UndirectedGraph = /** @class */ (function (_super) {
86
+ __extends(UndirectedGraph, _super);
87
+ function UndirectedGraph() {
88
+ var _this = _super.call(this) || this;
89
+ _this._edges = new Map();
90
+ return _this;
29
91
  }
30
- getEdge(v1, v2) {
92
+ UndirectedGraph.prototype.getEdge = function (v1, v2) {
31
93
  var _a;
32
- let edges = [];
94
+ var edges = [];
33
95
  if (v1 !== null && v2 !== null) {
34
- const vertex1 = this.getVertex(v1);
35
- const vertex2 = this.getVertex(v2);
36
- if (vertex1 && vertex2) {
37
- edges = (_a = this._edges.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(e => e.vertices.includes(vertex2.id));
96
+ var vertex1 = this.getVertex(v1);
97
+ var vertex2_1 = this.getVertex(v2);
98
+ if (vertex1 && vertex2_1) {
99
+ edges = (_a = this._edges.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(function (e) { return e.vertices.includes(vertex2_1.id); });
38
100
  }
39
101
  }
40
102
  return edges ? edges[0] || null : null;
41
- }
42
- addEdge(edge) {
43
- for (const end of edge.vertices) {
44
- const endVertex = this.getVertex(end);
45
- if (endVertex === null)
46
- return false;
47
- if (endVertex) {
48
- const edges = this._edges.get(endVertex);
49
- if (edges) {
50
- edges.push(edge);
51
- }
52
- else {
53
- this._edges.set(endVertex, [edge]);
103
+ };
104
+ UndirectedGraph.prototype.addEdge = function (edge) {
105
+ var e_1, _a;
106
+ try {
107
+ for (var _b = __values(edge.vertices), _c = _b.next(); !_c.done; _c = _b.next()) {
108
+ var end = _c.value;
109
+ var endVertex = this.getVertex(end);
110
+ if (endVertex === null)
111
+ return false;
112
+ if (endVertex) {
113
+ var edges = this._edges.get(endVertex);
114
+ if (edges) {
115
+ edges.push(edge);
116
+ }
117
+ else {
118
+ this._edges.set(endVertex, [edge]);
119
+ }
54
120
  }
55
121
  }
56
122
  }
123
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
124
+ finally {
125
+ try {
126
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
127
+ }
128
+ finally { if (e_1) throw e_1.error; }
129
+ }
57
130
  return true;
58
- }
59
- removeEdgeBetween(v1, v2) {
60
- const vertex1 = this.getVertex(v1);
61
- const vertex2 = this.getVertex(v2);
131
+ };
132
+ UndirectedGraph.prototype.removeEdgeBetween = function (v1, v2) {
133
+ var vertex1 = this.getVertex(v1);
134
+ var vertex2 = this.getVertex(v2);
62
135
  if (!vertex1 || !vertex2) {
63
136
  return null;
64
137
  }
65
- const v1Edges = this._edges.get(vertex1);
66
- let removed = null;
138
+ var v1Edges = this._edges.get(vertex1);
139
+ var removed = null;
67
140
  if (v1Edges) {
68
- removed = (0, utils_1.arrayRemove)(v1Edges, e => e.vertices.includes(vertex2.id))[0] || null;
141
+ removed = (0, utils_1.arrayRemove)(v1Edges, function (e) { return e.vertices.includes(vertex2.id); })[0] || null;
69
142
  }
70
- const v2Edges = this._edges.get(vertex2);
143
+ var v2Edges = this._edges.get(vertex2);
71
144
  if (v2Edges) {
72
- (0, utils_1.arrayRemove)(v2Edges, e => e.vertices.includes(vertex1.id));
145
+ (0, utils_1.arrayRemove)(v2Edges, function (e) { return e.vertices.includes(vertex1.id); });
73
146
  }
74
147
  return removed;
75
- }
76
- removeEdge(edge) {
148
+ };
149
+ UndirectedGraph.prototype.removeEdge = function (edge) {
77
150
  return this.removeEdgeBetween(edge.vertices[0], edge.vertices[1]);
78
- }
79
- degreeOf(vertexOrId) {
151
+ };
152
+ UndirectedGraph.prototype.degreeOf = function (vertexOrId) {
80
153
  var _a;
81
- const vertex = this.getVertex(vertexOrId);
154
+ var vertex = this.getVertex(vertexOrId);
82
155
  if (vertex) {
83
156
  return ((_a = this._edges.get(vertex)) === null || _a === void 0 ? void 0 : _a.length) || 0;
84
157
  }
85
158
  else {
86
159
  return 0;
87
160
  }
88
- }
89
- edgesOf(vertexOrId) {
90
- const vertex = this.getVertex(vertexOrId);
161
+ };
162
+ UndirectedGraph.prototype.edgesOf = function (vertexOrId) {
163
+ var vertex = this.getVertex(vertexOrId);
91
164
  if (vertex) {
92
165
  return this._edges.get(vertex) || [];
93
166
  }
94
167
  else {
95
168
  return [];
96
169
  }
97
- }
98
- edgeSet() {
99
- const edgeSet = new Set();
100
- this._edges.forEach(edges => {
101
- edges.forEach(edge => {
170
+ };
171
+ UndirectedGraph.prototype.edgeSet = function () {
172
+ var edgeSet = new Set();
173
+ this._edges.forEach(function (edges) {
174
+ edges.forEach(function (edge) {
102
175
  edgeSet.add(edge);
103
176
  });
104
177
  });
105
- return [...edgeSet];
106
- }
107
- getEdgesOf(vertexOrId) {
108
- const vertex = this.getVertex(vertexOrId);
178
+ return __spreadArray([], __read(edgeSet), false);
179
+ };
180
+ UndirectedGraph.prototype.getEdgesOf = function (vertexOrId) {
181
+ var vertex = this.getVertex(vertexOrId);
109
182
  if (!vertex) {
110
183
  return [];
111
184
  }
112
185
  return this._edges.get(vertex) || [];
113
- }
114
- getNeighbors(vertexOrId) {
115
- const neighbors = [];
116
- const vertex = this.getVertex(vertexOrId);
186
+ };
187
+ UndirectedGraph.prototype.getNeighbors = function (vertexOrId) {
188
+ var e_2, _a;
189
+ var neighbors = [];
190
+ var vertex = this.getVertex(vertexOrId);
117
191
  if (vertex) {
118
- const neighborEdges = this.getEdgesOf(vertex);
119
- for (const edge of neighborEdges) {
120
- const neighbor = this.getVertex(edge.vertices.filter(e => e !== vertex.id)[0]);
121
- if (neighbor) {
122
- neighbors.push(neighbor);
192
+ var neighborEdges = this.getEdgesOf(vertex);
193
+ try {
194
+ for (var neighborEdges_1 = __values(neighborEdges), neighborEdges_1_1 = neighborEdges_1.next(); !neighborEdges_1_1.done; neighborEdges_1_1 = neighborEdges_1.next()) {
195
+ var edge = neighborEdges_1_1.value;
196
+ var neighbor = this.getVertex(edge.vertices.filter(function (e) { return e !== vertex.id; })[0]);
197
+ if (neighbor) {
198
+ neighbors.push(neighbor);
199
+ }
200
+ }
201
+ }
202
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
203
+ finally {
204
+ try {
205
+ if (neighborEdges_1_1 && !neighborEdges_1_1.done && (_a = neighborEdges_1.return)) _a.call(neighborEdges_1);
123
206
  }
207
+ finally { if (e_2) throw e_2.error; }
124
208
  }
125
209
  }
126
210
  return neighbors;
127
- }
128
- getEndsOfEdge(edge) {
211
+ };
212
+ UndirectedGraph.prototype.getEndsOfEdge = function (edge) {
129
213
  if (!this.containsEdge(edge.vertices[0], edge.vertices[1])) {
130
214
  return null;
131
215
  }
132
- const v1 = this.getVertex(edge.vertices[0]);
133
- const v2 = this.getVertex(edge.vertices[1]);
216
+ var v1 = this.getVertex(edge.vertices[0]);
217
+ var v2 = this.getVertex(edge.vertices[1]);
134
218
  if (v1 && v2) {
135
219
  return [v1, v2];
136
220
  }
137
221
  else {
138
222
  return null;
139
223
  }
140
- }
141
- }
224
+ };
225
+ return UndirectedGraph;
226
+ }(abstract_graph_1.AbstractGraph));
142
227
  exports.UndirectedGraph = UndirectedGraph;
@@ -1,4 +1,4 @@
1
- export declare class CoordinateSet<V> extends Map<any, V> {
1
+ export declare class CoordinateMap<V> extends Map<any, V> {
2
2
  private readonly _joint;
3
3
  constructor(joint?: string);
4
4
  has(key: number[]): boolean;
@@ -1,24 +1,42 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CoordinateSet = void 0;
4
- class CoordinateSet extends Map {
5
- constructor(joint) {
6
- super();
7
- this._joint = '_';
18
+ exports.CoordinateMap = void 0;
19
+ var CoordinateMap = /** @class */ (function (_super) {
20
+ __extends(CoordinateMap, _super);
21
+ function CoordinateMap(joint) {
22
+ var _this = _super.call(this) || this;
23
+ _this._joint = '_';
8
24
  if (joint !== undefined)
9
- this._joint = joint;
25
+ _this._joint = joint;
26
+ return _this;
10
27
  }
11
- has(key) {
12
- return super.has(key.join(this._joint));
13
- }
14
- set(key, value) {
15
- return super.set(key.join(this._joint), value);
16
- }
17
- get(key) {
18
- return super.get(key.join(this._joint));
19
- }
20
- delete(key) {
21
- return super.delete(key.join(this._joint));
22
- }
23
- }
24
- exports.CoordinateSet = CoordinateSet;
28
+ CoordinateMap.prototype.has = function (key) {
29
+ return _super.prototype.has.call(this, key.join(this._joint));
30
+ };
31
+ CoordinateMap.prototype.set = function (key, value) {
32
+ return _super.prototype.set.call(this, key.join(this._joint), value);
33
+ };
34
+ CoordinateMap.prototype.get = function (key) {
35
+ return _super.prototype.get.call(this, key.join(this._joint));
36
+ };
37
+ CoordinateMap.prototype.delete = function (key) {
38
+ return _super.prototype.delete.call(this, key.join(this._joint));
39
+ };
40
+ return CoordinateMap;
41
+ }(Map));
42
+ exports.CoordinateMap = CoordinateMap;
@@ -1,21 +1,39 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.CoordinateSet = void 0;
4
- class CoordinateSet extends Set {
5
- constructor(joint) {
6
- super();
7
- this._joint = '_';
19
+ var CoordinateSet = /** @class */ (function (_super) {
20
+ __extends(CoordinateSet, _super);
21
+ function CoordinateSet(joint) {
22
+ var _this = _super.call(this) || this;
23
+ _this._joint = '_';
8
24
  if (joint !== undefined)
9
- this._joint = joint;
25
+ _this._joint = joint;
26
+ return _this;
10
27
  }
11
- has(value) {
12
- return super.has(value.join(this._joint));
13
- }
14
- add(value) {
15
- return super.add(value.join(this._joint));
16
- }
17
- delete(value) {
18
- return super.delete(value.join(this._joint));
19
- }
20
- }
28
+ CoordinateSet.prototype.has = function (value) {
29
+ return _super.prototype.has.call(this, value.join(this._joint));
30
+ };
31
+ CoordinateSet.prototype.add = function (value) {
32
+ return _super.prototype.add.call(this, value.join(this._joint));
33
+ };
34
+ CoordinateSet.prototype.delete = function (value) {
35
+ return _super.prototype.delete.call(this, value.join(this._joint));
36
+ };
37
+ return CoordinateSet;
38
+ }(Set));
21
39
  exports.CoordinateSet = CoordinateSet;
@@ -1 +1,6 @@
1
1
  export * from './hash-table';
2
+ export * from './coordinate-map';
3
+ export * from './coordinate-set';
4
+ export * from './pair';
5
+ export * from './tree-map';
6
+ export * from './tree-set';
@@ -15,3 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./hash-table"), exports);
18
+ __exportStar(require("./coordinate-map"), exports);
19
+ __exportStar(require("./coordinate-set"), exports);
20
+ __exportStar(require("./pair"), exports);
21
+ __exportStar(require("./tree-map"), exports);
22
+ __exportStar(require("./tree-set"), exports);
@@ -1,13 +1,7 @@
1
1
  import { PriorityQueue } from '../priority-queue';
2
- export interface HeapOptions<T> {
3
- priority?: (element: T) => number;
4
- }
5
- export interface HeapItem<T> {
6
- priority: number;
7
- element: T | null;
8
- }
2
+ import type { HeapItem, HeapOptions } from '../types';
9
3
  /**
10
- * @copyright 2021 Pablo Rios <zrwusa@gmail.com>
4
+ * @copyright 2021 Tyler Zeng <zrwusa@gmail.com>
11
5
  * @license MIT
12
6
  *
13
7
  * @abstract
@@ -2,60 +2,64 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Heap = void 0;
4
4
  /**
5
- * @copyright 2021 Pablo Rios <zrwusa@gmail.com>
5
+ * @copyright 2021 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT
7
7
  *
8
8
  * @abstract
9
9
  * @class Heap
10
10
  */
11
- class Heap {
11
+ var Heap = /** @class */ (function () {
12
12
  /**
13
13
  * Creates a priority queue
14
14
  * @public
15
15
  * @params {object} [options]
16
16
  */
17
- constructor(options) {
17
+ function Heap(options) {
18
18
  if (options) {
19
- const { priority } = options;
19
+ var priority = options.priority;
20
20
  if (priority !== undefined && typeof priority !== 'function') {
21
21
  throw new Error('.constructor expects a valid priority function');
22
22
  }
23
- this._priorityCb = priority || ((el) => +el);
23
+ this._priorityCb = priority || (function (el) { return +el; });
24
24
  }
25
25
  else {
26
- this._priorityCb = (el) => +el;
26
+ this._priorityCb = function (el) { return +el; };
27
27
  }
28
28
  }
29
- /**
30
- * @public
31
- * @returns {number}
32
- */
33
- get size() {
34
- return this._pq.size;
35
- }
29
+ Object.defineProperty(Heap.prototype, "size", {
30
+ /**
31
+ * @public
32
+ * @returns {number}
33
+ */
34
+ get: function () {
35
+ return this._pq.size;
36
+ },
37
+ enumerable: false,
38
+ configurable: true
39
+ });
36
40
  /**
37
41
  * @public
38
42
  * @returns {boolean}
39
43
  */
40
- isEmpty() {
44
+ Heap.prototype.isEmpty = function () {
41
45
  return this._pq.size < 1;
42
- }
46
+ };
43
47
  /**
44
48
  * Returns an element with highest priority in the queue
45
49
  * @public
46
50
  * @returns {object}
47
51
  */
48
- peek() {
52
+ Heap.prototype.peek = function () {
49
53
  return this._pq.peek();
50
- }
54
+ };
51
55
  /**
52
56
  * Returns an element with lowest priority in the queue
53
57
  * @public
54
58
  * @returns {object}
55
59
  */
56
- peekLast() {
60
+ Heap.prototype.peekLast = function () {
57
61
  return this._pq.leaf();
58
- }
62
+ };
59
63
  /**
60
64
  * Adds an element to the queue
61
65
  * @public
@@ -63,7 +67,7 @@ class Heap {
63
67
  * @param priority
64
68
  * @throws {Error} if priority is not a valid number
65
69
  */
66
- offer(element, priority) {
70
+ Heap.prototype.offer = function (element, priority) {
67
71
  if (typeof element === 'number') {
68
72
  priority = element;
69
73
  }
@@ -79,36 +83,37 @@ class Heap {
79
83
  throw new Error('.offer expects a numeric priority '
80
84
  + 'or a constructor callback that returns a number');
81
85
  }
82
- const _priority = !Number.isNaN(+priority) ? priority : this._priorityCb(element);
83
- this._pq.offer({ priority: _priority, element });
86
+ var _priority = !Number.isNaN(+priority) ? priority : this._priorityCb(element);
87
+ this._pq.offer({ priority: _priority, element: element });
84
88
  return this;
85
- }
89
+ };
86
90
  /**
87
91
  * Removes and returns an element with highest priority in the queue
88
92
  * @public
89
93
  * @returns {object}
90
94
  */
91
- poll() {
92
- const top = this._pq.poll();
95
+ Heap.prototype.poll = function () {
96
+ var top = this._pq.poll();
93
97
  if (!top) {
94
98
  return null;
95
99
  }
96
100
  return top;
97
- }
101
+ };
98
102
  /**
99
103
  * Returns a sorted list of elements
100
104
  * @public
101
105
  * @returns {array}
102
106
  */
103
- toArray() {
107
+ Heap.prototype.toArray = function () {
104
108
  return this._pq.toArray();
105
- }
109
+ };
106
110
  /**
107
111
  * Clears the queue
108
112
  * @public
109
113
  */
110
- clear() {
114
+ Heap.prototype.clear = function () {
111
115
  this._pq.clear();
112
- }
113
- }
116
+ };
117
+ return Heap;
118
+ }());
114
119
  exports.Heap = Heap;
@@ -1,9 +1,10 @@
1
1
  /**
2
- * @copyright 2020 Pablo Rios <zrwusa@gmail.com>
2
+ * @copyright 2020 Tyler Zeng <zrwusa@gmail.com>
3
3
  * @license MIT
4
4
  */
5
- import { Heap, HeapItem, HeapOptions } from './heap';
5
+ import { Heap } from './heap';
6
6
  import { PriorityQueue } from '../priority-queue';
7
+ import type { HeapItem, HeapOptions } from '../types';
7
8
  /**
8
9
  * @class MaxHeap
9
10
  * @extends Heap