min-heap-typed 1.50.4 → 1.50.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.
@@ -74,6 +74,24 @@ class SinglyLinkedList extends base_1.IterableElementBase {
74
74
  get tail() {
75
75
  return this._tail;
76
76
  }
77
+ /**
78
+ * The above function returns the value of the first element in a linked list, or undefined if the
79
+ * list is empty.
80
+ * @returns The value of the first node in the linked list, or undefined if the linked list is empty.
81
+ */
82
+ get first() {
83
+ var _a;
84
+ return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
85
+ }
86
+ /**
87
+ * The function returns the value of the last element in a linked list, or undefined if the list is
88
+ * empty.
89
+ * @returns The value of the last node in the linked list, or undefined if the linked list is empty.
90
+ */
91
+ get last() {
92
+ var _a;
93
+ return (_a = this.tail) === null || _a === void 0 ? void 0 : _a.value;
94
+ }
77
95
  /**
78
96
  * The function returns the size of an object.
79
97
  * @returns The size of the object, which is a number.
@@ -106,19 +124,18 @@ class SinglyLinkedList extends base_1.IterableElementBase {
106
124
  /**
107
125
  * Time Complexity: O(1)
108
126
  * Space Complexity: O(1)
109
- * Constant time, as it involves basic pointer adjustments.
110
- * Constant space, as it only creates a new node.
111
127
  */
112
128
  /**
113
129
  * Time Complexity: O(1)
114
130
  * Space Complexity: O(1)
115
131
  *
116
- * The `push` function adds a new node with the given value to the end of a singly linked list.
117
- * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
118
- * any type (E) as specified in the generic type declaration of the class or function.
132
+ * The push function adds a new element to the end of a singly linked list.
133
+ * @param {E} element - The "element" parameter represents the value of the element that you want to
134
+ * add to the linked list.
135
+ * @returns The `push` method is returning a boolean value, `true`.
119
136
  */
120
- push(value) {
121
- const newNode = new SinglyLinkedListNode(value);
137
+ push(element) {
138
+ const newNode = new SinglyLinkedListNode(element);
122
139
  if (!this.head) {
123
140
  this._head = newNode;
124
141
  this._tail = newNode;
@@ -130,21 +147,6 @@ class SinglyLinkedList extends base_1.IterableElementBase {
130
147
  this._size++;
131
148
  return true;
132
149
  }
133
- /**
134
- * Time Complexity: O(1)
135
- * Space Complexity: O(1)
136
- */
137
- /**
138
- * Time Complexity: O(1)
139
- * Space Complexity: O(1)
140
- *
141
- * The `push` function adds a new node with the given value to the end of a singly linked list.
142
- * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
143
- * any type (E) as specified in the generic type declaration of the class or function.
144
- */
145
- addLast(value) {
146
- return this.push(value);
147
- }
148
150
  /**
149
151
  * Time Complexity: O(n)
150
152
  * Space Complexity: O(1)
@@ -154,10 +156,9 @@ class SinglyLinkedList extends base_1.IterableElementBase {
154
156
  * Time Complexity: O(n)
155
157
  * Space Complexity: O(1)
156
158
  *
157
- * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
158
- * pointers accordingly.
159
- * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
160
- * the linked list is empty, it returns `undefined`.
159
+ * The `pop` function removes and returns the value of the last element in a linked list.
160
+ * @returns The method is returning the value of the element that is being popped from the end of the
161
+ * list.
161
162
  */
162
163
  pop() {
163
164
  if (!this.head)
@@ -179,22 +180,6 @@ class SinglyLinkedList extends base_1.IterableElementBase {
179
180
  this._size--;
180
181
  return value;
181
182
  }
182
- /**
183
- * Time Complexity: O(n)
184
- * Space Complexity: O(1)
185
- */
186
- /**
187
- * Time Complexity: O(n)
188
- * Space Complexity: O(1)
189
- *
190
- * The `pollLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
191
- * pointers accordingly.
192
- * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
193
- * the linked list is empty, it returns `undefined`.
194
- */
195
- pollLast() {
196
- return this.pop();
197
- }
198
183
  /**
199
184
  * Time Complexity: O(1)
200
185
  * Space Complexity: O(1)
@@ -203,8 +188,8 @@ class SinglyLinkedList extends base_1.IterableElementBase {
203
188
  * Time Complexity: O(1)
204
189
  * Space Complexity: O(1)
205
190
  *
206
- * The `shift()` function removes and returns the value of the first node in a linked list.
207
- * @returns The value of the node that is being removed from the beginning of the linked list.
191
+ * The `shift()` function removes and returns the value of the first element in a linked list.
192
+ * @returns The value of the removed node.
208
193
  */
209
194
  shift() {
210
195
  if (!this.head)
@@ -222,26 +207,13 @@ class SinglyLinkedList extends base_1.IterableElementBase {
222
207
  * Time Complexity: O(1)
223
208
  * Space Complexity: O(1)
224
209
  *
225
- * The `pollFirst()` function removes and returns the value of the first node in a linked list.
226
- * @returns The value of the node that is being removed from the beginning of the linked list.
227
- */
228
- pollFirst() {
229
- return this.shift();
230
- }
231
- /**
232
- * Time Complexity: O(1)
233
- * Space Complexity: O(1)
234
- */
235
- /**
236
- * Time Complexity: O(1)
237
- * Space Complexity: O(1)
238
- *
239
- * The unshift function adds a new node with the given value to the beginning of a singly linked list.
240
- * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
241
- * linked list.
210
+ * The unshift function adds a new element to the beginning of a singly linked list.
211
+ * @param {E} element - The "element" parameter represents the value of the element that you want to
212
+ * add to the beginning of the singly linked list.
213
+ * @returns The `unshift` method is returning a boolean value, `true`.
242
214
  */
243
- unshift(value) {
244
- const newNode = new SinglyLinkedListNode(value);
215
+ unshift(element) {
216
+ const newNode = new SinglyLinkedListNode(element);
245
217
  if (!this.head) {
246
218
  this._head = newNode;
247
219
  this._tail = newNode;
@@ -253,25 +225,9 @@ class SinglyLinkedList extends base_1.IterableElementBase {
253
225
  this._size++;
254
226
  return true;
255
227
  }
256
- /**
257
- * Time Complexity: O(1)
258
- * Space Complexity: O(1)
259
- */
260
- /**
261
- * Time Complexity: O(1)
262
- * Space Complexity: O(1)
263
- *
264
- * The addFirst function adds a new node with the given value to the beginning of a singly linked list.
265
- * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
266
- * linked list.
267
- */
268
- addFirst(value) {
269
- return this.unshift(value);
270
- }
271
228
  /**
272
229
  * Time Complexity: O(n)
273
230
  * Space Complexity: O(1)
274
- * Linear time, where n is the index, as it may need to traverse the list to find the desired node.
275
231
  */
276
232
  /**
277
233
  * Time Complexity: O(n)
@@ -432,59 +432,6 @@ export declare class Deque<E> extends IterableElementBase<E> {
432
432
  * @returns a new Deque object with the mapped values.
433
433
  */
434
434
  map<T>(callback: ElementCallback<E, T>, thisArg?: any): Deque<T>;
435
- /**
436
- * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
437
- * Space Complexity: O(n) - Due to potential resizing.
438
- */
439
- /**
440
- * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
441
- * Space Complexity: O(n) - Due to potential resizing.
442
- *
443
- * The addLast function adds an element to the end of an array.
444
- * @param {E} element - The element parameter represents the element that you want to add to the end of the
445
- * data structure.
446
- */
447
- addLast(element: E): boolean;
448
- /**
449
- * Time Complexity: O(1)
450
- * Space Complexity: O(1)
451
- */
452
- /**
453
- * Time Complexity: O(1)
454
- * Space Complexity: O(1)
455
- *
456
- * The function "pollLast" removes and returns the last element of an array.
457
- * @returns The last element of the array is being returned.
458
- */
459
- pollLast(): E | undefined;
460
- /**
461
- * Time Complexity: O(1)
462
- * Space Complexity: O(1)
463
- * /
464
-
465
- /**
466
- * Time Complexity: O(1)
467
- * Space Complexity: O(1)
468
- *
469
- * The "addFirst" function adds an element to the beginning of an array.
470
- * @param {E} element - The parameter "element" represents the element that you want to add to the
471
- * beginning of the data structure.
472
- */
473
- addFirst(element: E): boolean;
474
- /**
475
- * Time Complexity: O(1)
476
- * Space Complexity: O(1)
477
- * /
478
-
479
- /**
480
- * Time Complexity: O(1)
481
- * Space Complexity: O(1)
482
- *
483
- * The function "pollFirst" removes and returns the first element of an array.
484
- * @returns The method `pollFirst()` is returning the first element of the array after removing it
485
- * from the beginning. If the array is empty, it will return `undefined`.
486
- */
487
- pollFirst(): E | undefined;
488
435
  /**
489
436
  * Time Complexity: O(n)
490
437
  * Space Complexity: O(1)
@@ -767,67 +767,6 @@ class Deque extends base_1.IterableElementBase {
767
767
  }
768
768
  return newDeque;
769
769
  }
770
- /**
771
- * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
772
- * Space Complexity: O(n) - Due to potential resizing.
773
- */
774
- /**
775
- * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
776
- * Space Complexity: O(n) - Due to potential resizing.
777
- *
778
- * The addLast function adds an element to the end of an array.
779
- * @param {E} element - The element parameter represents the element that you want to add to the end of the
780
- * data structure.
781
- */
782
- addLast(element) {
783
- return this.push(element);
784
- }
785
- /**
786
- * Time Complexity: O(1)
787
- * Space Complexity: O(1)
788
- */
789
- /**
790
- * Time Complexity: O(1)
791
- * Space Complexity: O(1)
792
- *
793
- * The function "pollLast" removes and returns the last element of an array.
794
- * @returns The last element of the array is being returned.
795
- */
796
- pollLast() {
797
- return this.pop();
798
- }
799
- /**
800
- * Time Complexity: O(1)
801
- * Space Complexity: O(1)
802
- * /
803
-
804
- /**
805
- * Time Complexity: O(1)
806
- * Space Complexity: O(1)
807
- *
808
- * The "addFirst" function adds an element to the beginning of an array.
809
- * @param {E} element - The parameter "element" represents the element that you want to add to the
810
- * beginning of the data structure.
811
- */
812
- addFirst(element) {
813
- return this.unshift(element);
814
- }
815
- /**
816
- * Time Complexity: O(1)
817
- * Space Complexity: O(1)
818
- * /
819
-
820
- /**
821
- * Time Complexity: O(1)
822
- * Space Complexity: O(1)
823
- *
824
- * The function "pollFirst" removes and returns the first element of an array.
825
- * @returns The method `pollFirst()` is returning the first element of the array after removing it
826
- * from the beginning. If the array is empty, it will return `undefined`.
827
- */
828
- pollFirst() {
829
- return this.shift();
830
- }
831
770
  /**
832
771
  * Time Complexity: O(n)
833
772
  * Space Complexity: O(1)
@@ -120,56 +120,6 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
120
120
  * @return A boolean value
121
121
  */
122
122
  deleteAt(index: number): boolean;
123
- /**
124
- * Time Complexity: O(1)
125
- * Space Complexity: O(1)
126
- */
127
- /**
128
- * Time Complexity: O(1)
129
- * Space Complexity: O(1)
130
- *
131
- * The `peek` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
132
- * @returns The `peek()` method returns the first element of the data structure, represented by the `_elements` array at
133
- * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
134
- */
135
- peek(): E | undefined;
136
- /**
137
- * Time Complexity: O(1)
138
- * Space Complexity: O(1)
139
- */
140
- /**
141
- * Time Complexity: O(1)
142
- * Space Complexity: O(1)
143
- *
144
- * The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
145
- * @returns The method `peekLast()` returns the last element of the `_elements` array if the array is not empty. If the
146
- * array is empty, it returns `undefined`.
147
- */
148
- peekLast(): E | undefined;
149
- /**
150
- * Time Complexity: O(1)
151
- * Space Complexity: O(1)
152
- */
153
- /**
154
- * Time Complexity: O(1)
155
- * Space Complexity: O(1)
156
- *
157
- * The enqueue function adds a value to the end of a queue.
158
- * @param {E} value - The value parameter represents the value that you want to add to the queue.
159
- */
160
- enqueue(value: E): boolean;
161
- /**
162
- * Time Complexity: O(1)
163
- * Space Complexity: O(1)
164
- */
165
- /**
166
- * Time Complexity: O(1)
167
- * Space Complexity: O(1)
168
- *
169
- * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
170
- * @returns The method is returning a value of type E or undefined.
171
- */
172
- dequeue(): E | undefined;
173
123
  /**
174
124
  * Time Complexity: O(1)
175
125
  * Space Complexity: O(1)
@@ -288,26 +238,6 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
288
238
  * 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
289
239
  */
290
240
  export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
291
- /**
292
- * The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
293
- * @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
294
- */
295
- get first(): E | undefined;
296
- /**
297
- * The enqueue function adds a value to the end of an array.
298
- * @param {E} value - The value parameter represents the value that you want to add to the queue.
299
- */
300
- enqueue(value: E): boolean;
301
- /**
302
- * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
303
- * @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
304
- */
305
- dequeue(): E | undefined;
306
- /**
307
- * The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
308
- * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
309
- */
310
- peek(): E | undefined;
311
241
  /**
312
242
  * Time Complexity: O(n)
313
243
  * Space Complexity: O(n)
@@ -156,64 +156,6 @@ class Queue extends base_1.IterableElementBase {
156
156
  const spliced = this.elements.splice(index, 1);
157
157
  return spliced.length === 1;
158
158
  }
159
- /**
160
- * Time Complexity: O(1)
161
- * Space Complexity: O(1)
162
- */
163
- /**
164
- * Time Complexity: O(1)
165
- * Space Complexity: O(1)
166
- *
167
- * The `peek` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
168
- * @returns The `peek()` method returns the first element of the data structure, represented by the `_elements` array at
169
- * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
170
- */
171
- peek() {
172
- return this.first;
173
- }
174
- /**
175
- * Time Complexity: O(1)
176
- * Space Complexity: O(1)
177
- */
178
- /**
179
- * Time Complexity: O(1)
180
- * Space Complexity: O(1)
181
- *
182
- * The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
183
- * @returns The method `peekLast()` returns the last element of the `_elements` array if the array is not empty. If the
184
- * array is empty, it returns `undefined`.
185
- */
186
- peekLast() {
187
- return this.last;
188
- }
189
- /**
190
- * Time Complexity: O(1)
191
- * Space Complexity: O(1)
192
- */
193
- /**
194
- * Time Complexity: O(1)
195
- * Space Complexity: O(1)
196
- *
197
- * The enqueue function adds a value to the end of a queue.
198
- * @param {E} value - The value parameter represents the value that you want to add to the queue.
199
- */
200
- enqueue(value) {
201
- return this.push(value);
202
- }
203
- /**
204
- * Time Complexity: O(1)
205
- * Space Complexity: O(1)
206
- */
207
- /**
208
- * Time Complexity: O(1)
209
- * Space Complexity: O(1)
210
- *
211
- * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
212
- * @returns The method is returning a value of type E or undefined.
213
- */
214
- dequeue() {
215
- return this.shift();
216
- }
217
159
  /**
218
160
  * Time Complexity: O(1)
219
161
  * Space Complexity: O(1)
@@ -366,35 +308,6 @@ exports.Queue = Queue;
366
308
  * 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
367
309
  */
368
310
  class LinkedListQueue extends linked_list_1.SinglyLinkedList {
369
- /**
370
- * The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
371
- * @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
372
- */
373
- get first() {
374
- var _a;
375
- return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
376
- }
377
- /**
378
- * The enqueue function adds a value to the end of an array.
379
- * @param {E} value - The value parameter represents the value that you want to add to the queue.
380
- */
381
- enqueue(value) {
382
- return this.push(value);
383
- }
384
- /**
385
- * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
386
- * @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
387
- */
388
- dequeue() {
389
- return this.shift();
390
- }
391
- /**
392
- * The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
393
- * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
394
- */
395
- peek() {
396
- return this.first;
397
- }
398
311
  /**
399
312
  * Time Complexity: O(n)
400
313
  * Space Complexity: O(n)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "min-heap-typed",
3
- "version": "1.50.4",
3
+ "version": "1.50.5",
4
4
  "description": "Min Heap. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -6,6 +6,8 @@ export abstract class IterableEntryBase<K = any, V = any> {
6
6
  * Space Complexity: O(1)
7
7
  */
8
8
 
9
+ abstract get size(): number;
10
+
9
11
  /**
10
12
  * Time Complexity: O(n)
11
13
  * Space Complexity: O(1)
@@ -125,6 +127,11 @@ export abstract class IterableEntryBase<K = any, V = any> {
125
127
  return false;
126
128
  }
127
129
 
130
+ /**
131
+ * Time Complexity: O(n)
132
+ * Space Complexity: O(1)
133
+ */
134
+
128
135
  /**
129
136
  * Time Complexity: O(n)
130
137
  * Space Complexity: O(1)
@@ -248,11 +255,6 @@ export abstract class IterableEntryBase<K = any, V = any> {
248
255
  return;
249
256
  }
250
257
 
251
- /**
252
- * Time Complexity: O(n)
253
- * Space Complexity: O(1)
254
- */
255
-
256
258
  /**
257
259
  * Time Complexity: O(n)
258
260
  * Space Complexity: O(1)
@@ -301,6 +303,8 @@ export abstract class IterableEntryBase<K = any, V = any> {
301
303
  }
302
304
 
303
305
  export abstract class IterableElementBase<E = any, C = any> {
306
+ abstract get size(): number;
307
+
304
308
  /**
305
309
  * Time Complexity: O(n)
306
310
  * Space Complexity: O(1)
@@ -362,6 +366,11 @@ export abstract class IterableElementBase<E = any, C = any> {
362
366
  return true;
363
367
  }
364
368
 
369
+ /**
370
+ * Time Complexity: O(n)
371
+ * Space Complexity: O(1)
372
+ */
373
+
365
374
  /**
366
375
  * Time Complexity: O(n)
367
376
  * Space Complexity: O(1)
@@ -445,11 +454,6 @@ export abstract class IterableElementBase<E = any, C = any> {
445
454
  return;
446
455
  }
447
456
 
448
- /**
449
- * Time Complexity: O(n)
450
- * Space Complexity: O(1)
451
- */
452
-
453
457
  /**
454
458
  * Time Complexity: O(n)
455
459
  * Space Complexity: O(1)
@@ -82,6 +82,10 @@ export abstract class AbstractGraph<
82
82
  this._vertexMap = v;
83
83
  }
84
84
 
85
+ get size(): number {
86
+ return this._vertexMap.size;
87
+ }
88
+
85
89
  /**
86
90
  * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
87
91
  * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
@@ -200,7 +200,7 @@ export class Heap<E = any> extends IterableElementBase<E> {
200
200
  * @param element - the element to check.
201
201
  * @returns Returns true if the specified element is contained; otherwise, returns false.
202
202
  */
203
- has(element: E): boolean {
203
+ override has(element: E): boolean {
204
204
  return this.elements.includes(element);
205
205
  }
206
206