priority-queue-typed 1.54.2 → 2.0.0
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/base/iterable-element-base.d.ts +14 -40
- package/dist/data-structures/base/iterable-element-base.js +14 -11
- package/dist/data-structures/base/linear-base.d.ts +277 -0
- package/dist/data-structures/base/linear-base.js +552 -0
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +21 -20
- package/dist/data-structures/binary-tree/avl-tree-counter.js +8 -7
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +23 -19
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +51 -38
- package/dist/data-structures/binary-tree/avl-tree.d.ts +89 -21
- package/dist/data-structures/binary-tree/avl-tree.js +76 -8
- package/dist/data-structures/binary-tree/binary-tree.d.ts +173 -225
- package/dist/data-structures/binary-tree/binary-tree.js +244 -149
- package/dist/data-structures/binary-tree/bst.d.ts +62 -56
- package/dist/data-structures/binary-tree/bst.js +89 -133
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +19 -25
- package/dist/data-structures/binary-tree/red-black-tree.js +7 -13
- package/dist/data-structures/binary-tree/tree-counter.d.ts +19 -19
- package/dist/data-structures/binary-tree/tree-counter.js +12 -12
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +186 -25
- package/dist/data-structures/binary-tree/tree-multi-map.js +211 -41
- package/dist/data-structures/graph/abstract-graph.js +2 -2
- package/dist/data-structures/heap/heap.d.ts +3 -11
- package/dist/data-structures/heap/heap.js +0 -10
- package/dist/data-structures/heap/max-heap.d.ts +2 -2
- package/dist/data-structures/heap/min-heap.d.ts +2 -2
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +65 -94
- package/dist/data-structures/linked-list/doubly-linked-list.js +131 -146
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +79 -75
- package/dist/data-structures/linked-list/singly-linked-list.js +217 -169
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +2 -2
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +2 -2
- package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -2
- package/dist/data-structures/queue/deque.d.ts +130 -91
- package/dist/data-structures/queue/deque.js +269 -169
- package/dist/data-structures/queue/queue.d.ts +84 -40
- package/dist/data-structures/queue/queue.js +134 -50
- package/dist/data-structures/stack/stack.d.ts +3 -11
- package/dist/data-structures/stack/stack.js +0 -10
- package/dist/data-structures/trie/trie.d.ts +4 -3
- package/dist/data-structures/trie/trie.js +3 -0
- package/dist/types/data-structures/base/base.d.ts +9 -4
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/types/data-structures/queue/deque.d.ts +2 -3
- package/dist/types/data-structures/queue/queue.d.ts +2 -2
- package/dist/utils/utils.d.ts +2 -2
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +29 -20
- package/src/data-structures/base/linear-base.ts +649 -0
- package/src/data-structures/binary-tree/avl-tree-counter.ts +30 -23
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +74 -49
- package/src/data-structures/binary-tree/avl-tree.ts +99 -29
- package/src/data-structures/binary-tree/binary-tree.ts +474 -257
- package/src/data-structures/binary-tree/bst.ts +150 -152
- package/src/data-structures/binary-tree/red-black-tree.ts +27 -35
- package/src/data-structures/binary-tree/tree-counter.ts +33 -27
- package/src/data-structures/binary-tree/tree-multi-map.ts +235 -53
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/heap/heap.ts +3 -14
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/heap/min-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +144 -160
- package/src/data-structures/linked-list/singly-linked-list.ts +241 -185
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -5
- package/src/data-structures/priority-queue/min-priority-queue.ts +2 -5
- package/src/data-structures/priority-queue/priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +286 -183
- package/src/data-structures/queue/queue.ts +149 -63
- package/src/data-structures/stack/stack.ts +3 -18
- package/src/data-structures/trie/trie.ts +7 -3
- package/src/types/data-structures/base/base.ts +17 -8
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/bst.ts +1 -1
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -1
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +2 -2
- package/src/types/data-structures/linked-list/singly-linked-list.ts +2 -2
- package/src/types/data-structures/queue/deque.ts +2 -3
- package/src/types/data-structures/queue/queue.ts +2 -2
- package/src/utils/utils.ts +2 -2
|
@@ -41,11 +41,169 @@ exports.TreeMultiMapNode = TreeMultiMapNode;
|
|
|
41
41
|
/**
|
|
42
42
|
*
|
|
43
43
|
* @example
|
|
44
|
-
* //
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
44
|
+
* // players ranked by score with their equipment
|
|
45
|
+
* type Equipment = {
|
|
46
|
+
* name: string; // Equipment name
|
|
47
|
+
* quality: 'legendary' | 'epic' | 'rare' | 'common';
|
|
48
|
+
* level: number;
|
|
49
|
+
* };
|
|
50
|
+
*
|
|
51
|
+
* type Player = {
|
|
52
|
+
* name: string;
|
|
53
|
+
* score: number;
|
|
54
|
+
* equipments: Equipment[];
|
|
55
|
+
* };
|
|
56
|
+
*
|
|
57
|
+
* // Mock player data with their scores and equipment
|
|
58
|
+
* const players: Player[] = [
|
|
59
|
+
* {
|
|
60
|
+
* name: 'DragonSlayer',
|
|
61
|
+
* score: 8750,
|
|
62
|
+
* equipments: [
|
|
63
|
+
* { name: 'AWM', quality: 'legendary', level: 85 },
|
|
64
|
+
* { name: 'Level 3 Helmet', quality: 'epic', level: 80 },
|
|
65
|
+
* { name: 'Extended Quickdraw Mag', quality: 'rare', level: 75 },
|
|
66
|
+
* { name: 'Compensator', quality: 'epic', level: 78 },
|
|
67
|
+
* { name: 'Vertical Grip', quality: 'rare', level: 72 }
|
|
68
|
+
* ]
|
|
69
|
+
* },
|
|
70
|
+
* {
|
|
71
|
+
* name: 'ShadowNinja',
|
|
72
|
+
* score: 7200,
|
|
73
|
+
* equipments: [
|
|
74
|
+
* { name: 'M416', quality: 'epic', level: 75 },
|
|
75
|
+
* { name: 'Ghillie Suit', quality: 'rare', level: 70 },
|
|
76
|
+
* { name: 'Red Dot Sight', quality: 'common', level: 65 },
|
|
77
|
+
* { name: 'Extended QuickDraw Mag', quality: 'rare', level: 68 }
|
|
78
|
+
* ]
|
|
79
|
+
* },
|
|
80
|
+
* {
|
|
81
|
+
* name: 'RuneMaster',
|
|
82
|
+
* score: 9100,
|
|
83
|
+
* equipments: [
|
|
84
|
+
* { name: 'KAR98K', quality: 'legendary', level: 90 },
|
|
85
|
+
* { name: 'Level 3 Vest', quality: 'legendary', level: 85 },
|
|
86
|
+
* { name: 'Holographic Sight', quality: 'epic', level: 82 },
|
|
87
|
+
* { name: 'Suppressor', quality: 'legendary', level: 88 },
|
|
88
|
+
* { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
|
|
89
|
+
* ]
|
|
90
|
+
* },
|
|
91
|
+
* {
|
|
92
|
+
* name: 'BattleKing',
|
|
93
|
+
* score: 8500,
|
|
94
|
+
* equipments: [
|
|
95
|
+
* { name: 'AUG', quality: 'epic', level: 82 },
|
|
96
|
+
* { name: 'Red Dot Sight', quality: 'rare', level: 75 },
|
|
97
|
+
* { name: 'Extended Mag', quality: 'common', level: 70 },
|
|
98
|
+
* { name: 'Tactical Stock', quality: 'rare', level: 76 }
|
|
99
|
+
* ]
|
|
100
|
+
* },
|
|
101
|
+
* {
|
|
102
|
+
* name: 'SniperElite',
|
|
103
|
+
* score: 7800,
|
|
104
|
+
* equipments: [
|
|
105
|
+
* { name: 'M24', quality: 'legendary', level: 88 },
|
|
106
|
+
* { name: 'Compensator', quality: 'epic', level: 80 },
|
|
107
|
+
* { name: 'Scope 8x', quality: 'legendary', level: 85 },
|
|
108
|
+
* { name: 'Level 2 Helmet', quality: 'rare', level: 75 }
|
|
109
|
+
* ]
|
|
110
|
+
* },
|
|
111
|
+
* {
|
|
112
|
+
* name: 'RushMaster',
|
|
113
|
+
* score: 7500,
|
|
114
|
+
* equipments: [
|
|
115
|
+
* { name: 'Vector', quality: 'rare', level: 72 },
|
|
116
|
+
* { name: 'Level 2 Helmet', quality: 'common', level: 65 },
|
|
117
|
+
* { name: 'Quickdraw Mag', quality: 'common', level: 60 },
|
|
118
|
+
* { name: 'Laser Sight', quality: 'rare', level: 68 }
|
|
119
|
+
* ]
|
|
120
|
+
* },
|
|
121
|
+
* {
|
|
122
|
+
* name: 'GhostWarrior',
|
|
123
|
+
* score: 8200,
|
|
124
|
+
* equipments: [
|
|
125
|
+
* { name: 'SCAR-L', quality: 'epic', level: 78 },
|
|
126
|
+
* { name: 'Extended Quickdraw Mag', quality: 'rare', level: 70 },
|
|
127
|
+
* { name: 'Holographic Sight', quality: 'epic', level: 75 },
|
|
128
|
+
* { name: 'Suppressor', quality: 'rare', level: 72 },
|
|
129
|
+
* { name: 'Vertical Grip', quality: 'common', level: 65 }
|
|
130
|
+
* ]
|
|
131
|
+
* },
|
|
132
|
+
* {
|
|
133
|
+
* name: 'DeathDealer',
|
|
134
|
+
* score: 7300,
|
|
135
|
+
* equipments: [
|
|
136
|
+
* { name: 'SKS', quality: 'epic', level: 76 },
|
|
137
|
+
* { name: 'Holographic Sight', quality: 'rare', level: 68 },
|
|
138
|
+
* { name: 'Extended Mag', quality: 'common', level: 65 }
|
|
139
|
+
* ]
|
|
140
|
+
* },
|
|
141
|
+
* {
|
|
142
|
+
* name: 'StormRider',
|
|
143
|
+
* score: 8900,
|
|
144
|
+
* equipments: [
|
|
145
|
+
* { name: 'MK14', quality: 'legendary', level: 92 },
|
|
146
|
+
* { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
|
|
147
|
+
* { name: 'Scope 8x', quality: 'epic', level: 80 },
|
|
148
|
+
* { name: 'Suppressor', quality: 'legendary', level: 88 },
|
|
149
|
+
* { name: 'Tactical Stock', quality: 'rare', level: 75 }
|
|
150
|
+
* ]
|
|
151
|
+
* },
|
|
152
|
+
* {
|
|
153
|
+
* name: 'CombatLegend',
|
|
154
|
+
* score: 7600,
|
|
155
|
+
* equipments: [
|
|
156
|
+
* { name: 'UMP45', quality: 'rare', level: 74 },
|
|
157
|
+
* { name: 'Level 2 Vest', quality: 'common', level: 67 },
|
|
158
|
+
* { name: 'Red Dot Sight', quality: 'common', level: 62 },
|
|
159
|
+
* { name: 'Extended Mag', quality: 'rare', level: 70 }
|
|
160
|
+
* ]
|
|
161
|
+
* }
|
|
162
|
+
* ];
|
|
163
|
+
*
|
|
164
|
+
* // Create a TreeMultiMap for player rankings
|
|
165
|
+
* const playerRankings = new TreeMultiMap<number, Equipment, Player>(players, {
|
|
166
|
+
* toEntryFn: ({ score, equipments }) => [score, equipments],
|
|
167
|
+
* isMapMode: false
|
|
168
|
+
* });
|
|
169
|
+
*
|
|
170
|
+
* const topPlayersEquipments = playerRankings.rangeSearch([8900, 10000], node => playerRankings.get(node));
|
|
171
|
+
* console.log(topPlayersEquipments); // [
|
|
172
|
+
* // [
|
|
173
|
+
* // {
|
|
174
|
+
* // name: 'MK14',
|
|
175
|
+
* // quality: 'legendary',
|
|
176
|
+
* // level: 92
|
|
177
|
+
* // },
|
|
178
|
+
* // { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
|
|
179
|
+
* // {
|
|
180
|
+
* // name: 'Scope 8x',
|
|
181
|
+
* // quality: 'epic',
|
|
182
|
+
* // level: 80
|
|
183
|
+
* // },
|
|
184
|
+
* // { name: 'Suppressor', quality: 'legendary', level: 88 },
|
|
185
|
+
* // {
|
|
186
|
+
* // name: 'Tactical Stock',
|
|
187
|
+
* // quality: 'rare',
|
|
188
|
+
* // level: 75
|
|
189
|
+
* // }
|
|
190
|
+
* // ],
|
|
191
|
+
* // [
|
|
192
|
+
* // { name: 'KAR98K', quality: 'legendary', level: 90 },
|
|
193
|
+
* // {
|
|
194
|
+
* // name: 'Level 3 Vest',
|
|
195
|
+
* // quality: 'legendary',
|
|
196
|
+
* // level: 85
|
|
197
|
+
* // },
|
|
198
|
+
* // { name: 'Holographic Sight', quality: 'epic', level: 82 },
|
|
199
|
+
* // {
|
|
200
|
+
* // name: 'Suppressor',
|
|
201
|
+
* // quality: 'legendary',
|
|
202
|
+
* // level: 88
|
|
203
|
+
* // },
|
|
204
|
+
* // { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
|
|
205
|
+
* // ]
|
|
206
|
+
* // ]
|
|
49
207
|
*/
|
|
50
208
|
class TreeMultiMap extends red_black_tree_1.RedBlackTree {
|
|
51
209
|
/**
|
|
@@ -60,7 +218,7 @@ class TreeMultiMap extends red_black_tree_1.RedBlackTree {
|
|
|
60
218
|
* additional options for configuring the TreeMultiMap instance.
|
|
61
219
|
*/
|
|
62
220
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
63
|
-
super([], Object.assign(
|
|
221
|
+
super([], Object.assign({}, options));
|
|
64
222
|
if (keysNodesEntriesOrRaws) {
|
|
65
223
|
this.addMany(keysNodesEntriesOrRaws);
|
|
66
224
|
}
|
|
@@ -79,34 +237,36 @@ class TreeMultiMap extends red_black_tree_1.RedBlackTree {
|
|
|
79
237
|
* data and the provided options merged with the existing properties of the current object.
|
|
80
238
|
*/
|
|
81
239
|
createTree(options) {
|
|
82
|
-
return new TreeMultiMap([], Object.assign({ iterationType: this.iterationType, specifyComparable: this._specifyComparable, toEntryFn: this._toEntryFn, isReverse: this._isReverse }, options));
|
|
240
|
+
return new TreeMultiMap([], Object.assign({ iterationType: this.iterationType, specifyComparable: this._specifyComparable, toEntryFn: this._toEntryFn, isReverse: this._isReverse, isMapMode: this._isMapMode }, options));
|
|
83
241
|
}
|
|
84
242
|
/**
|
|
85
243
|
* Time Complexity: O(1)
|
|
86
244
|
* Space Complexity: O(1)
|
|
87
245
|
*
|
|
88
|
-
* The function `createNode` overrides the
|
|
89
|
-
*
|
|
90
|
-
* @param {K} key - The `key` parameter
|
|
91
|
-
*
|
|
92
|
-
* @
|
|
93
|
-
*
|
|
246
|
+
* The function `createNode` overrides the creation of a new TreeMultiMapNode with a specified key
|
|
247
|
+
* and value array.
|
|
248
|
+
* @param {K} key - The `key` parameter represents the key of the node being created in the
|
|
249
|
+
* `TreeMultiMap`.
|
|
250
|
+
* @param {V[]} value - The `value` parameter in the `createNode` method represents an array of
|
|
251
|
+
* values associated with a specific key in the TreeMultiMap data structure.
|
|
252
|
+
* @returns A new instance of `TreeMultiMapNode<K, V>` is being returned with the specified key and
|
|
253
|
+
* value. If `_isMapMode` is true, an empty array is passed as the value, otherwise the provided
|
|
254
|
+
* value is used.
|
|
94
255
|
*/
|
|
95
|
-
createNode(key) {
|
|
96
|
-
return new TreeMultiMapNode(key, []);
|
|
256
|
+
createNode(key, value = []) {
|
|
257
|
+
return new TreeMultiMapNode(key, this._isMapMode ? [] : value);
|
|
97
258
|
}
|
|
98
259
|
/**
|
|
99
260
|
* Time Complexity: O(log n)
|
|
100
261
|
* Space Complexity: O(log n)
|
|
101
262
|
*
|
|
102
|
-
* The function
|
|
103
|
-
*
|
|
104
|
-
* @param
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* @param {V} [
|
|
108
|
-
* you want to add to the TreeMultiMap.
|
|
109
|
-
* be added to the existing list of values associated with that key. If the key is not present,
|
|
263
|
+
* The function overrides the add method to handle different types of input for a TreeMultiMap data
|
|
264
|
+
* structure.
|
|
265
|
+
* @param [key] - The `key` parameter in the `override add` method represents the key of the entry to
|
|
266
|
+
* be added to the TreeMultiMap. It can be of type `K`, which is the key type of the TreeMultiMap, or
|
|
267
|
+
* it can be a TreeMultiMapNode containing the key and its
|
|
268
|
+
* @param {V[]} [values] - The `values` parameter in the `add` method represents an array of values
|
|
269
|
+
* that you want to add to the TreeMultiMap. It can contain one or more values of type `V`.
|
|
110
270
|
* @returns The `add` method is returning a boolean value, which indicates whether the operation was
|
|
111
271
|
* successful or not.
|
|
112
272
|
*/
|
|
@@ -116,30 +276,40 @@ class TreeMultiMap extends red_black_tree_1.RedBlackTree {
|
|
|
116
276
|
const _commonAdd = (key, values) => {
|
|
117
277
|
if (key === undefined || key === null)
|
|
118
278
|
return false;
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
existingValues.push(value);
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
const existingNode = this.getNode(key);
|
|
126
|
-
if (this.isRealNode(existingNode)) {
|
|
127
|
-
if (existingValues === undefined) {
|
|
128
|
-
super.add(key, values);
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
131
|
-
if (values !== undefined) {
|
|
279
|
+
const _addToValues = () => {
|
|
280
|
+
const existingValues = this.get(key);
|
|
281
|
+
if (existingValues !== undefined && values !== undefined) {
|
|
132
282
|
for (const value of values)
|
|
133
283
|
existingValues.push(value);
|
|
134
284
|
return true;
|
|
135
285
|
}
|
|
286
|
+
return false;
|
|
287
|
+
};
|
|
288
|
+
const _addByNode = () => {
|
|
289
|
+
const existingNode = this.getNode(key);
|
|
290
|
+
if (this.isRealNode(existingNode)) {
|
|
291
|
+
const existingValues = this.get(existingNode);
|
|
292
|
+
if (existingValues === undefined) {
|
|
293
|
+
super.add(key, values);
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
if (values !== undefined) {
|
|
297
|
+
for (const value of values)
|
|
298
|
+
existingValues.push(value);
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
136
305
|
else {
|
|
137
|
-
return
|
|
306
|
+
return super.add(key, values);
|
|
138
307
|
}
|
|
308
|
+
};
|
|
309
|
+
if (this._isMapMode) {
|
|
310
|
+
return _addByNode() || _addToValues();
|
|
139
311
|
}
|
|
140
|
-
|
|
141
|
-
return super.add(key, values);
|
|
142
|
-
}
|
|
312
|
+
return _addToValues() || _addByNode();
|
|
143
313
|
};
|
|
144
314
|
if (this.isEntry(keyNodeOrEntry)) {
|
|
145
315
|
const [key, values] = keyNodeOrEntry;
|
|
@@ -153,7 +323,7 @@ class TreeMultiMap extends red_black_tree_1.RedBlackTree {
|
|
|
153
323
|
*
|
|
154
324
|
* The function `deleteValue` removes a specific value from a key in a TreeMultiMap data structure
|
|
155
325
|
* and deletes the entire node if no values are left for that key.
|
|
156
|
-
* @param {
|
|
326
|
+
* @param {K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
157
327
|
* parameter in the `deleteValue` function can be either a `BTNRep` object containing a key and an
|
|
158
328
|
* array of values, or just a key itself.
|
|
159
329
|
* @param {V} value - The `value` parameter in the `deleteValue` function represents the specific
|
|
@@ -267,8 +267,8 @@ class AbstractGraph extends base_1.IterableEntryBase {
|
|
|
267
267
|
const queue = new queue_1.Queue([vertex1]);
|
|
268
268
|
visited.set(vertex1, true);
|
|
269
269
|
let cost = 0;
|
|
270
|
-
while (queue.
|
|
271
|
-
for (let i = 0; i < queue.
|
|
270
|
+
while (queue.length > 0) {
|
|
271
|
+
for (let i = 0; i < queue.length; i++) {
|
|
272
272
|
const cur = queue.shift();
|
|
273
273
|
if (cur === vertex2) {
|
|
274
274
|
return cost;
|
|
@@ -183,7 +183,7 @@ import { IterableElementBase } from '../base';
|
|
|
183
183
|
* ]);
|
|
184
184
|
* console.log(scheduleTasks(tasks, 2)); // expectedMap
|
|
185
185
|
*/
|
|
186
|
-
export declare class Heap<E = any, R = any> extends IterableElementBase<E, R
|
|
186
|
+
export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
187
187
|
/**
|
|
188
188
|
* The constructor initializes a heap data structure with optional elements and options.
|
|
189
189
|
* @param elements - The `elements` parameter is an iterable object that contains the initial
|
|
@@ -308,14 +308,6 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R, He
|
|
|
308
308
|
* @returns An array containing elements traversed in the specified order.
|
|
309
309
|
*/
|
|
310
310
|
dfs(order?: DFSOrderPattern): E[];
|
|
311
|
-
/**
|
|
312
|
-
* Time Complexity: O(n)
|
|
313
|
-
* Space Complexity: O(n)
|
|
314
|
-
*
|
|
315
|
-
* Convert the heap to an array.
|
|
316
|
-
* @returns An array containing the elements of the heap.
|
|
317
|
-
*/
|
|
318
|
-
toArray(): E[];
|
|
319
311
|
/**
|
|
320
312
|
* Time Complexity: O(n)
|
|
321
313
|
* Space Complexity: O(n)
|
|
@@ -355,7 +347,7 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R, He
|
|
|
355
347
|
* @returns The `filter` method is returning a new `Heap` object that contains the elements that pass
|
|
356
348
|
* the filter condition specified by the `callback` function.
|
|
357
349
|
*/
|
|
358
|
-
filter(callback: ElementCallback<E, R, boolean
|
|
350
|
+
filter(callback: ElementCallback<E, R, boolean>, thisArg?: any): Heap<E, R>;
|
|
359
351
|
/**
|
|
360
352
|
* Time Complexity: O(n)
|
|
361
353
|
* Space Complexity: O(n)
|
|
@@ -377,7 +369,7 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R, He
|
|
|
377
369
|
* value of
|
|
378
370
|
* @returns a new instance of the `Heap` class with the mapped elements.
|
|
379
371
|
*/
|
|
380
|
-
map<EM, RM>(callback: ElementCallback<E, R, EM
|
|
372
|
+
map<EM, RM>(callback: ElementCallback<E, R, EM>, comparator: Comparator<EM>, toElementFn?: (rawElement: RM) => EM, thisArg?: any): Heap<EM, RM>;
|
|
381
373
|
protected _DEFAULT_COMPARATOR: (a: E, b: E) => number;
|
|
382
374
|
protected _comparator: Comparator<E>;
|
|
383
375
|
/**
|
|
@@ -413,16 +413,6 @@ class Heap extends base_1.IterableElementBase {
|
|
|
413
413
|
_dfs(0); // Traverse starting from the root node
|
|
414
414
|
return result;
|
|
415
415
|
}
|
|
416
|
-
/**
|
|
417
|
-
* Time Complexity: O(n)
|
|
418
|
-
* Space Complexity: O(n)
|
|
419
|
-
*
|
|
420
|
-
* Convert the heap to an array.
|
|
421
|
-
* @returns An array containing the elements of the heap.
|
|
422
|
-
*/
|
|
423
|
-
toArray() {
|
|
424
|
-
return [...this.elements];
|
|
425
|
-
}
|
|
426
416
|
/**
|
|
427
417
|
* Time Complexity: O(n)
|
|
428
418
|
* Space Complexity: O(n)
|
|
@@ -42,7 +42,7 @@ export declare class MaxHeap<E = any, R = any> extends Heap<E, R> {
|
|
|
42
42
|
* @returns The `filter` method is returning a new `MaxHeap` object that contains the elements that pass
|
|
43
43
|
* the filter condition specified by the `callback` function.
|
|
44
44
|
*/
|
|
45
|
-
filter(callback: ElementCallback<E, R, boolean
|
|
45
|
+
filter(callback: ElementCallback<E, R, boolean>, thisArg?: any): MaxHeap<E, R>;
|
|
46
46
|
/**
|
|
47
47
|
* Time Complexity: O(n log n)
|
|
48
48
|
* Space Complexity: O(n)
|
|
@@ -64,5 +64,5 @@ export declare class MaxHeap<E = any, R = any> extends Heap<E, R> {
|
|
|
64
64
|
* value of
|
|
65
65
|
* @returns a new instance of the `MaxHeap` class with the mapped elements.
|
|
66
66
|
*/
|
|
67
|
-
map<EM, RM>(callback: ElementCallback<E, R, EM
|
|
67
|
+
map<EM, RM>(callback: ElementCallback<E, R, EM>, comparator: Comparator<EM>, toElementFn?: (rawElement: RM) => EM, thisArg?: any): MaxHeap<EM, RM>;
|
|
68
68
|
}
|
|
@@ -42,7 +42,7 @@ export declare class MinHeap<E = any, R = any> extends Heap<E, R> {
|
|
|
42
42
|
* @returns The `filter` method is returning a new `MinHeap` object that contains the elements that pass
|
|
43
43
|
* the filter condition specified by the `callback` function.
|
|
44
44
|
*/
|
|
45
|
-
filter(callback: ElementCallback<E, R, boolean
|
|
45
|
+
filter(callback: ElementCallback<E, R, boolean>, thisArg?: any): MinHeap<E, R>;
|
|
46
46
|
/**
|
|
47
47
|
* Time Complexity: O(n log n)
|
|
48
48
|
* Space Complexity: O(n)
|
|
@@ -64,5 +64,5 @@ export declare class MinHeap<E = any, R = any> extends Heap<E, R> {
|
|
|
64
64
|
* value of
|
|
65
65
|
* @returns a new instance of the `MinHeap` class with the mapped elements.
|
|
66
66
|
*/
|
|
67
|
-
map<EM, RM>(callback: ElementCallback<E, R, EM
|
|
67
|
+
map<EM, RM>(callback: ElementCallback<E, R, EM>, comparator: Comparator<EM>, toElementFn?: (rawElement: RM) => EM, thisArg?: any): MinHeap<EM, RM>;
|
|
68
68
|
}
|