data-structure-typed 1.19.3 → 1.19.5
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 +3 -2
- 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,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Heap = exports.HeapItem = void 0;
|
|
4
|
-
|
|
4
|
+
class HeapItem {
|
|
5
5
|
/**
|
|
6
6
|
* The constructor function initializes an instance of a class with a priority and a value.
|
|
7
7
|
* @param {number} priority - The `priority` parameter is a number that represents the priority of the value. It is
|
|
@@ -9,99 +9,76 @@ var HeapItem = /** @class */ (function () {
|
|
|
9
9
|
* @param {T | null} [val=null] - The `val` parameter is of type `T | null`, which means it can accept a value of type
|
|
10
10
|
* `T` or `null`.
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
if (priority === void 0) { priority = NaN; }
|
|
14
|
-
if (val === void 0) { val = null; }
|
|
12
|
+
constructor(priority = NaN, val = null) {
|
|
15
13
|
this._val = val;
|
|
16
14
|
this._priority = priority;
|
|
17
15
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
},
|
|
32
|
-
set: function (value) {
|
|
33
|
-
this._val = value;
|
|
34
|
-
},
|
|
35
|
-
enumerable: false,
|
|
36
|
-
configurable: true
|
|
37
|
-
});
|
|
38
|
-
return HeapItem;
|
|
39
|
-
}());
|
|
16
|
+
get priority() {
|
|
17
|
+
return this._priority;
|
|
18
|
+
}
|
|
19
|
+
set priority(value) {
|
|
20
|
+
this._priority = value;
|
|
21
|
+
}
|
|
22
|
+
get val() {
|
|
23
|
+
return this._val;
|
|
24
|
+
}
|
|
25
|
+
set val(value) {
|
|
26
|
+
this._val = value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
40
29
|
exports.HeapItem = HeapItem;
|
|
41
|
-
|
|
30
|
+
class Heap {
|
|
42
31
|
/**
|
|
43
32
|
* The function is a constructor for a class that initializes a priority callback function based on the
|
|
44
33
|
* options provided.
|
|
45
34
|
* @param [options] - An optional object that contains configuration options for the Heap.
|
|
46
35
|
*/
|
|
47
|
-
|
|
36
|
+
constructor(options) {
|
|
48
37
|
if (options) {
|
|
49
|
-
|
|
38
|
+
const { priorityExtractor } = options;
|
|
50
39
|
if (priorityExtractor !== undefined && typeof priorityExtractor !== 'function') {
|
|
51
40
|
throw new Error('.constructor expects a valid priority function');
|
|
52
41
|
}
|
|
53
|
-
this._priorityExtractor = priorityExtractor || (
|
|
42
|
+
this._priorityExtractor = priorityExtractor || ((el) => +el);
|
|
54
43
|
}
|
|
55
44
|
else {
|
|
56
|
-
this._priorityExtractor =
|
|
45
|
+
this._priorityExtractor = (el) => +el;
|
|
57
46
|
}
|
|
58
47
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
73
|
-
Object.defineProperty(Heap.prototype, "size", {
|
|
74
|
-
/**
|
|
75
|
-
* The function returns the size of a priority queue.
|
|
76
|
-
* @returns The size of the priority queue.
|
|
77
|
-
*/
|
|
78
|
-
get: function () {
|
|
79
|
-
return this._pq.size;
|
|
80
|
-
},
|
|
81
|
-
enumerable: false,
|
|
82
|
-
configurable: true
|
|
83
|
-
});
|
|
48
|
+
get pq() {
|
|
49
|
+
return this._pq;
|
|
50
|
+
}
|
|
51
|
+
get priorityExtractor() {
|
|
52
|
+
return this._priorityExtractor;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The function returns the size of a priority queue.
|
|
56
|
+
* @returns The size of the priority queue.
|
|
57
|
+
*/
|
|
58
|
+
get size() {
|
|
59
|
+
return this._pq.size;
|
|
60
|
+
}
|
|
84
61
|
/**
|
|
85
62
|
* The function checks if a priority queue is empty.
|
|
86
63
|
* @returns {boolean} A boolean value indicating whether the size of the priority queue is less than 1.
|
|
87
64
|
*/
|
|
88
|
-
|
|
65
|
+
isEmpty() {
|
|
89
66
|
return this._pq.size < 1;
|
|
90
|
-
}
|
|
67
|
+
}
|
|
91
68
|
/**
|
|
92
69
|
* The `peek` function returns the top item in the priority queue without removing it.
|
|
93
70
|
* @returns The `peek()` method is returning either a `HeapItem<T>` object or `null`.Returns an val with the highest priority in the queue
|
|
94
71
|
*/
|
|
95
|
-
|
|
72
|
+
peek() {
|
|
96
73
|
return this._pq.peek();
|
|
97
|
-
}
|
|
74
|
+
}
|
|
98
75
|
/**
|
|
99
76
|
* The `peekLast` function returns the last item in the heap.
|
|
100
77
|
* @returns The method `peekLast()` returns either a `HeapItem<T>` object or `null`.Returns an val with the lowest priority in the queue
|
|
101
78
|
*/
|
|
102
|
-
|
|
79
|
+
peekLast() {
|
|
103
80
|
return this._pq.leaf();
|
|
104
|
-
}
|
|
81
|
+
}
|
|
105
82
|
/**
|
|
106
83
|
* The `add` function adds an val to a priority queue with an optional priority value.
|
|
107
84
|
* @param {T} val - The `val` parameter represents the value that you want to add to the heap. It can be of any
|
|
@@ -112,7 +89,7 @@ var Heap = /** @class */ (function () {
|
|
|
112
89
|
* @returns The `add` method returns the instance of the `Heap` class.
|
|
113
90
|
* @throws {Error} if priority is not a valid number
|
|
114
91
|
*/
|
|
115
|
-
|
|
92
|
+
add(val, priority) {
|
|
116
93
|
if (typeof val === 'number') {
|
|
117
94
|
priority = val;
|
|
118
95
|
}
|
|
@@ -128,49 +105,48 @@ var Heap = /** @class */ (function () {
|
|
|
128
105
|
throw new Error('.add expects a numeric priority '
|
|
129
106
|
+ 'or a constructor callback that returns a number');
|
|
130
107
|
}
|
|
131
|
-
|
|
108
|
+
const _priority = !Number.isNaN(+priority) ? priority : this._priorityExtractor(val);
|
|
132
109
|
this._pq.add(new HeapItem(_priority, val));
|
|
133
110
|
return this;
|
|
134
|
-
}
|
|
111
|
+
}
|
|
135
112
|
/**
|
|
136
113
|
* The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an val with the highest priority in the queue
|
|
137
114
|
* @returns either a HeapItem<T> object or null.
|
|
138
115
|
*/
|
|
139
|
-
|
|
140
|
-
|
|
116
|
+
poll() {
|
|
117
|
+
const top = this._pq.poll();
|
|
141
118
|
if (!top) {
|
|
142
119
|
return null;
|
|
143
120
|
}
|
|
144
121
|
return top;
|
|
145
|
-
}
|
|
122
|
+
}
|
|
146
123
|
/**
|
|
147
124
|
* The function checks if a given node or value exists in the priority queue.
|
|
148
125
|
* @param {T | HeapItem<T>} node - The parameter `node` can be of type `T` or `HeapItem<T>`.
|
|
149
126
|
* @returns a boolean value.
|
|
150
127
|
*/
|
|
151
|
-
|
|
128
|
+
has(node) {
|
|
152
129
|
if (node instanceof HeapItem) {
|
|
153
130
|
return this.pq.getNodes().includes(node);
|
|
154
131
|
}
|
|
155
132
|
else {
|
|
156
|
-
return this.pq.getNodes().findIndex(
|
|
133
|
+
return this.pq.getNodes().findIndex(item => {
|
|
157
134
|
return item.val === node;
|
|
158
135
|
}) !== -1;
|
|
159
136
|
}
|
|
160
|
-
}
|
|
137
|
+
}
|
|
161
138
|
/**
|
|
162
139
|
* The `toArray` function returns an array of `HeapItem<T>` objects.
|
|
163
140
|
* @returns An array of HeapItem<T> objects.Returns a sorted list of vals
|
|
164
141
|
*/
|
|
165
|
-
|
|
142
|
+
toArray() {
|
|
166
143
|
return this._pq.toArray();
|
|
167
|
-
}
|
|
144
|
+
}
|
|
168
145
|
/**
|
|
169
146
|
* The clear function clears the priority queue.
|
|
170
147
|
*/
|
|
171
|
-
|
|
148
|
+
clear() {
|
|
172
149
|
this._pq.clear();
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
}());
|
|
150
|
+
}
|
|
151
|
+
}
|
|
176
152
|
exports.Heap = Heap;
|
|
@@ -6,43 +6,25 @@
|
|
|
6
6
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
7
7
|
* @license MIT License
|
|
8
8
|
*/
|
|
9
|
-
var __extends = (this && this.__extends) || (function () {
|
|
10
|
-
var extendStatics = function (d, b) {
|
|
11
|
-
extendStatics = Object.setPrototypeOf ||
|
|
12
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
13
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
14
|
-
return extendStatics(d, b);
|
|
15
|
-
};
|
|
16
|
-
return function (d, b) {
|
|
17
|
-
if (typeof b !== "function" && b !== null)
|
|
18
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
19
|
-
extendStatics(d, b);
|
|
20
|
-
function __() { this.constructor = d; }
|
|
21
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
10
|
exports.MaxHeap = void 0;
|
|
26
|
-
|
|
27
|
-
|
|
11
|
+
const heap_1 = require("./heap");
|
|
12
|
+
const priority_queue_1 = require("../priority-queue");
|
|
28
13
|
/**
|
|
29
14
|
* @class MaxHeap
|
|
30
15
|
* @extends Heap
|
|
31
16
|
*/
|
|
32
|
-
|
|
33
|
-
__extends(MaxHeap, _super);
|
|
17
|
+
class MaxHeap extends heap_1.Heap {
|
|
34
18
|
/**
|
|
35
19
|
* The constructor initializes a PriorityQueue with a custom comparator function.
|
|
36
20
|
* @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
|
|
37
21
|
* type `HeapOptions<T>`, which is a generic type that represents the options for the heap.
|
|
38
22
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
comparator:
|
|
23
|
+
constructor(options) {
|
|
24
|
+
super(options);
|
|
25
|
+
this._pq = new priority_queue_1.PriorityQueue({
|
|
26
|
+
comparator: (a, b) => b.priority - a.priority
|
|
43
27
|
});
|
|
44
|
-
return _this;
|
|
45
28
|
}
|
|
46
|
-
|
|
47
|
-
}(heap_1.Heap));
|
|
29
|
+
}
|
|
48
30
|
exports.MaxHeap = MaxHeap;
|
|
@@ -6,44 +6,26 @@
|
|
|
6
6
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
7
7
|
* @license MIT License
|
|
8
8
|
*/
|
|
9
|
-
var __extends = (this && this.__extends) || (function () {
|
|
10
|
-
var extendStatics = function (d, b) {
|
|
11
|
-
extendStatics = Object.setPrototypeOf ||
|
|
12
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
13
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
14
|
-
return extendStatics(d, b);
|
|
15
|
-
};
|
|
16
|
-
return function (d, b) {
|
|
17
|
-
if (typeof b !== "function" && b !== null)
|
|
18
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
19
|
-
extendStatics(d, b);
|
|
20
|
-
function __() { this.constructor = d; }
|
|
21
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
10
|
exports.MinHeap = void 0;
|
|
26
|
-
|
|
27
|
-
|
|
11
|
+
const heap_1 = require("./heap");
|
|
12
|
+
const priority_queue_1 = require("../priority-queue");
|
|
28
13
|
/**
|
|
29
14
|
* @class MinHeap
|
|
30
15
|
* @extends Heap
|
|
31
16
|
*/
|
|
32
|
-
|
|
33
|
-
__extends(MinHeap, _super);
|
|
17
|
+
class MinHeap extends heap_1.Heap {
|
|
34
18
|
/**
|
|
35
19
|
* The constructor initializes a PriorityQueue with a comparator function that compares the priority of two HeapItem
|
|
36
20
|
* objects.
|
|
37
21
|
* @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
|
|
38
22
|
* type `HeapOptions<T>`, which is a generic type that represents the options for the heap.
|
|
39
23
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
comparator:
|
|
24
|
+
constructor(options) {
|
|
25
|
+
super(options);
|
|
26
|
+
this._pq = new priority_queue_1.PriorityQueue({
|
|
27
|
+
comparator: (a, b) => a.priority - b.priority
|
|
44
28
|
});
|
|
45
|
-
return _this;
|
|
46
29
|
}
|
|
47
|
-
|
|
48
|
-
}(heap_1.Heap));
|
|
30
|
+
}
|
|
49
31
|
exports.MinHeap = MinHeap;
|