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.
- package/.idea/modules.xml +1 -1
- package/README.md +197 -2
- package/dist/data-structures/binary-tree/aa-tree.js +5 -2
- package/dist/data-structures/binary-tree/avl-tree.d.ts +1 -5
- package/dist/data-structures/binary-tree/avl-tree.js +93 -46
- package/dist/data-structures/binary-tree/b-tree.js +5 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +14 -13
- package/dist/data-structures/binary-tree/binary-tree.d.ts +20 -32
- package/dist/data-structures/binary-tree/binary-tree.js +480 -370
- package/dist/data-structures/binary-tree/bst.d.ts +4 -8
- package/dist/data-structures/binary-tree/bst.js +152 -107
- package/dist/data-structures/binary-tree/rb-tree.js +5 -2
- package/dist/data-structures/binary-tree/segment-tree.d.ts +3 -3
- package/dist/data-structures/binary-tree/segment-tree.js +91 -61
- package/dist/data-structures/binary-tree/splay-tree.js +5 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -5
- package/dist/data-structures/binary-tree/tree-multiset.js +31 -11
- package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
- package/dist/data-structures/graph/abstract-graph.d.ts +5 -33
- package/dist/data-structures/graph/abstract-graph.js +546 -311
- package/dist/data-structures/graph/directed-graph.d.ts +5 -13
- package/dist/data-structures/graph/directed-graph.js +250 -128
- package/dist/data-structures/graph/undirected-graph.d.ts +4 -3
- package/dist/data-structures/graph/undirected-graph.js +166 -81
- package/dist/data-structures/hash/coordinate-map.d.ts +1 -1
- package/dist/data-structures/hash/coordinate-map.js +38 -20
- package/dist/data-structures/hash/coordinate-set.js +33 -15
- package/dist/data-structures/hash/index.d.ts +5 -0
- package/dist/data-structures/hash/index.js +5 -0
- package/dist/data-structures/heap/heap.d.ts +2 -8
- package/dist/data-structures/heap/heap.js +36 -31
- package/dist/data-structures/heap/max-heap.d.ts +3 -2
- package/dist/data-structures/heap/max-heap.js +27 -9
- package/dist/data-structures/heap/min-heap.d.ts +3 -2
- package/dist/data-structures/heap/min-heap.js +27 -9
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +56 -53
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +8 -12
- package/dist/data-structures/linked-list/singly-linked-list.js +308 -174
- package/dist/data-structures/matrix/matrix.js +8 -7
- package/dist/data-structures/matrix/matrix2d.d.ts +5 -5
- package/dist/data-structures/matrix/matrix2d.js +80 -63
- package/dist/data-structures/matrix/navigator.d.ts +2 -16
- package/dist/data-structures/matrix/navigator.js +37 -18
- package/dist/data-structures/matrix/vector2d.d.ts +18 -18
- package/dist/data-structures/matrix/vector2d.js +117 -94
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +25 -8
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +25 -8
- package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -21
- package/dist/data-structures/priority-queue/priority-queue.js +159 -116
- package/dist/data-structures/queue/deque.js +82 -56
- package/dist/data-structures/queue/queue.d.ts +9 -10
- package/dist/data-structures/queue/queue.js +34 -34
- package/dist/data-structures/stack/stack.d.ts +9 -10
- package/dist/data-structures/stack/stack.js +31 -31
- package/dist/data-structures/trampoline.d.ts +14 -23
- package/dist/data-structures/trampoline.js +103 -25
- package/dist/data-structures/trie/trie.d.ts +13 -3
- package/dist/data-structures/trie/trie.js +234 -80
- package/dist/data-structures/types/abstract-graph.d.ts +29 -0
- package/dist/data-structures/types/abstract-graph.js +2 -0
- package/dist/data-structures/types/avl-tree.d.ts +5 -0
- package/dist/data-structures/types/avl-tree.js +2 -0
- package/dist/data-structures/types/binary-tree.d.ts +16 -0
- package/dist/data-structures/types/binary-tree.js +2 -0
- package/dist/data-structures/types/bst.d.ts +7 -0
- package/dist/data-structures/types/bst.js +2 -0
- package/dist/data-structures/types/directed-graph.d.ts +10 -0
- package/dist/data-structures/types/directed-graph.js +2 -0
- package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
- package/dist/data-structures/types/doubly-linked-list.js +2 -0
- package/dist/data-structures/types/heap.d.ts +7 -0
- package/dist/data-structures/types/heap.js +2 -0
- package/dist/data-structures/types/index.d.ts +13 -0
- package/dist/data-structures/types/index.js +29 -0
- package/dist/data-structures/types/navigator.d.ts +14 -0
- package/dist/data-structures/types/navigator.js +2 -0
- package/dist/data-structures/types/priority-queue.d.ts +7 -0
- package/dist/data-structures/types/priority-queue.js +2 -0
- package/dist/data-structures/types/segment-tree.d.ts +1 -0
- package/dist/data-structures/types/segment-tree.js +2 -0
- package/dist/data-structures/types/singly-linked-list.d.ts +5 -0
- package/dist/data-structures/types/singly-linked-list.js +2 -0
- package/dist/data-structures/types/tree-multiset.d.ts +5 -0
- package/dist/data-structures/types/tree-multiset.js +2 -0
- package/dist/{types → data-structures/types}/utils.d.ts +7 -1
- package/dist/{types → data-structures/types}/utils.js +20 -19
- package/dist/{utils.d.ts → utils/utils.d.ts} +6 -23
- package/dist/utils/utils.js +651 -0
- package/package.json +20 -42
- package/src/data-structures/binary-tree/avl-tree.ts +1 -6
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +4 -4
- package/src/data-structures/binary-tree/binary-tree.ts +184 -139
- package/src/data-structures/binary-tree/bst.ts +15 -24
- 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/segment-tree.ts +20 -12
- package/src/data-structures/binary-tree/tree-multiset.ts +1 -4
- package/src/data-structures/diagrams/README.md +7 -0
- package/src/data-structures/graph/abstract-graph.ts +58 -94
- package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
- package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list.png +0 -0
- package/src/data-structures/graph/diagrams/max-flow.png +0 -0
- package/src/data-structures/graph/diagrams/mst.png +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/directed-graph.ts +12 -28
- package/src/data-structures/graph/undirected-graph.ts +11 -10
- package/src/data-structures/hash/coordinate-map.ts +1 -1
- package/src/data-structures/hash/index.ts +5 -0
- package/src/data-structures/heap/heap.ts +2 -11
- package/src/data-structures/heap/max-heap.ts +3 -2
- package/src/data-structures/heap/min-heap.ts +3 -2
- package/src/data-structures/index.ts +1 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -9
- package/src/data-structures/linked-list/singly-linked-list.ts +18 -32
- package/src/data-structures/matrix/matrix2d.ts +11 -11
- package/src/data-structures/matrix/navigator.ts +2 -14
- package/src/data-structures/matrix/vector2d.ts +52 -52
- package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/priority-queue.ts +70 -78
- package/src/data-structures/queue/deque.ts +2 -2
- package/src/data-structures/queue/queue.ts +12 -13
- package/src/data-structures/stack/stack.ts +12 -13
- package/src/data-structures/trampoline.ts +31 -71
- package/src/data-structures/trie/trie.ts +61 -11
- package/src/data-structures/types/abstract-graph.ts +51 -0
- package/src/data-structures/types/avl-tree.ts +6 -0
- package/src/data-structures/types/binary-tree.ts +15 -0
- package/src/data-structures/types/bst.ts +5 -0
- package/src/data-structures/types/directed-graph.ts +18 -0
- package/src/data-structures/types/doubly-linked-list.ts +1 -0
- package/src/data-structures/types/heap.ts +8 -0
- package/src/data-structures/types/index.ts +13 -0
- package/src/data-structures/types/navigator.ts +12 -0
- package/src/data-structures/types/priority-queue.ts +9 -0
- package/src/data-structures/types/segment-tree.ts +1 -0
- package/src/data-structures/types/singly-linked-list.ts +15 -0
- package/src/data-structures/types/tree-multiset.ts +3 -0
- package/src/{types → data-structures/types}/utils.ts +20 -5
- package/src/utils/index.ts +1 -0
- package/src/{utils.ts → utils/utils.ts} +32 -132
- package/tsconfig.json +9 -6
- package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
- package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
- package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
- package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
- package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
- package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
- package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
- package/dist/types/data-structures/graph/index.d.ts +0 -3
- package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
- package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
- package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
- package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/hash/pair.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +0 -72
- package/dist/types/data-structures/heap/index.d.ts +0 -3
- package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
- package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
- package/dist/types/data-structures/index.d.ts +0 -9
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
- package/dist/types/data-structures/linked-list/index.d.ts +0 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
- package/dist/types/data-structures/matrix/index.d.ts +0 -3
- package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
- package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
- package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
- package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
- package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
- package/dist/types/data-structures/queue/deque.d.ts +0 -37
- package/dist/types/data-structures/queue/index.d.ts +0 -1
- package/dist/types/data-structures/queue/queue.d.ts +0 -76
- package/dist/types/data-structures/stack/index.d.ts +0 -1
- package/dist/types/data-structures/stack/stack.d.ts +0 -69
- package/dist/types/data-structures/trampoline.d.ts +0 -25
- package/dist/types/data-structures/trie/index.d.ts +0 -1
- package/dist/types/data-structures/trie/trie.d.ts +0 -28
- package/dist/types/types/index.d.ts +0 -1
- package/dist/types/types/utils.d.ts +0 -46
- package/dist/utils.js +0 -569
- package/src/types/index.ts +0 -1
- package/src/types/patches/index.d.ts +0 -0
- /package/dist/{types → utils}/index.d.ts +0 -0
- /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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
94
|
+
var edges = [];
|
|
33
95
|
if (v1 !== null && v2 !== null) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (vertex1 &&
|
|
37
|
-
edges = (_a = this._edges.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(e
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
61
|
-
|
|
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
|
-
|
|
66
|
-
|
|
138
|
+
var v1Edges = this._edges.get(vertex1);
|
|
139
|
+
var removed = null;
|
|
67
140
|
if (v1Edges) {
|
|
68
|
-
removed = (0, utils_1.arrayRemove)(v1Edges, e
|
|
141
|
+
removed = (0, utils_1.arrayRemove)(v1Edges, function (e) { return e.vertices.includes(vertex2.id); })[0] || null;
|
|
69
142
|
}
|
|
70
|
-
|
|
143
|
+
var v2Edges = this._edges.get(vertex2);
|
|
71
144
|
if (v2Edges) {
|
|
72
|
-
(0, utils_1.arrayRemove)(v2Edges, e
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 [
|
|
106
|
-
}
|
|
107
|
-
getEdgesOf(vertexOrId) {
|
|
108
|
-
|
|
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
|
-
|
|
116
|
-
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
133
|
-
|
|
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,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.
|
|
4
|
-
class
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
25
|
+
_this._joint = joint;
|
|
26
|
+
return _this;
|
|
10
27
|
}
|
|
11
|
-
has(key) {
|
|
12
|
-
return
|
|
13
|
-
}
|
|
14
|
-
set(key, value) {
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
get(key) {
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
delete(key) {
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
25
|
+
_this._joint = joint;
|
|
26
|
+
return _this;
|
|
10
27
|
}
|
|
11
|
-
has(value) {
|
|
12
|
-
return
|
|
13
|
-
}
|
|
14
|
-
add(value) {
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
delete(value) {
|
|
18
|
-
return
|
|
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;
|
|
@@ -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
|
-
|
|
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
|
|
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
|
|
5
|
+
* @copyright 2021 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT
|
|
7
7
|
*
|
|
8
8
|
* @abstract
|
|
9
9
|
* @class Heap
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
var Heap = /** @class */ (function () {
|
|
12
12
|
/**
|
|
13
13
|
* Creates a priority queue
|
|
14
14
|
* @public
|
|
15
15
|
* @params {object} [options]
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
function Heap(options) {
|
|
18
18
|
if (options) {
|
|
19
|
-
|
|
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)
|
|
23
|
+
this._priorityCb = priority || (function (el) { return +el; });
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
|
-
this._priorityCb = (el)
|
|
26
|
+
this._priorityCb = function (el) { return +el; };
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
2
|
+
* @copyright 2020 Tyler Zeng <zrwusa@gmail.com>
|
|
3
3
|
* @license MIT
|
|
4
4
|
*/
|
|
5
|
-
import { 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
|