linked-list-typed 1.51.9 → 1.52.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-structures/base/index.d.ts +2 -1
- package/dist/data-structures/base/index.js +2 -1
- package/dist/data-structures/base/iterable-element-base.d.ts +171 -0
- package/dist/data-structures/base/iterable-element-base.js +225 -0
- package/dist/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
- package/dist/data-structures/base/{iterable-base.js → iterable-entry-base.js} +12 -189
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +13 -13
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
- package/dist/data-structures/binary-tree/avl-tree.d.ts +13 -13
- package/dist/data-structures/binary-tree/avl-tree.js +6 -6
- package/dist/data-structures/binary-tree/binary-tree.d.ts +99 -99
- package/dist/data-structures/binary-tree/binary-tree.js +54 -52
- package/dist/data-structures/binary-tree/bst.d.ts +37 -45
- package/dist/data-structures/binary-tree/bst.js +17 -25
- package/dist/data-structures/binary-tree/rb-tree.d.ts +10 -10
- package/dist/data-structures/binary-tree/rb-tree.js +6 -6
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +12 -12
- package/dist/data-structures/binary-tree/tree-multi-map.js +5 -5
- package/dist/data-structures/graph/directed-graph.js +2 -1
- package/dist/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/data-structures/heap/heap.d.ts +43 -114
- package/dist/data-structures/heap/heap.js +59 -127
- package/dist/data-structures/heap/max-heap.d.ts +50 -4
- package/dist/data-structures/heap/max-heap.js +76 -10
- package/dist/data-structures/heap/min-heap.d.ts +51 -5
- package/dist/data-structures/heap/min-heap.js +68 -11
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
- package/dist/data-structures/linked-list/doubly-linked-list.js +26 -28
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +22 -25
- package/dist/data-structures/linked-list/singly-linked-list.js +29 -26
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
- package/dist/data-structures/priority-queue/max-priority-queue.js +79 -10
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
- package/dist/data-structures/priority-queue/min-priority-queue.js +71 -11
- package/dist/data-structures/priority-queue/priority-queue.d.ts +50 -4
- package/dist/data-structures/priority-queue/priority-queue.js +70 -1
- package/dist/data-structures/queue/deque.d.ts +27 -18
- package/dist/data-structures/queue/deque.js +43 -21
- package/dist/data-structures/queue/queue.d.ts +8 -29
- package/dist/data-structures/queue/queue.js +15 -32
- package/dist/data-structures/stack/stack.d.ts +17 -22
- package/dist/data-structures/stack/stack.js +25 -24
- package/dist/data-structures/trie/trie.d.ts +18 -13
- package/dist/data-structures/trie/trie.js +26 -15
- package/dist/interfaces/binary-tree.d.ts +4 -4
- package/dist/types/common.d.ts +1 -22
- package/dist/types/data-structures/base/base.d.ts +5 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +20 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +5 -3
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -3
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -3
- package/dist/types/data-structures/heap/heap.d.ts +3 -2
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/data-structures/queue/deque.d.ts +4 -2
- package/dist/types/data-structures/queue/queue.d.ts +2 -1
- package/dist/types/data-structures/stack/stack.d.ts +2 -1
- package/dist/types/data-structures/trie/trie.d.ts +3 -2
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +2 -1
- package/src/data-structures/base/iterable-element-base.ts +250 -0
- package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +14 -15
- package/src/data-structures/binary-tree/avl-tree.ts +13 -14
- package/src/data-structures/binary-tree/binary-tree.ts +156 -152
- package/src/data-structures/binary-tree/bst.ts +52 -60
- package/src/data-structures/binary-tree/rb-tree.ts +12 -13
- package/src/data-structures/binary-tree/tree-multi-map.ts +12 -13
- package/src/data-structures/graph/directed-graph.ts +2 -1
- package/src/data-structures/hash/hash-map.ts +4 -4
- package/src/data-structures/heap/heap.ts +71 -152
- package/src/data-structures/heap/max-heap.ts +88 -13
- package/src/data-structures/heap/min-heap.ts +78 -15
- package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
- package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
- package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
- package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
- package/src/data-structures/priority-queue/priority-queue.ts +81 -4
- package/src/data-structures/queue/deque.ts +50 -25
- package/src/data-structures/queue/queue.ts +23 -37
- package/src/data-structures/stack/stack.ts +31 -26
- package/src/data-structures/trie/trie.ts +33 -18
- package/src/interfaces/binary-tree.ts +4 -5
- package/src/types/common.ts +2 -24
- package/src/types/data-structures/base/base.ts +14 -6
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -3
- package/src/types/data-structures/binary-tree/avl-tree.ts +2 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +24 -5
- package/src/types/data-structures/binary-tree/bst.ts +9 -3
- package/src/types/data-structures/binary-tree/rb-tree.ts +2 -3
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -3
- package/src/types/data-structures/heap/heap.ts +4 -1
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
- package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
- package/src/types/data-structures/queue/deque.ts +6 -1
- package/src/types/data-structures/queue/queue.ts +3 -1
- package/src/types/data-structures/stack/stack.ts +3 -1
- package/src/types/data-structures/trie/trie.ts +3 -1
|
@@ -12,16 +12,15 @@ import type {
|
|
|
12
12
|
BinaryTreeDeleteResult,
|
|
13
13
|
BSTNKeyOrNode,
|
|
14
14
|
BTNCallback,
|
|
15
|
-
|
|
16
|
-
IterationType
|
|
17
|
-
KeyOrNodeOrEntry
|
|
15
|
+
BTNKeyOrNodeOrEntry,
|
|
16
|
+
IterationType
|
|
18
17
|
} from '../../types';
|
|
19
18
|
import { BTNEntry } from '../../types';
|
|
20
19
|
import { IBinaryTree } from '../../interfaces';
|
|
21
20
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
22
21
|
|
|
23
22
|
export class AVLTreeMultiMapNode<
|
|
24
|
-
K
|
|
23
|
+
K = any,
|
|
25
24
|
V = any,
|
|
26
25
|
NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>
|
|
27
26
|
> extends AVLTreeNode<K, V, NODE> {
|
|
@@ -64,7 +63,7 @@ export class AVLTreeMultiMapNode<
|
|
|
64
63
|
* The only distinction between a AVLTreeMultiMap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
|
|
65
64
|
*/
|
|
66
65
|
export class AVLTreeMultiMap<
|
|
67
|
-
K
|
|
66
|
+
K = any,
|
|
68
67
|
V = any,
|
|
69
68
|
R = BTNEntry<K, V>,
|
|
70
69
|
NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>,
|
|
@@ -87,7 +86,7 @@ export class AVLTreeMultiMap<
|
|
|
87
86
|
* `compareValues` functions to define custom comparison logic for keys and values, respectively.
|
|
88
87
|
*/
|
|
89
88
|
constructor(
|
|
90
|
-
keysOrNodesOrEntriesOrRawElements: Iterable<R |
|
|
89
|
+
keysOrNodesOrEntriesOrRawElements: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>> = [],
|
|
91
90
|
options?: AVLTreeMultiMapOptions<K, V, R>
|
|
92
91
|
) {
|
|
93
92
|
super([], options);
|
|
@@ -156,13 +155,13 @@ export class AVLTreeMultiMap<
|
|
|
156
155
|
|
|
157
156
|
/**
|
|
158
157
|
* The function checks if the input is an instance of AVLTreeMultiMapNode.
|
|
159
|
-
* @param {R |
|
|
160
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
158
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
159
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
161
160
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
162
161
|
* an instance of the `AVLTreeMultiMapNode` class.
|
|
163
162
|
*/
|
|
164
163
|
override isNode(
|
|
165
|
-
keyOrNodeOrEntryOrRawElement: R |
|
|
164
|
+
keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>
|
|
166
165
|
): keyOrNodeOrEntryOrRawElement is NODE {
|
|
167
166
|
return keyOrNodeOrEntryOrRawElement instanceof AVLTreeMultiMapNode;
|
|
168
167
|
}
|
|
@@ -170,8 +169,8 @@ export class AVLTreeMultiMap<
|
|
|
170
169
|
/**
|
|
171
170
|
* The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
|
|
172
171
|
* a node object.
|
|
173
|
-
* @param {R |
|
|
174
|
-
* `keyOrNodeOrEntryOrRawElement` parameter can be of type `R` or `
|
|
172
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
173
|
+
* `keyOrNodeOrEntryOrRawElement` parameter can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
175
174
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
176
175
|
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
177
176
|
* value is provided, it will default to `undefined`.
|
|
@@ -180,7 +179,7 @@ export class AVLTreeMultiMap<
|
|
|
180
179
|
* @returns either a NODE object or undefined.
|
|
181
180
|
*/
|
|
182
181
|
override keyValueOrEntryOrRawElementToNode(
|
|
183
|
-
keyOrNodeOrEntryOrRawElement: R |
|
|
182
|
+
keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
|
|
184
183
|
value?: V,
|
|
185
184
|
count = 1
|
|
186
185
|
): NODE | undefined {
|
|
@@ -214,9 +213,9 @@ export class AVLTreeMultiMap<
|
|
|
214
213
|
*
|
|
215
214
|
* The function overrides the add method of a TypeScript class to add a new node to a data structure
|
|
216
215
|
* and update the count.
|
|
217
|
-
* @param {R |
|
|
216
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
218
217
|
* `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which can be any type. It
|
|
219
|
-
* can also accept a value of type `
|
|
218
|
+
* can also accept a value of type `BTNKeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
|
|
220
219
|
* entry, or raw element
|
|
221
220
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
222
221
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
@@ -225,7 +224,7 @@ export class AVLTreeMultiMap<
|
|
|
225
224
|
* be added once. However, you can specify a different value for `count` if you want to add
|
|
226
225
|
* @returns a boolean value.
|
|
227
226
|
*/
|
|
228
|
-
override add(keyOrNodeOrEntryOrRawElement: R |
|
|
227
|
+
override add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count = 1): boolean {
|
|
229
228
|
const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count);
|
|
230
229
|
if (newNode === undefined) return false;
|
|
231
230
|
|
|
@@ -13,14 +13,13 @@ import type {
|
|
|
13
13
|
BinaryTreeDeleteResult,
|
|
14
14
|
BSTNKeyOrNode,
|
|
15
15
|
BTNCallback,
|
|
16
|
-
|
|
17
|
-
KeyOrNodeOrEntry
|
|
16
|
+
BTNKeyOrNodeOrEntry
|
|
18
17
|
} from '../../types';
|
|
19
18
|
import { BTNEntry } from '../../types';
|
|
20
19
|
import { IBinaryTree } from '../../interfaces';
|
|
21
20
|
|
|
22
21
|
export class AVLTreeNode<
|
|
23
|
-
K
|
|
22
|
+
K = any,
|
|
24
23
|
V = any,
|
|
25
24
|
NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>
|
|
26
25
|
> extends BSTNode<K, V, NODE> {
|
|
@@ -67,7 +66,7 @@ export class AVLTreeNode<
|
|
|
67
66
|
* 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
|
|
68
67
|
*/
|
|
69
68
|
export class AVLTree<
|
|
70
|
-
K
|
|
69
|
+
K = any,
|
|
71
70
|
V = any,
|
|
72
71
|
R = BTNEntry<K, V>,
|
|
73
72
|
NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>,
|
|
@@ -87,7 +86,7 @@ export class AVLTree<
|
|
|
87
86
|
* `nodeBuilder` (
|
|
88
87
|
*/
|
|
89
88
|
constructor(
|
|
90
|
-
keysOrNodesOrEntriesOrRawElements: Iterable<R |
|
|
89
|
+
keysOrNodesOrEntriesOrRawElements: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>> = [],
|
|
91
90
|
options?: AVLTreeOptions<K, V, R>
|
|
92
91
|
) {
|
|
93
92
|
super([], options);
|
|
@@ -124,13 +123,13 @@ export class AVLTree<
|
|
|
124
123
|
|
|
125
124
|
/**
|
|
126
125
|
* The function checks if the input is an instance of AVLTreeNode.
|
|
127
|
-
* @param {R |
|
|
128
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
126
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
127
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
129
128
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
130
129
|
* an instance of the `AVLTreeNode` class.
|
|
131
130
|
*/
|
|
132
131
|
override isNode(
|
|
133
|
-
keyOrNodeOrEntryOrRawElement: R |
|
|
132
|
+
keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>
|
|
134
133
|
): keyOrNodeOrEntryOrRawElement is NODE {
|
|
135
134
|
return keyOrNodeOrEntryOrRawElement instanceof AVLTreeNode;
|
|
136
135
|
}
|
|
@@ -147,14 +146,14 @@ export class AVLTree<
|
|
|
147
146
|
*
|
|
148
147
|
* The function overrides the add method of a class and inserts a key-value pair into a data
|
|
149
148
|
* structure, then balances the path.
|
|
150
|
-
* @param {R |
|
|
151
|
-
* `keyOrNodeOrEntryOrRawElement` can accept values of type `R`, `
|
|
149
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
150
|
+
* `keyOrNodeOrEntryOrRawElement` can accept values of type `R`, `BTNKeyOrNodeOrEntry<K, V, NODE>`, or
|
|
152
151
|
* `RawElement`.
|
|
153
152
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
154
153
|
* the key or node being added to the data structure.
|
|
155
154
|
* @returns The method is returning a boolean value.
|
|
156
155
|
*/
|
|
157
|
-
override add(keyOrNodeOrEntryOrRawElement: R |
|
|
156
|
+
override add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean {
|
|
158
157
|
if (keyOrNodeOrEntryOrRawElement === null) return false;
|
|
159
158
|
const inserted = super.add(keyOrNodeOrEntryOrRawElement, value);
|
|
160
159
|
if (inserted) this._balancePath(keyOrNodeOrEntryOrRawElement);
|
|
@@ -489,10 +488,10 @@ export class AVLTree<
|
|
|
489
488
|
*
|
|
490
489
|
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
491
490
|
* to restore balance in an AVL tree after inserting a node.
|
|
492
|
-
* @param {R |
|
|
493
|
-
* `
|
|
491
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The `node` parameter can be of type `R` or
|
|
492
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
494
493
|
*/
|
|
495
|
-
protected _balancePath(node: R |
|
|
494
|
+
protected _balancePath(node: R | BTNKeyOrNodeOrEntry<K, V, NODE>): void {
|
|
496
495
|
node = this.ensureNode(node);
|
|
497
496
|
const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
|
|
498
497
|
for (let i = 0; i < path.length; i++) {
|