min-heap-typed 1.39.4 → 1.39.6

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.
Files changed (47) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +6 -6
  2. package/dist/data-structures/binary-tree/avl-tree.js +13 -13
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +7 -7
  4. package/dist/data-structures/binary-tree/binary-tree.js +17 -17
  5. package/dist/data-structures/binary-tree/bst.d.ts +6 -6
  6. package/dist/data-structures/binary-tree/bst.js +13 -13
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +2 -2
  8. package/dist/data-structures/binary-tree/rb-tree.js +4 -4
  9. package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -7
  10. package/dist/data-structures/binary-tree/segment-tree.js +16 -16
  11. package/dist/data-structures/binary-tree/tree-multiset.d.ts +6 -6
  12. package/dist/data-structures/binary-tree/tree-multiset.js +18 -18
  13. package/dist/data-structures/graph/abstract-graph.d.ts +96 -96
  14. package/dist/data-structures/graph/abstract-graph.js +64 -64
  15. package/dist/data-structures/graph/directed-graph.d.ts +68 -68
  16. package/dist/data-structures/graph/directed-graph.js +48 -48
  17. package/dist/data-structures/graph/map-graph.d.ts +13 -13
  18. package/dist/data-structures/graph/map-graph.js +15 -15
  19. package/dist/data-structures/graph/undirected-graph.d.ts +42 -42
  20. package/dist/data-structures/graph/undirected-graph.js +32 -32
  21. package/dist/data-structures/hash/hash-table.d.ts +4 -4
  22. package/dist/data-structures/hash/hash-table.js +8 -8
  23. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +31 -31
  24. package/dist/data-structures/linked-list/doubly-linked-list.js +54 -54
  25. package/dist/data-structures/linked-list/singly-linked-list.d.ts +24 -24
  26. package/dist/data-structures/linked-list/singly-linked-list.js +52 -52
  27. package/dist/data-structures/queue/queue.d.ts +1 -1
  28. package/dist/data-structures/queue/queue.js +4 -4
  29. package/dist/interfaces/binary-tree.d.ts +2 -2
  30. package/dist/interfaces/graph.d.ts +3 -3
  31. package/package.json +2 -2
  32. package/src/data-structures/binary-tree/avl-tree.ts +13 -13
  33. package/src/data-structures/binary-tree/binary-tree.ts +18 -18
  34. package/src/data-structures/binary-tree/bst.ts +16 -16
  35. package/src/data-structures/binary-tree/rb-tree.ts +6 -6
  36. package/src/data-structures/binary-tree/segment-tree.ts +15 -15
  37. package/src/data-structures/binary-tree/tree-multiset.ts +18 -18
  38. package/src/data-structures/graph/abstract-graph.ts +156 -154
  39. package/src/data-structures/graph/directed-graph.ts +99 -94
  40. package/src/data-structures/graph/map-graph.ts +22 -25
  41. package/src/data-structures/graph/undirected-graph.ts +62 -60
  42. package/src/data-structures/hash/hash-table.ts +9 -9
  43. package/src/data-structures/linked-list/doubly-linked-list.ts +61 -61
  44. package/src/data-structures/linked-list/singly-linked-list.ts +58 -58
  45. package/src/data-structures/queue/queue.ts +2 -2
  46. package/src/interfaces/binary-tree.ts +2 -2
  47. package/src/interfaces/graph.ts +3 -3
@@ -8,22 +8,22 @@
8
8
  export class SinglyLinkedListNode<E = any> {
9
9
  /**
10
10
  * The constructor function initializes an instance of a class with a given value and sets the next property to null.
11
- * @param {E} val - The "val" parameter is of type E, which means it can be any data type. It represents the value that
11
+ * @param {E} value - The "value" parameter is of type E, which means it can be any data type. It represents the value that
12
12
  * will be stored in the node of a linked list.
13
13
  */
14
- constructor(val: E) {
15
- this._val = val;
14
+ constructor(value: E) {
15
+ this._value = value;
16
16
  this._next = null;
17
17
  }
18
18
 
19
- private _val: E;
19
+ private _value: E;
20
20
 
21
- get val(): E {
22
- return this._val;
21
+ get value(): E {
22
+ return this._value;
23
23
  }
24
24
 
25
- set val(value: E) {
26
- this._val = value;
25
+ set value(value: E) {
26
+ this._value = value;
27
27
  }
28
28
 
29
29
  private _next: SinglyLinkedListNode<E> | null;
@@ -88,12 +88,12 @@ export class SinglyLinkedList<E = any> {
88
88
  }
89
89
 
90
90
  /**
91
- * The `push` function adds a new node with the given val to the end of a singly linked list.
92
- * @param {E} val - The "val" parameter represents the value that you want to add to the linked list. It can be of
91
+ * The `push` function adds a new node with the given value to the end of a singly linked list.
92
+ * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
93
93
  * any type (E) as specified in the generic type declaration of the class or function.
94
94
  */
95
- push(val: E): void {
96
- const newNode = new SinglyLinkedListNode(val);
95
+ push(value: E): void {
96
+ const newNode = new SinglyLinkedListNode(value);
97
97
  if (!this.head) {
98
98
  this.head = newNode;
99
99
  this.tail = newNode;
@@ -105,12 +105,12 @@ export class SinglyLinkedList<E = any> {
105
105
  }
106
106
 
107
107
  /**
108
- * The `push` function adds a new node with the given val to the end of a singly linked list.
109
- * @param {E} val - The "val" parameter represents the value that you want to add to the linked list. It can be of
108
+ * The `push` function adds a new node with the given value to the end of a singly linked list.
109
+ * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
110
110
  * any type (E) as specified in the generic type declaration of the class or function.
111
111
  */
112
- addLast(val: E): void {
113
- this.push(val);
112
+ addLast(value: E): void {
113
+ this.push(value);
114
114
  }
115
115
 
116
116
  /**
@@ -122,22 +122,22 @@ export class SinglyLinkedList<E = any> {
122
122
  pop(): E | undefined {
123
123
  if (!this.head) return undefined;
124
124
  if (this.head === this.tail) {
125
- const val = this.head.val;
125
+ const value = this.head.value;
126
126
  this.head = null;
127
127
  this.tail = null;
128
128
  this._length--;
129
- return val;
129
+ return value;
130
130
  }
131
131
 
132
132
  let current = this.head;
133
133
  while (current.next !== this.tail) {
134
134
  current = current.next!;
135
135
  }
136
- const val = this.tail!.val;
136
+ const value = this.tail!.value;
137
137
  current.next = null;
138
138
  this.tail = current;
139
139
  this._length--;
140
- return val;
140
+ return value;
141
141
  }
142
142
 
143
143
  /**
@@ -159,7 +159,7 @@ export class SinglyLinkedList<E = any> {
159
159
  const removedNode = this.head;
160
160
  this.head = this.head.next;
161
161
  this._length--;
162
- return removedNode.val;
162
+ return removedNode.value;
163
163
  }
164
164
 
165
165
  /**
@@ -172,11 +172,11 @@ export class SinglyLinkedList<E = any> {
172
172
 
173
173
  /**
174
174
  * The unshift function adds a new node with the given value to the beginning of a singly linked list.
175
- * @param {E} val - The parameter "val" represents the value of the new node that will be added to the beginning of the
175
+ * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
176
176
  * linked list.
177
177
  */
178
- unshift(val: E): void {
179
- const newNode = new SinglyLinkedListNode(val);
178
+ unshift(value: E): void {
179
+ const newNode = new SinglyLinkedListNode(value);
180
180
  if (!this.head) {
181
181
  this.head = newNode;
182
182
  this.tail = newNode;
@@ -189,11 +189,11 @@ export class SinglyLinkedList<E = any> {
189
189
 
190
190
  /**
191
191
  * The addFirst function adds a new node with the given value to the beginning of a singly linked list.
192
- * @param {E} val - The parameter "val" represents the value of the new node that will be added to the beginning of the
192
+ * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
193
193
  * linked list.
194
194
  */
195
- addFirst(val: E): void {
196
- this.unshift(val);
195
+ addFirst(value: E): void {
196
+ this.unshift(value);
197
197
  }
198
198
 
199
199
  /**
@@ -209,7 +209,7 @@ export class SinglyLinkedList<E = any> {
209
209
  for (let i = 0; i < index; i++) {
210
210
  current = current!.next;
211
211
  }
212
- return current!.val;
212
+ return current!.value;
213
213
  }
214
214
 
215
215
  /**
@@ -243,7 +243,7 @@ export class SinglyLinkedList<E = any> {
243
243
  const removedNode = prevNode!.next;
244
244
  prevNode!.next = removedNode!.next;
245
245
  this._length--;
246
- return removedNode!.val;
246
+ return removedNode!.value;
247
247
  }
248
248
 
249
249
  /**
@@ -257,7 +257,7 @@ export class SinglyLinkedList<E = any> {
257
257
  if (!valueOrNode) return false;
258
258
  let value: E;
259
259
  if (valueOrNode instanceof SinglyLinkedListNode) {
260
- value = valueOrNode.val;
260
+ value = valueOrNode.value;
261
261
  } else {
262
262
  value = valueOrNode;
263
263
  }
@@ -265,7 +265,7 @@ export class SinglyLinkedList<E = any> {
265
265
  prev = null;
266
266
 
267
267
  while (current) {
268
- if (current.val === value) {
268
+ if (current.value === value) {
269
269
  if (prev === null) {
270
270
  this.head = current.next;
271
271
  if (current === this.tail) {
@@ -291,23 +291,23 @@ export class SinglyLinkedList<E = any> {
291
291
  * The `insertAt` function inserts a value at a specified index in a singly linked list.
292
292
  * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
293
293
  * linked list. It is of type number.
294
- * @param {E} val - The `val` parameter represents the value that you want to insert into the linked list at the
294
+ * @param {E} value - The `value` parameter represents the value that you want to insert into the linked list at the
295
295
  * specified index.
296
296
  * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
297
297
  * if the index is out of bounds.
298
298
  */
299
- insertAt(index: number, val: E): boolean {
299
+ insertAt(index: number, value: E): boolean {
300
300
  if (index < 0 || index > this.length) return false;
301
301
  if (index === 0) {
302
- this.unshift(val);
302
+ this.unshift(value);
303
303
  return true;
304
304
  }
305
305
  if (index === this.length) {
306
- this.push(val);
306
+ this.push(value);
307
307
  return true;
308
308
  }
309
309
 
310
- const newNode = new SinglyLinkedListNode(val);
310
+ const newNode = new SinglyLinkedListNode(value);
311
311
  const prevNode = this.getNodeAt(index - 1);
312
312
  newNode.next = prevNode!.next;
313
313
  prevNode!.next = newNode;
@@ -341,7 +341,7 @@ export class SinglyLinkedList<E = any> {
341
341
  const array: E[] = [];
342
342
  let current = this.head;
343
343
  while (current) {
344
- array.push(current.val);
344
+ array.push(current.value);
345
345
  current = current.next;
346
346
  }
347
347
  return array;
@@ -375,11 +375,11 @@ export class SinglyLinkedList<E = any> {
375
375
  * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
376
376
  * the callback function. If no element satisfies the condition, it returns `null`.
377
377
  */
378
- find(callback: (val: E) => boolean): E | null {
378
+ find(callback: (value: E) => boolean): E | null {
379
379
  let current = this.head;
380
380
  while (current) {
381
- if (callback(current.val)) {
382
- return current.val;
381
+ if (callback(current.value)) {
382
+ return current.value;
383
383
  }
384
384
  current = current.next;
385
385
  }
@@ -397,7 +397,7 @@ export class SinglyLinkedList<E = any> {
397
397
  let current = this.head;
398
398
 
399
399
  while (current) {
400
- if (current.val === value) {
400
+ if (current.value === value) {
401
401
  return index;
402
402
  }
403
403
  index++;
@@ -418,7 +418,7 @@ export class SinglyLinkedList<E = any> {
418
418
  let current = this.head;
419
419
 
420
420
  while (current) {
421
- if (current.val === value) {
421
+ if (current.value === value) {
422
422
  return current;
423
423
  }
424
424
  current = current.next;
@@ -440,18 +440,18 @@ export class SinglyLinkedList<E = any> {
440
440
 
441
441
  let existingValue: E;
442
442
  if (existingValueOrNode instanceof SinglyLinkedListNode) {
443
- existingValue = existingValueOrNode.val;
443
+ existingValue = existingValueOrNode.value;
444
444
  } else {
445
445
  existingValue = existingValueOrNode;
446
446
  }
447
- if (this.head.val === existingValue) {
447
+ if (this.head.value === existingValue) {
448
448
  this.unshift(newValue);
449
449
  return true;
450
450
  }
451
451
 
452
452
  let current = this.head;
453
453
  while (current.next) {
454
- if (current.next.val === existingValue) {
454
+ if (current.next.value === existingValue) {
455
455
  const newNode = new SinglyLinkedListNode(newValue);
456
456
  newNode.next = current.next;
457
457
  current.next = newNode;
@@ -505,7 +505,7 @@ export class SinglyLinkedList<E = any> {
505
505
  let current = this.head;
506
506
 
507
507
  while (current) {
508
- if (current.val === value) {
508
+ if (current.value === value) {
509
509
  count++;
510
510
  }
511
511
  current = current.next;
@@ -516,15 +516,15 @@ export class SinglyLinkedList<E = any> {
516
516
 
517
517
  /**
518
518
  * The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
519
- * @param callback - The callback parameter is a function that takes two arguments: val and index. The val argument
519
+ * @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
520
520
  * represents the value of the current node in the linked list, and the index argument represents the index of the
521
521
  * current node in the linked list.
522
522
  */
523
- forEach(callback: (val: E, index: number) => void): void {
523
+ forEach(callback: (value: E, index: number) => void): void {
524
524
  let current = this.head;
525
525
  let index = 0;
526
526
  while (current) {
527
- callback(current.val, index);
527
+ callback(current.value, index);
528
528
  current = current.next;
529
529
  index++;
530
530
  }
@@ -538,11 +538,11 @@ export class SinglyLinkedList<E = any> {
538
538
  * SinglyLinkedList).
539
539
  * @returns The `map` function is returning a new instance of `SinglyLinkedList<U>` that contains the mapped values.
540
540
  */
541
- map<U>(callback: (val: E) => U): SinglyLinkedList<U> {
541
+ map<U>(callback: (value: E) => U): SinglyLinkedList<U> {
542
542
  const mappedList = new SinglyLinkedList<U>();
543
543
  let current = this.head;
544
544
  while (current) {
545
- mappedList.push(callback(current.val));
545
+ mappedList.push(callback(current.value));
546
546
  current = current.next;
547
547
  }
548
548
  return mappedList;
@@ -555,12 +555,12 @@ export class SinglyLinkedList<E = any> {
555
555
  * It is used to determine whether a value should be included in the filtered list or not.
556
556
  * @returns The filtered list, which is an instance of the SinglyLinkedList class.
557
557
  */
558
- filter(callback: (val: E) => boolean): SinglyLinkedList<E> {
558
+ filter(callback: (value: E) => boolean): SinglyLinkedList<E> {
559
559
  const filteredList = new SinglyLinkedList<E>();
560
560
  let current = this.head;
561
561
  while (current) {
562
- if (callback(current.val)) {
563
- filteredList.push(current.val);
562
+ if (callback(current.value)) {
563
+ filteredList.push(current.value);
564
564
  }
565
565
  current = current.next;
566
566
  }
@@ -570,18 +570,18 @@ export class SinglyLinkedList<E = any> {
570
570
  /**
571
571
  * The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
572
572
  * single value.
573
- * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `val`. It is
573
+ * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
574
574
  * used to perform a specific operation on each element of the linked list.
575
575
  * @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
576
576
  * point for the reduction operation.
577
577
  * @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
578
578
  * elements in the linked list.
579
579
  */
580
- reduce<U>(callback: (accumulator: U, val: E) => U, initialValue: U): U {
580
+ reduce<U>(callback: (accumulator: U, value: E) => U, initialValue: U): U {
581
581
  let accumulator = initialValue;
582
582
  let current = this.head;
583
583
  while (current) {
584
- accumulator = callback(accumulator, current.val);
584
+ accumulator = callback(accumulator, current.value);
585
585
  current = current.next;
586
586
  }
587
587
  return accumulator;
@@ -594,7 +594,7 @@ export class SinglyLinkedList<E = any> {
594
594
  let current = this.head;
595
595
 
596
596
  while (current) {
597
- yield current.val;
597
+ yield current.value;
598
598
  current = current.next;
599
599
  }
600
600
  }
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import {SinglyLinkedList} from '../linked-list';
7
7
 
8
- export class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
8
+ export class SkipQueue<E = any> extends SinglyLinkedList<E> {
9
9
  /**
10
10
  * The enqueue function adds a value to the end of an array.
11
11
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
@@ -27,7 +27,7 @@ export class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
27
27
  * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
28
28
  */
29
29
  peek(): E | undefined {
30
- return this.head?.val;
30
+ return this.head?.value;
31
31
  }
32
32
  }
33
33
 
@@ -2,9 +2,9 @@ import {BinaryTreeNode} from '../data-structures';
2
2
  import {BinaryTreeDeletedResult, BTNKey, BinaryTreeNodeNested, BTNCallback} from '../types';
3
3
 
4
4
  export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>> {
5
- createNode(key: BTNKey, val?: N['val']): N;
5
+ createNode(key: BTNKey, value?: N['value']): N;
6
6
 
7
- add(keyOrNode: BTNKey | N | null, val?: N['val']): N | null | undefined;
7
+ add(keyOrNode: BTNKey | N | null, value?: N['value']): N | null | undefined;
8
8
 
9
9
  delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeletedResult<N>[];
10
10
  }
@@ -1,7 +1,7 @@
1
1
  import {VertexKey} from '../types';
2
2
 
3
- export interface IGraph<V, E> {
4
- createVertex(key: VertexKey, val?: V): V;
3
+ export interface IGraph<V, E, VO, EO> {
4
+ createVertex(key: VertexKey, value?: V): VO;
5
5
 
6
- createEdge(srcOrV1: VertexKey | string, destOrV2: VertexKey | string, weight?: number, val?: E): E;
6
+ createEdge(srcOrV1: VertexKey, destOrV2: VertexKey, weight?: number, value?: E): EO;
7
7
  }