min-heap-typed 1.39.1 → 1.39.3

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 (35) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +10 -10
  2. package/dist/data-structures/binary-tree/avl-tree.js +4 -4
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +58 -107
  4. package/dist/data-structures/binary-tree/binary-tree.js +65 -27
  5. package/dist/data-structures/binary-tree/bst.d.ts +22 -22
  6. package/dist/data-structures/binary-tree/bst.js +12 -12
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +3 -3
  8. package/dist/data-structures/binary-tree/tree-multiset.d.ts +14 -14
  9. package/dist/data-structures/binary-tree/tree-multiset.js +7 -7
  10. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +46 -28
  11. package/dist/data-structures/linked-list/doubly-linked-list.js +59 -49
  12. package/dist/data-structures/linked-list/singly-linked-list.d.ts +75 -7
  13. package/dist/data-structures/linked-list/singly-linked-list.js +110 -9
  14. package/dist/data-structures/queue/deque.d.ts +20 -20
  15. package/dist/data-structures/queue/deque.js +22 -22
  16. package/dist/data-structures/queue/queue.d.ts +3 -3
  17. package/dist/data-structures/queue/queue.js +3 -3
  18. package/dist/interfaces/binary-tree.d.ts +4 -4
  19. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  20. package/dist/types/data-structures/binary-tree/bst.d.ts +2 -2
  21. package/dist/types/helpers.d.ts +1 -1
  22. package/package.json +2 -2
  23. package/src/data-structures/binary-tree/avl-tree.ts +10 -10
  24. package/src/data-structures/binary-tree/binary-tree.ts +165 -53
  25. package/src/data-structures/binary-tree/bst.ts +29 -31
  26. package/src/data-structures/binary-tree/rb-tree.ts +5 -5
  27. package/src/data-structures/binary-tree/tree-multiset.ts +14 -14
  28. package/src/data-structures/linked-list/doubly-linked-list.ts +62 -56
  29. package/src/data-structures/linked-list/singly-linked-list.ts +118 -13
  30. package/src/data-structures/queue/deque.ts +22 -22
  31. package/src/data-structures/queue/queue.ts +3 -3
  32. package/src/interfaces/binary-tree.ts +4 -4
  33. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  34. package/src/types/data-structures/binary-tree/bst.ts +2 -2
  35. package/src/types/helpers.ts +1 -1
@@ -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
  }
@@ -172,19 +172,19 @@ class ArrayDeque {
172
172
  return this._nodes.push(value);
173
173
  }
174
174
  /**
175
- * The function "pollLast" returns and removes the last element from an array, or returns null if the array is empty.
176
- * @returns The method `pollLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
175
+ * The function "popLast" returns and removes the last element from an array, or returns null if the array is empty.
176
+ * @returns The method `popLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
177
177
  */
178
- pollLast() {
178
+ popLast() {
179
179
  var _a;
180
180
  return (_a = this._nodes.pop()) !== null && _a !== void 0 ? _a : null;
181
181
  }
182
182
  /**
183
- * The `pollFirst` function removes and returns the first element from an array, or returns null if the array is empty.
184
- * @returns The `pollFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
183
+ * The `popFirst` function removes and returns the first element from an array, or returns null if the array is empty.
184
+ * @returns The `popFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
185
185
  * empty.
186
186
  */
187
- pollFirst() {
187
+ popFirst() {
188
188
  var _a;
189
189
  return (_a = this._nodes.shift()) !== null && _a !== void 0 ? _a : null;
190
190
  }
@@ -201,19 +201,19 @@ class ArrayDeque {
201
201
  return this._nodes.unshift(value);
202
202
  }
203
203
  /**
204
- * The `peekFirst` function returns the first element of an array or null if the array is empty.
205
- * @returns The function `peekFirst()` is returning the first element (`E`) of the `_nodes` array. If the array is
204
+ * The `getFirst` function returns the first element of an array or null if the array is empty.
205
+ * @returns The function `getFirst()` is returning the first element (`E`) of the `_nodes` array. If the array is
206
206
  * empty, it will return `null`.
207
207
  */
208
- peekFirst() {
208
+ getFirst() {
209
209
  var _a;
210
210
  return (_a = this._nodes[0]) !== null && _a !== void 0 ? _a : null;
211
211
  }
212
212
  /**
213
- * The `peekLast` function returns the last element of an array or null if the array is empty.
214
- * @returns The method `peekLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
213
+ * The `getLast` function returns the last element of an array or null if the array is empty.
214
+ * @returns The method `getLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
215
215
  */
216
- peekLast() {
216
+ getLast() {
217
217
  var _a;
218
218
  return (_a = this._nodes[this._nodes.length - 1]) !== null && _a !== void 0 ? _a : null;
219
219
  }
@@ -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.
@@ -109,11 +109,11 @@ class Queue {
109
109
  return this.size > 0 ? this.nodes[this.offset] : undefined;
110
110
  }
111
111
  /**
112
- * The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
113
- * @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
112
+ * The `getLast` function returns the last element in an array-like data structure, or null if the structure is empty.
113
+ * @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
114
114
  * array is empty, it returns `null`.
115
115
  */
116
- peekLast() {
116
+ getLast() {
117
117
  return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
118
118
  }
119
119
  /**
@@ -1,7 +1,7 @@
1
1
  import { BinaryTreeNode } from '../data-structures';
2
- import { BinaryTreeDeletedResult, BinaryTreeNodeKey, BinaryTreeNodeNested, OneParamCallback } from '../types';
2
+ import { BinaryTreeDeletedResult, BTNKey, BinaryTreeNodeNested, BTNCallback } from '../types';
3
3
  export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>> {
4
- createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
5
- add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
6
- delete<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeletedResult<N>[];
4
+ createNode(key: BTNKey, val?: N['val']): N;
5
+ add(keyOrNode: BTNKey | N | null, val?: N['val']): N | null | undefined;
6
+ delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeletedResult<N>[];
7
7
  }
@@ -18,7 +18,7 @@ export declare enum FamilyPosition {
18
18
  ISOLATED = "ISOLATED",
19
19
  MAL_NODE = "MAL_NODE"
20
20
  }
21
- export type BinaryTreeNodeKey = number;
21
+ export type BTNKey = number;
22
22
  export type BinaryTreeDeletedResult<N> = {
23
23
  deleted: N | null | undefined;
24
24
  needBalanced: N | null;
@@ -1,6 +1,6 @@
1
1
  import { BSTNode } from '../../../data-structures';
2
- import type { BinaryTreeNodeKey, BinaryTreeOptions } from './binary-tree';
3
- export type BSTComparator = (a: BinaryTreeNodeKey, b: BinaryTreeNodeKey) => number;
2
+ import type { BTNKey, BinaryTreeOptions } from './binary-tree';
3
+ export type BSTComparator = (a: BTNKey, b: BTNKey) => number;
4
4
  export type BSTNodeNested<T> = BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
5
  export type BSTOptions = BinaryTreeOptions & {
6
6
  comparator?: BSTComparator;
@@ -1,6 +1,6 @@
1
1
  export type Comparator<T> = (a: T, b: T) => number;
2
2
  export type DFSOrderPattern = 'pre' | 'in' | 'post';
3
- export type OneParamCallback<N, D = any> = (node: N) => D;
3
+ export type BTNCallback<N, D = any> = (node: N) => D;
4
4
  export declare enum CP {
5
5
  lt = "lt",
6
6
  eq = "eq",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "min-heap-typed",
3
- "version": "1.39.1",
3
+ "version": "1.39.3",
4
4
  "description": "Min Heap. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -131,6 +131,6 @@
131
131
  "typescript": "^4.9.5"
132
132
  },
133
133
  "dependencies": {
134
- "data-structure-typed": "^1.39.0"
134
+ "data-structure-typed": "^1.39.2"
135
135
  }
136
136
  }
@@ -6,14 +6,14 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import {BST, BSTNode} from './bst';
9
- import type {AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeKey} from '../../types';
10
- import {OneParamCallback} from '../../types';
9
+ import type {AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BTNKey} from '../../types';
10
+ import {BTNCallback} from '../../types';
11
11
  import {IBinaryTree} from '../../interfaces';
12
12
 
13
13
  export class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNested<V>> extends BSTNode<V, N> {
14
14
  height: number;
15
15
 
16
- constructor(key: BinaryTreeNodeKey, val?: V) {
16
+ constructor(key: BTNKey, val?: V) {
17
17
  super(key, val);
18
18
  this.height = 0;
19
19
  }
@@ -35,27 +35,27 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
35
35
 
36
36
  /**
37
37
  * The function creates a new AVL tree node with the specified key and value.
38
- * @param {BinaryTreeNodeKey} key - The key parameter is the key value that will be associated with
38
+ * @param {BTNKey} key - The key parameter is the key value that will be associated with
39
39
  * the new node. It is used to determine the position of the node in the binary search tree.
40
40
  * @param [val] - The parameter `val` is an optional value that can be assigned to the node. It is of
41
41
  * type `V`, which means it can be any value that is assignable to the `val` property of the
42
42
  * node type `N`.
43
43
  * @returns a new AVLTreeNode object with the specified key and value.
44
44
  */
45
- override createNode(key: BinaryTreeNodeKey, val?: V): N {
45
+ override createNode(key: BTNKey, val?: V): N {
46
46
  return new AVLTreeNode<V, N>(key, val) as N;
47
47
  }
48
48
 
49
49
  /**
50
50
  * The function overrides the add method of a binary tree node and balances the tree after inserting
51
51
  * a new node.
52
- * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can accept either a
53
- * `BinaryTreeNodeKey` or a `N` (which represents a node in the binary tree) or `null`.
52
+ * @param {BTNKey | N | null} keyOrNode - The `keyOrNode` parameter can accept either a
53
+ * `BTNKey` or a `N` (which represents a node in the binary tree) or `null`.
54
54
  * @param [val] - The `val` parameter is the value that you want to assign to the new node that you
55
55
  * are adding to the binary search tree.
56
56
  * @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
57
57
  */
58
- override add(keyOrNode: BinaryTreeNodeKey | N | null, val?: V): N | null | undefined {
58
+ override add(keyOrNode: BTNKey | N | null, val?: V): N | null | undefined {
59
59
  // TODO support node as a param
60
60
  const inserted = super.add(keyOrNode, val);
61
61
  if (inserted) this._balancePath(inserted);
@@ -66,7 +66,7 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
66
66
  * The function overrides the delete method of a binary tree and balances the tree after deleting a
67
67
  * node if necessary.
68
68
  * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
69
- * `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
69
+ * `BTNKey` or a generic type `N`. It represents the property of the node that we are
70
70
  * searching for. It can be a specific key value or any other property of the node.
71
71
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
72
72
  * value. This value is compared with the `identifier` parameter to determine if the node should be
@@ -74,7 +74,7 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
74
74
  * `this._defaultCallbackByKey`
75
75
  * @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
76
76
  */
77
- override delete<C extends OneParamCallback<N>>(
77
+ override delete<C extends BTNCallback<N>>(
78
78
  identifier: ReturnType<C>,
79
79
  callback: C = this._defaultCallbackByKey as C
80
80
  ): BinaryTreeDeletedResult<N>[] {