data-structure-typed 1.39.0 → 1.39.2

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 (100) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +2 -2
  3. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +96 -32
  4. package/dist/cjs/data-structures/binary-tree/binary-tree.js +46 -8
  5. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  6. package/dist/cjs/data-structures/binary-tree/bst.d.ts +6 -6
  7. package/dist/cjs/data-structures/binary-tree/bst.js +2 -2
  8. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  9. package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +2 -2
  10. package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
  11. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -1
  12. package/dist/cjs/data-structures/graph/abstract-graph.js +1 -1
  13. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  14. package/dist/cjs/data-structures/graph/map-graph.d.ts +1 -1
  15. package/dist/cjs/data-structures/graph/map-graph.js +1 -1
  16. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  17. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +46 -28
  18. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +59 -49
  19. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  20. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +75 -7
  21. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +110 -9
  22. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  23. package/dist/cjs/data-structures/matrix/matrix2d.d.ts +1 -2
  24. package/dist/cjs/data-structures/matrix/matrix2d.js +3 -7
  25. package/dist/cjs/data-structures/matrix/matrix2d.js.map +1 -1
  26. package/dist/cjs/data-structures/matrix/vector2d.d.ts +0 -1
  27. package/dist/cjs/data-structures/matrix/vector2d.js +0 -1
  28. package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
  29. package/dist/cjs/data-structures/queue/deque.d.ts +20 -20
  30. package/dist/cjs/data-structures/queue/deque.js +22 -22
  31. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  32. package/dist/cjs/data-structures/queue/queue.d.ts +3 -3
  33. package/dist/cjs/data-structures/queue/queue.js +3 -3
  34. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  35. package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
  36. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
  37. package/dist/cjs/types/helpers.d.ts +1 -4
  38. package/dist/cjs/types/helpers.js.map +1 -1
  39. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +2 -2
  40. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +96 -32
  41. package/dist/mjs/data-structures/binary-tree/binary-tree.js +46 -8
  42. package/dist/mjs/data-structures/binary-tree/bst.d.ts +6 -6
  43. package/dist/mjs/data-structures/binary-tree/bst.js +2 -2
  44. package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +2 -2
  45. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -1
  46. package/dist/mjs/data-structures/graph/abstract-graph.js +1 -1
  47. package/dist/mjs/data-structures/graph/map-graph.d.ts +1 -1
  48. package/dist/mjs/data-structures/graph/map-graph.js +1 -1
  49. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +46 -28
  50. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +59 -49
  51. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +75 -7
  52. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +110 -9
  53. package/dist/mjs/data-structures/matrix/matrix2d.d.ts +1 -2
  54. package/dist/mjs/data-structures/matrix/matrix2d.js +3 -7
  55. package/dist/mjs/data-structures/matrix/vector2d.d.ts +0 -1
  56. package/dist/mjs/data-structures/matrix/vector2d.js +0 -1
  57. package/dist/mjs/data-structures/queue/deque.d.ts +20 -20
  58. package/dist/mjs/data-structures/queue/deque.js +22 -22
  59. package/dist/mjs/data-structures/queue/queue.d.ts +3 -3
  60. package/dist/mjs/data-structures/queue/queue.js +3 -3
  61. package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
  62. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
  63. package/dist/mjs/types/helpers.d.ts +1 -4
  64. package/dist/umd/data-structure-typed.min.js +1 -1
  65. package/dist/umd/data-structure-typed.min.js.map +1 -1
  66. package/package.json +5 -5
  67. package/src/data-structures/binary-tree/avl-tree.ts +2 -2
  68. package/src/data-structures/binary-tree/binary-tree.ts +76 -90
  69. package/src/data-structures/binary-tree/bst.ts +9 -16
  70. package/src/data-structures/binary-tree/tree-multiset.ts +2 -2
  71. package/src/data-structures/graph/abstract-graph.ts +1 -1
  72. package/src/data-structures/graph/map-graph.ts +2 -2
  73. package/src/data-structures/linked-list/doubly-linked-list.ts +62 -56
  74. package/src/data-structures/linked-list/singly-linked-list.ts +118 -13
  75. package/src/data-structures/matrix/matrix2d.ts +1 -3
  76. package/src/data-structures/matrix/vector2d.ts +0 -2
  77. package/src/data-structures/queue/deque.ts +22 -22
  78. package/src/data-structures/queue/queue.ts +3 -3
  79. package/src/interfaces/binary-tree.ts +2 -2
  80. package/src/types/data-structures/binary-tree/binary-tree.ts +0 -4
  81. package/src/types/helpers.ts +1 -7
  82. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +141 -1
  83. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +289 -47
  84. package/test/unit/data-structures/binary-tree/bst.test.ts +391 -1
  85. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +73 -7
  86. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +241 -186
  87. package/test/unit/data-structures/graph/directed-graph.test.ts +34 -4
  88. package/test/unit/data-structures/graph/map-graph.test.ts +82 -1
  89. package/test/unit/data-structures/graph/undirected-graph.test.ts +82 -0
  90. package/test/unit/data-structures/hash/coordinate-map.test.ts +20 -0
  91. package/test/unit/data-structures/hash/coordinate-set.test.ts +25 -0
  92. package/test/unit/data-structures/hash/hash-table.test.ts +3 -1
  93. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +69 -6
  94. package/test/unit/data-structures/linked-list/linked-list.test.ts +2 -2
  95. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +59 -12
  96. package/test/unit/data-structures/matrix/matrix2d.test.ts +207 -0
  97. package/test/unit/data-structures/matrix/navigator.test.ts +166 -1
  98. package/test/unit/data-structures/matrix/vector2d.test.ts +171 -0
  99. package/test/unit/data-structures/queue/deque.test.ts +283 -20
  100. package/test/unit/data-structures/queue/queue.test.ts +10 -8
@@ -74,16 +74,13 @@ class SinglyLinkedList {
74
74
  }
75
75
  return singlyLinkedList;
76
76
  }
77
- getLength() {
78
- return this._length;
79
- }
80
77
  /**
81
- * The `push` function adds a new node with the given data to the end of a singly linked list.
82
- * @param {E} data - The "data" parameter represents the value that you want to add to the linked list. It can be of
78
+ * The `push` function adds a new node with the given val to the end of a singly linked list.
79
+ * @param {E} val - The "val" parameter represents the value that you want to add to the linked list. It can be of
83
80
  * any type (E) as specified in the generic type declaration of the class or function.
84
81
  */
85
- push(data) {
86
- const newNode = new SinglyLinkedListNode(data);
82
+ push(val) {
83
+ const newNode = new SinglyLinkedListNode(val);
87
84
  if (!this.head) {
88
85
  this.head = newNode;
89
86
  this.tail = newNode;
@@ -94,6 +91,14 @@ class SinglyLinkedList {
94
91
  }
95
92
  this._length++;
96
93
  }
94
+ /**
95
+ * The `push` function adds a new node with the given val to the end of a singly linked list.
96
+ * @param {E} val - The "val" parameter represents the value that you want to add to the linked list. It can be of
97
+ * any type (E) as specified in the generic type declaration of the class or function.
98
+ */
99
+ addLast(val) {
100
+ this.push(val);
101
+ }
97
102
  /**
98
103
  * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
99
104
  * pointers accordingly.
@@ -120,6 +125,15 @@ class SinglyLinkedList {
120
125
  this._length--;
121
126
  return val;
122
127
  }
128
+ /**
129
+ * The `popLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
130
+ * pointers accordingly.
131
+ * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
132
+ * the linked list is empty, it returns `null`.
133
+ */
134
+ popLast() {
135
+ return this.pop();
136
+ }
123
137
  /**
124
138
  * The `shift()` function removes and returns the value of the first node in a linked list.
125
139
  * @returns The value of the node that is being removed from the beginning of the linked list.
@@ -132,6 +146,13 @@ class SinglyLinkedList {
132
146
  this._length--;
133
147
  return removedNode.val;
134
148
  }
149
+ /**
150
+ * The `popFirst()` function removes and returns the value of the first node in a linked list.
151
+ * @returns The value of the node that is being removed from the beginning of the linked list.
152
+ */
153
+ popFirst() {
154
+ return this.shift();
155
+ }
135
156
  /**
136
157
  * The unshift function adds a new node with the given value to the beginning of a singly linked list.
137
158
  * @param {E} val - The parameter "val" represents the value of the new node that will be added to the beginning of the
@@ -149,6 +170,14 @@ class SinglyLinkedList {
149
170
  }
150
171
  this._length++;
151
172
  }
173
+ /**
174
+ * The addFirst 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
176
+ * linked list.
177
+ */
178
+ addFirst(val) {
179
+ this.unshift(val);
180
+ }
152
181
  /**
153
182
  * The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
154
183
  * @param {number} index - The index parameter is a number that represents the position of the element we want to
@@ -355,7 +384,7 @@ class SinglyLinkedList {
355
384
  * @returns a `SinglyLinkedListNode<E>` if a node with the specified value is found in the linked list. If no node with
356
385
  * the specified value is found, the function returns `null`.
357
386
  */
358
- findNode(value) {
387
+ getNode(value) {
359
388
  let current = this.head;
360
389
  while (current) {
361
390
  if (current.val === value) {
@@ -414,7 +443,7 @@ class SinglyLinkedList {
414
443
  existingNode = existingValueOrNode;
415
444
  }
416
445
  else {
417
- existingNode = this.findNode(existingValueOrNode);
446
+ existingNode = this.getNode(existingValueOrNode);
418
447
  }
419
448
  if (existingNode) {
420
449
  const newNode = new SinglyLinkedListNode(newValue);
@@ -444,6 +473,78 @@ class SinglyLinkedList {
444
473
  }
445
474
  return count;
446
475
  }
476
+ /**
477
+ * The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
478
+ * @param callback - The callback parameter is a function that takes two arguments: val and index. The val argument
479
+ * represents the value of the current node in the linked list, and the index argument represents the index of the
480
+ * current node in the linked list.
481
+ */
482
+ forEach(callback) {
483
+ let current = this.head;
484
+ let index = 0;
485
+ while (current) {
486
+ callback(current.val, index);
487
+ current = current.next;
488
+ index++;
489
+ }
490
+ }
491
+ /**
492
+ * The `map` function takes a callback function and applies it to each element in the SinglyLinkedList, returning a new
493
+ * SinglyLinkedList with the transformed values.
494
+ * @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
495
+ * the original SinglyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped
496
+ * SinglyLinkedList).
497
+ * @returns The `map` function is returning a new instance of `SinglyLinkedList<U>` that contains the mapped values.
498
+ */
499
+ map(callback) {
500
+ const mappedList = new SinglyLinkedList();
501
+ let current = this.head;
502
+ while (current) {
503
+ mappedList.push(callback(current.val));
504
+ current = current.next;
505
+ }
506
+ return mappedList;
507
+ }
508
+ /**
509
+ * The `filter` function iterates through a SinglyLinkedList and returns a new SinglyLinkedList containing only the
510
+ * elements that satisfy the given callback function.
511
+ * @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
512
+ * It is used to determine whether a value should be included in the filtered list or not.
513
+ * @returns The filtered list, which is an instance of the SinglyLinkedList class.
514
+ */
515
+ filter(callback) {
516
+ const filteredList = new SinglyLinkedList();
517
+ let current = this.head;
518
+ while (current) {
519
+ if (callback(current.val)) {
520
+ filteredList.push(current.val);
521
+ }
522
+ current = current.next;
523
+ }
524
+ return filteredList;
525
+ }
526
+ /**
527
+ * The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
528
+ * single value.
529
+ * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `val`. It is
530
+ * used to perform a specific operation on each element of the linked list.
531
+ * @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
532
+ * point for the reduction operation.
533
+ * @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
534
+ * elements in the linked list.
535
+ */
536
+ reduce(callback, initialValue) {
537
+ let accumulator = initialValue;
538
+ let current = this.head;
539
+ while (current) {
540
+ accumulator = callback(accumulator, current.val);
541
+ current = current.next;
542
+ }
543
+ return accumulator;
544
+ }
545
+ /**
546
+ * The function returns an iterator that iterates over the values of a linked list.
547
+ */
447
548
  *[Symbol.iterator]() {
448
549
  let current = this.head;
449
550
  while (current) {
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import Vector2D from './vector2d';
8
+ import { Vector2D } from './vector2d';
9
9
  export declare class Matrix2D {
10
10
  private readonly _matrix;
11
11
  /**
@@ -105,4 +105,3 @@ export declare class Matrix2D {
105
105
  */
106
106
  toVector(): Vector2D;
107
107
  }
108
- export default Matrix2D;
@@ -1,7 +1,4 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Matrix2D = void 0;
7
4
  /**
@@ -11,7 +8,7 @@ exports.Matrix2D = void 0;
11
8
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
12
9
  * @license MIT License
13
10
  */
14
- const vector2d_1 = __importDefault(require("./vector2d"));
11
+ const vector2d_1 = require("./vector2d");
15
12
  class Matrix2D {
16
13
  _matrix;
17
14
  /**
@@ -24,7 +21,7 @@ class Matrix2D {
24
21
  if (typeof value === 'undefined') {
25
22
  this._matrix = Matrix2D.identity;
26
23
  }
27
- else if (value instanceof vector2d_1.default) {
24
+ else if (value instanceof vector2d_1.Vector2D) {
28
25
  this._matrix = Matrix2D.identity;
29
26
  this._matrix[0][0] = value.x;
30
27
  this._matrix[1][0] = value.y;
@@ -197,8 +194,7 @@ class Matrix2D {
197
194
  * the first column of the matrix.
198
195
  */
199
196
  toVector() {
200
- return new vector2d_1.default(this._matrix[0][0], this._matrix[1][0]);
197
+ return new vector2d_1.Vector2D(this._matrix[0][0], this._matrix[1][0]);
201
198
  }
202
199
  }
203
200
  exports.Matrix2D = Matrix2D;
204
- exports.default = Matrix2D;
@@ -198,4 +198,3 @@ export declare class Vector2D {
198
198
  */
199
199
  zero(): void;
200
200
  }
201
- export default Vector2D;
@@ -291,4 +291,3 @@ class Vector2D {
291
291
  }
292
292
  }
293
293
  exports.Vector2D = Vector2D;
294
- exports.default = Vector2D;
@@ -37,25 +37,25 @@ export declare class ObjectDeque<E = number> {
37
37
  */
38
38
  addLast(value: E): void;
39
39
  /**
40
- * The function `pollFirst()` removes and returns the first element in a data structure.
40
+ * The function `popFirst()` removes and returns the first element in a data structure.
41
41
  * @returns The value of the first element in the data structure.
42
42
  */
43
- pollFirst(): E | undefined;
43
+ popFirst(): E | undefined;
44
44
  /**
45
- * The `peekFirst` function returns the first element in an array-like data structure if it exists.
45
+ * The `getFirst` function returns the first element in an array-like data structure if it exists.
46
46
  * @returns The element at the first position of the `_nodes` array.
47
47
  */
48
- peekFirst(): E | undefined;
48
+ getFirst(): E | undefined;
49
49
  /**
50
- * The `pollLast()` function removes and returns the last element in a data structure.
50
+ * The `popLast()` function removes and returns the last element in a data structure.
51
51
  * @returns The value that was removed from the data structure.
52
52
  */
53
- pollLast(): E | undefined;
53
+ popLast(): E | undefined;
54
54
  /**
55
- * The `peekLast()` function returns the last element in an array-like data structure.
55
+ * The `getLast()` function returns the last element in an array-like data structure.
56
56
  * @returns The last element in the array "_nodes" is being returned.
57
57
  */
58
- peekLast(): E | undefined;
58
+ getLast(): E | undefined;
59
59
  /**
60
60
  * The get function returns the element at the specified index in an array-like data structure.
61
61
  * @param {number} index - The index parameter is a number that represents the position of the element you want to
@@ -87,16 +87,16 @@ export declare class ArrayDeque<E> {
87
87
  */
88
88
  addLast(value: E): number;
89
89
  /**
90
- * The function "pollLast" returns and removes the last element from an array, or returns null if the array is empty.
91
- * @returns The method `pollLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
90
+ * The function "popLast" returns and removes the last element from an array, or returns null if the array is empty.
91
+ * @returns The method `popLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
92
92
  */
93
- pollLast(): E | null;
93
+ popLast(): E | null;
94
94
  /**
95
- * The `pollFirst` function removes and returns the first element from an array, or returns null if the array is empty.
96
- * @returns The `pollFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
95
+ * The `popFirst` function removes and returns the first element from an array, or returns null if the array is empty.
96
+ * @returns The `popFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
97
97
  * empty.
98
98
  */
99
- pollFirst(): E | null;
99
+ popFirst(): E | null;
100
100
  /**
101
101
  * O(n) time complexity of adding at the beginning and the end
102
102
  */
@@ -108,16 +108,16 @@ export declare class ArrayDeque<E> {
108
108
  */
109
109
  addFirst(value: E): number;
110
110
  /**
111
- * The `peekFirst` function returns the first element of an array or null if the array is empty.
112
- * @returns The function `peekFirst()` is returning the first element (`E`) of the `_nodes` array. If the array is
111
+ * The `getFirst` function returns the first element of an array or null if the array is empty.
112
+ * @returns The function `getFirst()` is returning the first element (`E`) of the `_nodes` array. If the array is
113
113
  * empty, it will return `null`.
114
114
  */
115
- peekFirst(): E | null;
115
+ getFirst(): E | null;
116
116
  /**
117
- * The `peekLast` function returns the last element of an array or null if the array is empty.
118
- * @returns The method `peekLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
117
+ * The `getLast` function returns the last element of an array or null if the array is empty.
118
+ * @returns The method `getLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
119
119
  */
120
- peekLast(): E | null;
120
+ getLast(): E | null;
121
121
  /**
122
122
  * O(1) time complexity of obtaining the value
123
123
  */
@@ -85,44 +85,44 @@ class ObjectDeque {
85
85
  this._size++;
86
86
  }
87
87
  /**
88
- * The function `pollFirst()` removes and returns the first element in a data structure.
88
+ * The function `popFirst()` removes and returns the first element in a data structure.
89
89
  * @returns The value of the first element in the data structure.
90
90
  */
91
- pollFirst() {
91
+ popFirst() {
92
92
  if (!this._size)
93
93
  return;
94
- const value = this.peekFirst();
94
+ const value = this.getFirst();
95
95
  delete this._nodes[this._first];
96
96
  this._first++;
97
97
  this._size--;
98
98
  return value;
99
99
  }
100
100
  /**
101
- * The `peekFirst` function returns the first element in an array-like data structure if it exists.
101
+ * The `getFirst` function returns the first element in an array-like data structure if it exists.
102
102
  * @returns The element at the first position of the `_nodes` array.
103
103
  */
104
- peekFirst() {
104
+ getFirst() {
105
105
  if (this._size)
106
106
  return this._nodes[this._first];
107
107
  }
108
108
  /**
109
- * The `pollLast()` function removes and returns the last element in a data structure.
109
+ * The `popLast()` function removes and returns the last element in a data structure.
110
110
  * @returns The value that was removed from the data structure.
111
111
  */
112
- pollLast() {
112
+ popLast() {
113
113
  if (!this._size)
114
114
  return;
115
- const value = this.peekLast();
115
+ const value = this.getLast();
116
116
  delete this._nodes[this._last];
117
117
  this._last--;
118
118
  this._size--;
119
119
  return value;
120
120
  }
121
121
  /**
122
- * The `peekLast()` function returns the last element in an array-like data structure.
122
+ * The `getLast()` function returns the last element in an array-like data structure.
123
123
  * @returns The last element in the array "_nodes" is being returned.
124
124
  */
125
- peekLast() {
125
+ getLast() {
126
126
  if (this._size)
127
127
  return this._nodes[this._last];
128
128
  }
@@ -170,18 +170,18 @@ class ArrayDeque {
170
170
  return this._nodes.push(value);
171
171
  }
172
172
  /**
173
- * The function "pollLast" returns and removes the last element from an array, or returns null if the array is empty.
174
- * @returns The method `pollLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
173
+ * The function "popLast" returns and removes the last element from an array, or returns null if the array is empty.
174
+ * @returns The method `popLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
175
175
  */
176
- pollLast() {
176
+ popLast() {
177
177
  return this._nodes.pop() ?? null;
178
178
  }
179
179
  /**
180
- * The `pollFirst` function removes and returns the first element from an array, or returns null if the array is empty.
181
- * @returns The `pollFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
180
+ * The `popFirst` function removes and returns the first element from an array, or returns null if the array is empty.
181
+ * @returns The `popFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
182
182
  * empty.
183
183
  */
184
- pollFirst() {
184
+ popFirst() {
185
185
  return this._nodes.shift() ?? null;
186
186
  }
187
187
  /**
@@ -197,18 +197,18 @@ class ArrayDeque {
197
197
  return this._nodes.unshift(value);
198
198
  }
199
199
  /**
200
- * The `peekFirst` function returns the first element of an array or null if the array is empty.
201
- * @returns The function `peekFirst()` is returning the first element (`E`) of the `_nodes` array. If the array is
200
+ * The `getFirst` function returns the first element of an array or null if the array is empty.
201
+ * @returns The function `getFirst()` is returning the first element (`E`) of the `_nodes` array. If the array is
202
202
  * empty, it will return `null`.
203
203
  */
204
- peekFirst() {
204
+ getFirst() {
205
205
  return this._nodes[0] ?? null;
206
206
  }
207
207
  /**
208
- * The `peekLast` function returns the last element of an array or null if the array is empty.
209
- * @returns The method `peekLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
208
+ * The `getLast` function returns the last element of an array or null if the array is empty.
209
+ * @returns The method `getLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
210
210
  */
211
- peekLast() {
211
+ getLast() {
212
212
  return this._nodes[this._nodes.length - 1] ?? null;
213
213
  }
214
214
  /**
@@ -68,11 +68,11 @@ export declare class Queue<E = any> {
68
68
  */
69
69
  peek(): E | undefined;
70
70
  /**
71
- * The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
72
- * @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
71
+ * The `getLast` function returns the last element in an array-like data structure, or null if the structure is empty.
72
+ * @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
73
73
  * array is empty, it returns `null`.
74
74
  */
75
- peekLast(): E | undefined;
75
+ getLast(): E | undefined;
76
76
  /**
77
77
  * The enqueue function adds a value to the end of a queue.
78
78
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
@@ -110,11 +110,11 @@ class Queue {
110
110
  return this.size > 0 ? this.nodes[this.offset] : undefined;
111
111
  }
112
112
  /**
113
- * The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
114
- * @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
113
+ * The `getLast` function returns the last element in an array-like data structure, or null if the structure is empty.
114
+ * @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
115
115
  * array is empty, it returns `null`.
116
116
  */
117
- peekLast() {
117
+ getLast() {
118
118
  return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
119
119
  }
120
120
  /**
@@ -1,7 +1,7 @@
1
1
  import { BinaryTreeNode } from '../data-structures';
2
- import { BinaryTreeDeletedResult, BinaryTreeNodeKey, BinaryTreeNodeNested, MapCallback } from '../types';
2
+ import { BinaryTreeDeletedResult, BinaryTreeNodeKey, BinaryTreeNodeNested, OneParamCallback } from '../types';
3
3
  export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>> {
4
4
  createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
5
5
  add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
6
- delete<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C): BinaryTreeDeletedResult<N>[];
6
+ delete<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeletedResult<N>[];
7
7
  }
@@ -19,8 +19,6 @@ export declare enum FamilyPosition {
19
19
  MAL_NODE = "MAL_NODE"
20
20
  }
21
21
  export type BinaryTreeNodeKey = number;
22
- export type BFSCallback<N, D = any> = (node: N, level?: number) => D;
23
- export type BFSCallbackReturn<N> = ReturnType<BFSCallback<N>>;
24
22
  export type BinaryTreeDeletedResult<N> = {
25
23
  deleted: N | null | undefined;
26
24
  needBalanced: N | null;
@@ -1,9 +1,6 @@
1
- import { BinaryTreeNodeKey } from './data-structures';
2
1
  export type Comparator<T> = (a: T, b: T) => number;
3
2
  export type DFSOrderPattern = 'pre' | 'in' | 'post';
4
- export type MapCallback<N, D = any> = (node: N) => D;
5
- export type DefaultMapCallback<N, D = BinaryTreeNodeKey> = (node: N) => D;
6
- export type MapCallbackReturn<N> = ReturnType<MapCallback<N>>;
3
+ export type OneParamCallback<N, D = any> = (node: N) => D;
7
4
  export declare enum CP {
8
5
  lt = "lt",
9
6
  eq = "eq",