data-structure-typed 1.19.2 → 1.19.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-structures/binary-tree/aa-tree.js +2 -5
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +361 -488
- package/dist/data-structures/binary-tree/avl-tree.js +46 -90
- package/dist/data-structures/binary-tree/b-tree.js +2 -5
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +17 -22
- package/dist/data-structures/binary-tree/binary-tree.js +9 -31
- package/dist/data-structures/binary-tree/bst.js +96 -139
- package/dist/data-structures/binary-tree/rb-tree.js +32 -56
- package/dist/data-structures/binary-tree/segment-tree.js +78 -120
- package/dist/data-structures/binary-tree/splay-tree.js +2 -5
- package/dist/data-structures/binary-tree/tree-multiset.js +176 -253
- package/dist/data-structures/binary-tree/two-three-tree.js +2 -5
- package/dist/data-structures/graph/abstract-graph.js +340 -574
- package/dist/data-structures/graph/directed-graph.js +146 -276
- package/dist/data-structures/graph/undirected-graph.js +87 -176
- package/dist/data-structures/hash/coordinate-map.js +23 -45
- package/dist/data-structures/hash/coordinate-set.js +20 -42
- package/dist/data-structures/hash/hash-table.js +2 -5
- package/dist/data-structures/hash/pair.js +2 -5
- package/dist/data-structures/hash/tree-map.js +2 -5
- package/dist/data-structures/hash/tree-set.js +2 -5
- package/dist/data-structures/heap/heap.js +53 -77
- package/dist/data-structures/heap/max-heap.js +8 -26
- package/dist/data-structures/heap/min-heap.js +8 -26
- package/dist/data-structures/linked-list/doubly-linked-list.js +132 -197
- package/dist/data-structures/linked-list/singly-linked-list.js +112 -173
- package/dist/data-structures/linked-list/skip-linked-list.js +2 -5
- package/dist/data-structures/matrix/matrix.js +7 -8
- package/dist/data-structures/matrix/matrix2d.js +76 -93
- package/dist/data-structures/matrix/navigator.js +18 -37
- package/dist/data-structures/matrix/vector2d.js +80 -101
- package/dist/data-structures/priority-queue/max-priority-queue.js +11 -39
- package/dist/data-structures/priority-queue/min-priority-queue.js +11 -39
- package/dist/data-structures/priority-queue/priority-queue.js +93 -139
- package/dist/data-structures/queue/deque.js +82 -128
- package/dist/data-structures/queue/queue.js +24 -25
- package/dist/data-structures/stack/stack.js +21 -22
- package/dist/data-structures/tree/tree.js +32 -45
- package/dist/data-structures/trie/trie.js +93 -200
- package/dist/utils/utils.js +22 -107
- package/dist/utils/validate-type.js +2 -2
- package/package.json +1 -1
- package/src/assets/complexities-diff.jpg +0 -0
- package/src/assets/data-structure-complexities.jpg +0 -0
- package/src/assets/logo.png +0 -0
- package/src/assets/overview-diagram-of-data-structures.png +0 -0
- package/src/data-structures/binary-tree/aa-tree.ts +3 -0
- package/src/data-structures/binary-tree/abstract-binary-tree.ts +1528 -0
- package/src/data-structures/binary-tree/avl-tree.ts +297 -0
- package/src/data-structures/binary-tree/b-tree.ts +3 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +78 -0
- package/src/data-structures/binary-tree/binary-tree.ts +40 -0
- package/src/data-structures/binary-tree/bst.ts +435 -0
- package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/src/data-structures/binary-tree/index.ts +12 -0
- package/src/data-structures/binary-tree/rb-tree.ts +102 -0
- package/src/data-structures/binary-tree/segment-tree.ts +243 -0
- package/src/data-structures/binary-tree/splay-tree.ts +3 -0
- package/src/data-structures/binary-tree/tree-multiset.ts +694 -0
- package/src/data-structures/binary-tree/two-three-tree.ts +3 -0
- package/src/data-structures/diagrams/README.md +5 -0
- package/src/data-structures/graph/abstract-graph.ts +1032 -0
- package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
- package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
- package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
- package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
- package/src/data-structures/graph/diagrams/mst.jpg +0 -0
- package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
- package/src/data-structures/graph/directed-graph.ts +472 -0
- package/src/data-structures/graph/index.ts +3 -0
- package/src/data-structures/graph/undirected-graph.ts +270 -0
- package/src/data-structures/hash/coordinate-map.ts +67 -0
- package/src/data-structures/hash/coordinate-set.ts +56 -0
- package/src/data-structures/hash/hash-table.ts +3 -0
- package/src/data-structures/hash/index.ts +6 -0
- package/src/data-structures/hash/pair.ts +3 -0
- package/src/data-structures/hash/tree-map.ts +3 -0
- package/src/data-structures/hash/tree-set.ts +3 -0
- package/src/data-structures/heap/heap.ts +183 -0
- package/src/data-structures/heap/index.ts +3 -0
- package/src/data-structures/heap/max-heap.ts +31 -0
- package/src/data-structures/heap/min-heap.ts +34 -0
- package/src/data-structures/index.ts +15 -0
- package/src/data-structures/interfaces/abstract-binary-tree.ts +231 -0
- package/src/data-structures/interfaces/abstract-graph.ts +40 -0
- package/src/data-structures/interfaces/avl-tree.ts +28 -0
- package/src/data-structures/interfaces/binary-tree.ts +8 -0
- package/src/data-structures/interfaces/bst.ts +32 -0
- package/src/data-structures/interfaces/directed-graph.ts +20 -0
- package/src/data-structures/interfaces/doubly-linked-list.ts +1 -0
- package/src/data-structures/interfaces/heap.ts +1 -0
- package/src/data-structures/interfaces/index.ts +15 -0
- package/src/data-structures/interfaces/navigator.ts +1 -0
- package/src/data-structures/interfaces/priority-queue.ts +1 -0
- package/src/data-structures/interfaces/rb-tree.ts +11 -0
- package/src/data-structures/interfaces/segment-tree.ts +1 -0
- package/src/data-structures/interfaces/singly-linked-list.ts +1 -0
- package/src/data-structures/interfaces/tree-multiset.ts +12 -0
- package/src/data-structures/interfaces/undirected-graph.ts +6 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +573 -0
- package/src/data-structures/linked-list/index.ts +3 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +490 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
- package/src/data-structures/matrix/index.ts +4 -0
- package/src/data-structures/matrix/matrix.ts +27 -0
- package/src/data-structures/matrix/matrix2d.ts +208 -0
- package/src/data-structures/matrix/navigator.ts +122 -0
- package/src/data-structures/matrix/vector2d.ts +316 -0
- package/src/data-structures/priority-queue/index.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +49 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +50 -0
- package/src/data-structures/priority-queue/priority-queue.ts +354 -0
- package/src/data-structures/queue/deque.ts +251 -0
- package/src/data-structures/queue/index.ts +2 -0
- package/src/data-structures/queue/queue.ts +120 -0
- package/src/data-structures/stack/index.ts +1 -0
- package/src/data-structures/stack/stack.ts +98 -0
- package/src/data-structures/tree/index.ts +1 -0
- package/src/data-structures/tree/tree.ts +69 -0
- package/src/data-structures/trie/index.ts +1 -0
- package/src/data-structures/trie/trie.ts +227 -0
- package/src/data-structures/types/abstract-binary-tree.ts +42 -0
- package/src/data-structures/types/abstract-graph.ts +5 -0
- package/src/data-structures/types/avl-tree.ts +5 -0
- package/src/data-structures/types/binary-tree.ts +9 -0
- package/src/data-structures/types/bst.ts +12 -0
- package/src/data-structures/types/directed-graph.ts +8 -0
- package/src/data-structures/types/doubly-linked-list.ts +1 -0
- package/src/data-structures/types/heap.ts +5 -0
- package/src/data-structures/types/helpers.ts +1 -0
- package/src/data-structures/types/index.ts +15 -0
- package/src/data-structures/types/navigator.ts +13 -0
- package/src/data-structures/types/priority-queue.ts +9 -0
- package/src/data-structures/types/rb-tree.ts +8 -0
- package/src/data-structures/types/segment-tree.ts +1 -0
- package/src/data-structures/types/singly-linked-list.ts +1 -0
- package/src/data-structures/types/tree-multiset.ts +8 -0
- package/src/index.ts +2 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/types/index.ts +2 -0
- package/src/utils/types/utils.ts +6 -0
- package/src/utils/types/validate-type.ts +25 -0
- package/src/utils/utils.ts +78 -0
- package/src/utils/validate-type.ts +69 -0
- package/tsconfig.json +1 -1
|
@@ -1,55 +1,4 @@
|
|
|
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 __read = (this && this.__read) || function (o, n) {
|
|
18
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
19
|
-
if (!m) return o;
|
|
20
|
-
var i = m.call(o), r, ar = [], e;
|
|
21
|
-
try {
|
|
22
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
23
|
-
}
|
|
24
|
-
catch (error) { e = { error: error }; }
|
|
25
|
-
finally {
|
|
26
|
-
try {
|
|
27
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
28
|
-
}
|
|
29
|
-
finally { if (e) throw e.error; }
|
|
30
|
-
}
|
|
31
|
-
return ar;
|
|
32
|
-
};
|
|
33
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
34
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
35
|
-
if (ar || !(i in from)) {
|
|
36
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
37
|
-
ar[i] = from[i];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
|
-
};
|
|
42
|
-
var __values = (this && this.__values) || function(o) {
|
|
43
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
44
|
-
if (m) return m.call(o);
|
|
45
|
-
if (o && typeof o.length === "number") return {
|
|
46
|
-
next: function () {
|
|
47
|
-
if (o && i >= o.length) o = void 0;
|
|
48
|
-
return { value: o && o[i++], done: !o };
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
52
|
-
};
|
|
53
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
3
|
exports.UndirectedGraph = exports.UndirectedEdge = exports.UndirectedVertex = void 0;
|
|
55
4
|
/**
|
|
@@ -59,10 +8,9 @@ exports.UndirectedGraph = exports.UndirectedEdge = exports.UndirectedVertex = vo
|
|
|
59
8
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
60
9
|
* @license MIT License
|
|
61
10
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
__extends(UndirectedVertex, _super);
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
|
+
const abstract_graph_1 = require("./abstract-graph");
|
|
13
|
+
class UndirectedVertex extends abstract_graph_1.AbstractVertex {
|
|
66
14
|
/**
|
|
67
15
|
* The constructor function initializes a vertex with an optional value.
|
|
68
16
|
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
|
|
@@ -70,14 +18,12 @@ var UndirectedVertex = /** @class */ (function (_super) {
|
|
|
70
18
|
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
|
|
71
19
|
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
72
20
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
21
|
+
constructor(id, val) {
|
|
22
|
+
super(id, val);
|
|
75
23
|
}
|
|
76
|
-
|
|
77
|
-
}(abstract_graph_1.AbstractVertex));
|
|
24
|
+
}
|
|
78
25
|
exports.UndirectedVertex = UndirectedVertex;
|
|
79
|
-
|
|
80
|
-
__extends(UndirectedEdge, _super);
|
|
26
|
+
class UndirectedEdge extends abstract_graph_1.AbstractEdge {
|
|
81
27
|
/**
|
|
82
28
|
* The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
|
|
83
29
|
* value.
|
|
@@ -88,41 +34,29 @@ var UndirectedEdge = /** @class */ (function (_super) {
|
|
|
88
34
|
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to store a value associated
|
|
89
35
|
* with the edge.
|
|
90
36
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
37
|
+
constructor(v1, v2, weight, val) {
|
|
38
|
+
super(weight, val);
|
|
39
|
+
this._vertices = [v1, v2];
|
|
40
|
+
}
|
|
41
|
+
get vertices() {
|
|
42
|
+
return this._vertices;
|
|
95
43
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
set: function (v) {
|
|
101
|
-
this._vertices = v;
|
|
102
|
-
},
|
|
103
|
-
enumerable: false,
|
|
104
|
-
configurable: true
|
|
105
|
-
});
|
|
106
|
-
return UndirectedEdge;
|
|
107
|
-
}(abstract_graph_1.AbstractEdge));
|
|
44
|
+
set vertices(v) {
|
|
45
|
+
this._vertices = v;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
108
48
|
exports.UndirectedEdge = UndirectedEdge;
|
|
109
|
-
|
|
110
|
-
__extends(UndirectedGraph, _super);
|
|
49
|
+
class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
111
50
|
/**
|
|
112
51
|
* The constructor initializes a new Map object to store edges.
|
|
113
52
|
*/
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
53
|
+
constructor() {
|
|
54
|
+
super();
|
|
55
|
+
this._edges = new Map();
|
|
56
|
+
}
|
|
57
|
+
get edges() {
|
|
58
|
+
return this._edges;
|
|
118
59
|
}
|
|
119
|
-
Object.defineProperty(UndirectedGraph.prototype, "edges", {
|
|
120
|
-
get: function () {
|
|
121
|
-
return this._edges;
|
|
122
|
-
},
|
|
123
|
-
enumerable: false,
|
|
124
|
-
configurable: true
|
|
125
|
-
});
|
|
126
60
|
/**
|
|
127
61
|
* The function creates a new vertex with an optional value and returns it.
|
|
128
62
|
* @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is used to distinguish one
|
|
@@ -132,9 +66,9 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
132
66
|
* the vertex.
|
|
133
67
|
* @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `V`.
|
|
134
68
|
*/
|
|
135
|
-
|
|
69
|
+
createVertex(id, val) {
|
|
136
70
|
return new UndirectedVertex(id, val !== null && val !== void 0 ? val : id);
|
|
137
|
-
}
|
|
71
|
+
}
|
|
138
72
|
/**
|
|
139
73
|
* The function creates an undirected edge between two vertices with an optional weight and value.
|
|
140
74
|
* @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge.
|
|
@@ -145,9 +79,9 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
145
79
|
* is used to store additional information or data associated with the edge.
|
|
146
80
|
* @returns a new instance of the `UndirectedEdge` class, which is casted as type `E`.
|
|
147
81
|
*/
|
|
148
|
-
|
|
82
|
+
createEdge(v1, v2, weight, val) {
|
|
149
83
|
return new UndirectedEdge(v1, v2, weight !== null && weight !== void 0 ? weight : 1, val);
|
|
150
|
-
}
|
|
84
|
+
}
|
|
151
85
|
/**
|
|
152
86
|
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
|
|
153
87
|
* @param {V | null | VertexId} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
|
|
@@ -156,18 +90,18 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
156
90
|
* object), `null`, or `VertexId` (vertex ID).
|
|
157
91
|
* @returns an edge (E) or null.
|
|
158
92
|
*/
|
|
159
|
-
|
|
93
|
+
getEdge(v1, v2) {
|
|
160
94
|
var _a;
|
|
161
|
-
|
|
95
|
+
let edges = [];
|
|
162
96
|
if (v1 !== null && v2 !== null) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (vertex1 &&
|
|
166
|
-
edges = (_a = this._edges.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(
|
|
97
|
+
const vertex1 = this._getVertex(v1);
|
|
98
|
+
const vertex2 = this._getVertex(v2);
|
|
99
|
+
if (vertex1 && vertex2) {
|
|
100
|
+
edges = (_a = this._edges.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(e => e.vertices.includes(vertex2.id));
|
|
167
101
|
}
|
|
168
102
|
}
|
|
169
103
|
return edges ? edges[0] || null : null;
|
|
170
|
-
}
|
|
104
|
+
}
|
|
171
105
|
/**
|
|
172
106
|
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
173
107
|
* @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
|
|
@@ -175,31 +109,31 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
175
109
|
* (VertexId). It represents the second vertex of the edge that needs to be removed.
|
|
176
110
|
* @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
|
|
177
111
|
*/
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
112
|
+
removeEdgeBetween(v1, v2) {
|
|
113
|
+
const vertex1 = this._getVertex(v1);
|
|
114
|
+
const vertex2 = this._getVertex(v2);
|
|
181
115
|
if (!vertex1 || !vertex2) {
|
|
182
116
|
return null;
|
|
183
117
|
}
|
|
184
|
-
|
|
185
|
-
|
|
118
|
+
const v1Edges = this._edges.get(vertex1);
|
|
119
|
+
let removed = null;
|
|
186
120
|
if (v1Edges) {
|
|
187
|
-
removed = (0, utils_1.arrayRemove)(v1Edges,
|
|
121
|
+
removed = (0, utils_1.arrayRemove)(v1Edges, (e) => e.vertices.includes(vertex2.id))[0] || null;
|
|
188
122
|
}
|
|
189
|
-
|
|
123
|
+
const v2Edges = this._edges.get(vertex2);
|
|
190
124
|
if (v2Edges) {
|
|
191
|
-
(0, utils_1.arrayRemove)(v2Edges,
|
|
125
|
+
(0, utils_1.arrayRemove)(v2Edges, (e) => e.vertices.includes(vertex1.id));
|
|
192
126
|
}
|
|
193
127
|
return removed;
|
|
194
|
-
}
|
|
128
|
+
}
|
|
195
129
|
/**
|
|
196
130
|
* The removeEdge function removes an edge between two vertices in a graph.
|
|
197
131
|
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
198
132
|
* @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
|
|
199
133
|
*/
|
|
200
|
-
|
|
134
|
+
removeEdge(edge) {
|
|
201
135
|
return this.removeEdgeBetween(edge.vertices[0], edge.vertices[1]);
|
|
202
|
-
}
|
|
136
|
+
}
|
|
203
137
|
/**
|
|
204
138
|
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
|
|
205
139
|
* vertex.
|
|
@@ -207,75 +141,64 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
207
141
|
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
|
|
208
142
|
* edges connected to that vertex.
|
|
209
143
|
*/
|
|
210
|
-
|
|
144
|
+
degreeOf(vertexOrId) {
|
|
211
145
|
var _a;
|
|
212
|
-
|
|
146
|
+
const vertex = this._getVertex(vertexOrId);
|
|
213
147
|
if (vertex) {
|
|
214
148
|
return ((_a = this._edges.get(vertex)) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
215
149
|
}
|
|
216
150
|
else {
|
|
217
151
|
return 0;
|
|
218
152
|
}
|
|
219
|
-
}
|
|
153
|
+
}
|
|
220
154
|
/**
|
|
221
155
|
* The function returns the edges of a given vertex or vertex ID.
|
|
222
156
|
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`. A `VertexId` is a
|
|
223
157
|
* unique identifier for a vertex in a graph, while `V` represents the type of the vertex.
|
|
224
158
|
* @returns an array of edges.
|
|
225
159
|
*/
|
|
226
|
-
|
|
227
|
-
|
|
160
|
+
edgesOf(vertexOrId) {
|
|
161
|
+
const vertex = this._getVertex(vertexOrId);
|
|
228
162
|
if (vertex) {
|
|
229
163
|
return this._edges.get(vertex) || [];
|
|
230
164
|
}
|
|
231
165
|
else {
|
|
232
166
|
return [];
|
|
233
167
|
}
|
|
234
|
-
}
|
|
168
|
+
}
|
|
235
169
|
/**
|
|
236
170
|
* The function "edgeSet" returns an array of unique edges from a set of edges.
|
|
237
171
|
* @returns The method `edgeSet()` returns an array of type `E[]`.
|
|
238
172
|
*/
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
this._edges.forEach(
|
|
242
|
-
edges.forEach(
|
|
173
|
+
edgeSet() {
|
|
174
|
+
const edgeSet = new Set();
|
|
175
|
+
this._edges.forEach(edges => {
|
|
176
|
+
edges.forEach(edge => {
|
|
243
177
|
edgeSet.add(edge);
|
|
244
178
|
});
|
|
245
179
|
});
|
|
246
|
-
return
|
|
247
|
-
}
|
|
180
|
+
return [...edgeSet];
|
|
181
|
+
}
|
|
248
182
|
/**
|
|
249
183
|
* The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
|
|
250
184
|
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
|
|
251
185
|
* (`VertexId`).
|
|
252
186
|
* @returns an array of vertices (V[]).
|
|
253
187
|
*/
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
var vertex = this._getVertex(vertexOrId);
|
|
188
|
+
getNeighbors(vertexOrId) {
|
|
189
|
+
const neighbors = [];
|
|
190
|
+
const vertex = this._getVertex(vertexOrId);
|
|
258
191
|
if (vertex) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
if (neighbor) {
|
|
265
|
-
neighbors.push(neighbor);
|
|
266
|
-
}
|
|
192
|
+
const neighborEdges = this.edgesOf(vertex);
|
|
193
|
+
for (const edge of neighborEdges) {
|
|
194
|
+
const neighbor = this._getVertex(edge.vertices.filter(e => e !== vertex.id)[0]);
|
|
195
|
+
if (neighbor) {
|
|
196
|
+
neighbors.push(neighbor);
|
|
267
197
|
}
|
|
268
198
|
}
|
|
269
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
270
|
-
finally {
|
|
271
|
-
try {
|
|
272
|
-
if (neighborEdges_1_1 && !neighborEdges_1_1.done && (_a = neighborEdges_1.return)) _a.call(neighborEdges_1);
|
|
273
|
-
}
|
|
274
|
-
finally { if (e_1) throw e_1.error; }
|
|
275
|
-
}
|
|
276
199
|
}
|
|
277
200
|
return neighbors;
|
|
278
|
-
}
|
|
201
|
+
}
|
|
279
202
|
/**
|
|
280
203
|
* The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
|
|
281
204
|
* it returns null.
|
|
@@ -283,59 +206,47 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
283
206
|
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
|
|
284
207
|
* graph. If the edge does not exist, it returns `null`.
|
|
285
208
|
*/
|
|
286
|
-
|
|
209
|
+
getEndsOfEdge(edge) {
|
|
287
210
|
if (!this.hasEdge(edge.vertices[0], edge.vertices[1])) {
|
|
288
211
|
return null;
|
|
289
212
|
}
|
|
290
|
-
|
|
291
|
-
|
|
213
|
+
const v1 = this._getVertex(edge.vertices[0]);
|
|
214
|
+
const v2 = this._getVertex(edge.vertices[1]);
|
|
292
215
|
if (v1 && v2) {
|
|
293
216
|
return [v1, v2];
|
|
294
217
|
}
|
|
295
218
|
else {
|
|
296
219
|
return null;
|
|
297
220
|
}
|
|
298
|
-
}
|
|
221
|
+
}
|
|
299
222
|
/**
|
|
300
223
|
* The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
|
|
301
224
|
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
302
225
|
* @returns a boolean value.
|
|
303
226
|
*/
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
this._edges.set(endVertex, [edge]);
|
|
319
|
-
}
|
|
227
|
+
_addEdgeOnly(edge) {
|
|
228
|
+
for (const end of edge.vertices) {
|
|
229
|
+
const endVertex = this._getVertex(end);
|
|
230
|
+
if (endVertex === null)
|
|
231
|
+
return false;
|
|
232
|
+
if (endVertex) {
|
|
233
|
+
const edges = this._edges.get(endVertex);
|
|
234
|
+
if (edges) {
|
|
235
|
+
edges.push(edge);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
this._edges.set(endVertex, [edge]);
|
|
320
239
|
}
|
|
321
240
|
}
|
|
322
241
|
}
|
|
323
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
324
|
-
finally {
|
|
325
|
-
try {
|
|
326
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
327
|
-
}
|
|
328
|
-
finally { if (e_2) throw e_2.error; }
|
|
329
|
-
}
|
|
330
242
|
return true;
|
|
331
|
-
}
|
|
243
|
+
}
|
|
332
244
|
/**
|
|
333
245
|
* The function sets the edges of a graph.
|
|
334
246
|
* @param v - A map where the keys are of type V and the values are arrays of type E.
|
|
335
247
|
*/
|
|
336
|
-
|
|
248
|
+
_setEdges(v) {
|
|
337
249
|
this._edges = v;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
}(abstract_graph_1.AbstractGraph));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
341
252
|
exports.UndirectedGraph = UndirectedGraph;
|
|
@@ -1,19 +1,4 @@
|
|
|
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.CoordinateMap = void 0;
|
|
19
4
|
/**
|
|
@@ -23,22 +8,16 @@ exports.CoordinateMap = void 0;
|
|
|
23
8
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
24
9
|
* @license MIT License
|
|
25
10
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
_this._joint = '_';
|
|
11
|
+
class CoordinateMap extends Map {
|
|
12
|
+
constructor(joint) {
|
|
13
|
+
super();
|
|
14
|
+
this._joint = '_';
|
|
31
15
|
if (joint !== undefined)
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
this._joint = joint;
|
|
17
|
+
}
|
|
18
|
+
get joint() {
|
|
19
|
+
return this._joint;
|
|
34
20
|
}
|
|
35
|
-
Object.defineProperty(CoordinateMap.prototype, "joint", {
|
|
36
|
-
get: function () {
|
|
37
|
-
return this._joint;
|
|
38
|
-
},
|
|
39
|
-
enumerable: false,
|
|
40
|
-
configurable: true
|
|
41
|
-
});
|
|
42
21
|
/**
|
|
43
22
|
* The "has" function overrides the base class's "has" function and checks if a key exists in the map by joining the
|
|
44
23
|
* key array with a specified delimiter.
|
|
@@ -46,9 +25,9 @@ var CoordinateMap = /** @class */ (function (_super) {
|
|
|
46
25
|
* @returns The `has` method is being overridden to return the result of calling the `has` method of the superclass
|
|
47
26
|
* (`super.has`) with the `key` array joined together using the `_joint` property.
|
|
48
27
|
*/
|
|
49
|
-
|
|
50
|
-
return
|
|
51
|
-
}
|
|
28
|
+
has(key) {
|
|
29
|
+
return super.has(key.join(this._joint));
|
|
30
|
+
}
|
|
52
31
|
/**
|
|
53
32
|
* The function overrides the set method of a Map object to convert the key from an array to a string using a specified
|
|
54
33
|
* delimiter before calling the original set method.
|
|
@@ -57,18 +36,18 @@ var CoordinateMap = /** @class */ (function (_super) {
|
|
|
57
36
|
* @returns The `set` method is returning the result of calling the `set` method of the superclass
|
|
58
37
|
* (`super.set(key.join(this._joint), value)`).
|
|
59
38
|
*/
|
|
60
|
-
|
|
61
|
-
return
|
|
62
|
-
}
|
|
39
|
+
set(key, value) {
|
|
40
|
+
return super.set(key.join(this._joint), value);
|
|
41
|
+
}
|
|
63
42
|
/**
|
|
64
43
|
* The function overrides the get method to join the key array with a specified joint and then calls the super get
|
|
65
44
|
* method.
|
|
66
45
|
* @param {number[]} key - An array of numbers
|
|
67
46
|
* @returns The code is returning the value associated with the specified key in the map.
|
|
68
47
|
*/
|
|
69
|
-
|
|
70
|
-
return
|
|
71
|
-
}
|
|
48
|
+
get(key) {
|
|
49
|
+
return super.get(key.join(this._joint));
|
|
50
|
+
}
|
|
72
51
|
/**
|
|
73
52
|
* The function overrides the delete method and joins the key array using a specified joint character before calling
|
|
74
53
|
* the super delete method.
|
|
@@ -76,12 +55,11 @@ var CoordinateMap = /** @class */ (function (_super) {
|
|
|
76
55
|
* @returns The `delete` method is returning the result of calling the `delete` method on the superclass, with the
|
|
77
56
|
* `key` array joined together using the `_joint` property.
|
|
78
57
|
*/
|
|
79
|
-
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
|
|
58
|
+
delete(key) {
|
|
59
|
+
return super.delete(key.join(this._joint));
|
|
60
|
+
}
|
|
61
|
+
_setJoint(v) {
|
|
83
62
|
this._joint = v;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
}(Map));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
87
65
|
exports.CoordinateMap = CoordinateMap;
|
|
@@ -1,19 +1,4 @@
|
|
|
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.CoordinateSet = void 0;
|
|
19
4
|
/**
|
|
@@ -23,22 +8,16 @@ exports.CoordinateSet = void 0;
|
|
|
23
8
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
24
9
|
* @license MIT License
|
|
25
10
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
_this._joint = '_';
|
|
11
|
+
class CoordinateSet extends Set {
|
|
12
|
+
constructor(joint) {
|
|
13
|
+
super();
|
|
14
|
+
this._joint = '_';
|
|
31
15
|
if (joint !== undefined)
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
this._joint = joint;
|
|
17
|
+
}
|
|
18
|
+
get joint() {
|
|
19
|
+
return this._joint;
|
|
34
20
|
}
|
|
35
|
-
Object.defineProperty(CoordinateSet.prototype, "joint", {
|
|
36
|
-
get: function () {
|
|
37
|
-
return this._joint;
|
|
38
|
-
},
|
|
39
|
-
enumerable: false,
|
|
40
|
-
configurable: true
|
|
41
|
-
});
|
|
42
21
|
/**
|
|
43
22
|
* The "has" function overrides the "has" method of the superclass and checks if a value exists in an array after
|
|
44
23
|
* joining its elements with a specified separator.
|
|
@@ -46,9 +25,9 @@ var CoordinateSet = /** @class */ (function (_super) {
|
|
|
46
25
|
* @returns The overridden `has` method is returning the result of calling the `has` method of the superclass, passing
|
|
47
26
|
* in the joined value as an argument.
|
|
48
27
|
*/
|
|
49
|
-
|
|
50
|
-
return
|
|
51
|
-
}
|
|
28
|
+
has(value) {
|
|
29
|
+
return super.has(value.join(this._joint));
|
|
30
|
+
}
|
|
52
31
|
/**
|
|
53
32
|
* The "add" function overrides the parent class's "add" function by joining the elements of the input array with a
|
|
54
33
|
* specified delimiter before calling the parent class's "add" function.
|
|
@@ -56,9 +35,9 @@ var CoordinateSet = /** @class */ (function (_super) {
|
|
|
56
35
|
* @returns The overridden `add` method is returning the result of calling the `add` method of the superclass
|
|
57
36
|
* (`super.add`) with the joined string representation of the `value` array (`value.join(this._joint)`).
|
|
58
37
|
*/
|
|
59
|
-
|
|
60
|
-
return
|
|
61
|
-
}
|
|
38
|
+
add(value) {
|
|
39
|
+
return super.add(value.join(this._joint));
|
|
40
|
+
}
|
|
62
41
|
/**
|
|
63
42
|
* The function overrides the delete method and deletes an element from a Set by joining the elements of the input
|
|
64
43
|
* array with a specified joint and then calling the delete method of the parent class.
|
|
@@ -66,12 +45,11 @@ var CoordinateSet = /** @class */ (function (_super) {
|
|
|
66
45
|
* @returns The `delete` method is returning the result of calling the `delete` method of the superclass, with the
|
|
67
46
|
* `value` array joined together using the `_joint` property.
|
|
68
47
|
*/
|
|
69
|
-
|
|
70
|
-
return
|
|
71
|
-
}
|
|
72
|
-
|
|
48
|
+
delete(value) {
|
|
49
|
+
return super.delete(value.join(this._joint));
|
|
50
|
+
}
|
|
51
|
+
_setJoint(v) {
|
|
73
52
|
this._joint = v;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
}(Set));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
77
55
|
exports.CoordinateSet = CoordinateSet;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HashTable = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
return HashTable;
|
|
8
|
-
}());
|
|
4
|
+
class HashTable {
|
|
5
|
+
}
|
|
9
6
|
exports.HashTable = HashTable;
|