data-structure-typed 1.52.0 → 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/CHANGELOG.md +1 -1
- package/README.md +128 -41
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +11 -11
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +11 -11
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +6 -6
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +97 -97
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +50 -50
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +35 -35
- package/dist/cjs/data-structures/binary-tree/bst.js +15 -15
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +8 -8
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +6 -6
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +10 -10
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +5 -5
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.js +2 -1
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +7 -0
- package/dist/cjs/data-structures/queue/deque.js +16 -1
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +0 -1
- package/dist/cjs/data-structures/queue/queue.js +0 -1
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/cjs/types/common.d.ts +1 -22
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +18 -1
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -0
- package/dist/cjs/types/data-structures/queue/deque.d.ts +1 -0
- package/dist/cjs/utils/number.js +1 -2
- package/dist/cjs/utils/number.js.map +1 -1
- package/dist/cjs/utils/utils.js +2 -2
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +11 -11
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +11 -11
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +6 -6
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +97 -97
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +50 -50
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +35 -35
- package/dist/mjs/data-structures/binary-tree/bst.js +15 -15
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +8 -8
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +6 -6
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +10 -10
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +5 -5
- package/dist/mjs/data-structures/graph/directed-graph.js +2 -1
- package/dist/mjs/data-structures/queue/deque.d.ts +7 -0
- package/dist/mjs/data-structures/queue/deque.js +16 -1
- package/dist/mjs/data-structures/queue/queue.d.ts +0 -1
- package/dist/mjs/data-structures/queue/queue.js +0 -1
- package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/mjs/types/common.d.ts +1 -22
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +18 -1
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +3 -0
- package/dist/mjs/types/data-structures/queue/deque.d.ts +1 -0
- package/dist/umd/data-structure-typed.js +105 -91
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +7 -7
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +12 -12
- package/src/data-structures/binary-tree/avl-tree.ts +11 -11
- package/src/data-structures/binary-tree/binary-tree.ts +151 -147
- package/src/data-structures/binary-tree/bst.ts +44 -41
- package/src/data-structures/binary-tree/rb-tree.ts +10 -10
- package/src/data-structures/binary-tree/tree-multi-map.ts +10 -10
- package/src/data-structures/graph/directed-graph.ts +2 -1
- package/src/data-structures/queue/deque.ts +15 -1
- package/src/data-structures/queue/queue.ts +0 -1
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/common.ts +2 -24
- package/src/types/data-structures/binary-tree/binary-tree.ts +21 -1
- package/src/types/data-structures/binary-tree/bst.ts +7 -0
- package/src/types/data-structures/queue/deque.ts +4 -1
- package/test/unit/data-structures/graph/directed-graph.test.ts +28 -0
- package/test/unit/data-structures/heap/heap.test.ts +20 -0
- package/test/unit/data-structures/queue/deque.test.ts +19 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "1.52.
|
|
3
|
+
"version": "1.52.1",
|
|
4
4
|
"description": "Javascript Data Structure. Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack. Benchmark compared with C++ STL. API aligned with ES6 and Java.util. Usability is comparable to Python",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/mjs/index.js",
|
|
@@ -66,11 +66,11 @@
|
|
|
66
66
|
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
67
67
|
"@typescript-eslint/parser": "^6.7.4",
|
|
68
68
|
"auto-changelog": "^2.4.0",
|
|
69
|
-
"avl-tree-typed": "^1.
|
|
69
|
+
"avl-tree-typed": "^1.52.0",
|
|
70
70
|
"benchmark": "^2.1.4",
|
|
71
|
-
"binary-tree-typed": "^1.
|
|
72
|
-
"bst-typed": "^1.
|
|
73
|
-
"data-structure-typed": "^1.
|
|
71
|
+
"binary-tree-typed": "^1.52.0",
|
|
72
|
+
"bst-typed": "^1.52.0",
|
|
73
|
+
"data-structure-typed": "^1.52.0",
|
|
74
74
|
"dependency-cruiser": "^14.1.0",
|
|
75
75
|
"doctoc": "^2.2.1",
|
|
76
76
|
"eslint": "^8.50.0",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
80
80
|
"eslint-plugin-import": "^2.28.1",
|
|
81
81
|
"fast-glob": "^3.3.1",
|
|
82
|
-
"heap-typed": "^1.
|
|
82
|
+
"heap-typed": "^1.52.0",
|
|
83
83
|
"istanbul-badges-readme": "^1.8.5",
|
|
84
84
|
"jest": "^29.7.0",
|
|
85
85
|
"js-sdsl": "^4.4.2",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"ts-loader": "^9.4.4",
|
|
89
89
|
"ts-node": "^10.9.1",
|
|
90
90
|
"tsup": "^7.2.0",
|
|
91
|
-
"typedoc": "^0.
|
|
91
|
+
"typedoc": "^0.26.5",
|
|
92
92
|
"typescript": "^5.3.2"
|
|
93
93
|
},
|
|
94
94
|
"keywords": [
|
|
@@ -12,8 +12,8 @@ import type {
|
|
|
12
12
|
BinaryTreeDeleteResult,
|
|
13
13
|
BSTNKeyOrNode,
|
|
14
14
|
BTNCallback,
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
BTNKeyOrNodeOrEntry,
|
|
16
|
+
IterationType
|
|
17
17
|
} from '../../types';
|
|
18
18
|
import { BTNEntry } from '../../types';
|
|
19
19
|
import { IBinaryTree } from '../../interfaces';
|
|
@@ -86,7 +86,7 @@ export class AVLTreeMultiMap<
|
|
|
86
86
|
* `compareValues` functions to define custom comparison logic for keys and values, respectively.
|
|
87
87
|
*/
|
|
88
88
|
constructor(
|
|
89
|
-
keysOrNodesOrEntriesOrRawElements: Iterable<R |
|
|
89
|
+
keysOrNodesOrEntriesOrRawElements: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>> = [],
|
|
90
90
|
options?: AVLTreeMultiMapOptions<K, V, R>
|
|
91
91
|
) {
|
|
92
92
|
super([], options);
|
|
@@ -155,13 +155,13 @@ export class AVLTreeMultiMap<
|
|
|
155
155
|
|
|
156
156
|
/**
|
|
157
157
|
* The function checks if the input is an instance of AVLTreeMultiMapNode.
|
|
158
|
-
* @param {R |
|
|
159
|
-
* `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>`.
|
|
160
160
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
161
161
|
* an instance of the `AVLTreeMultiMapNode` class.
|
|
162
162
|
*/
|
|
163
163
|
override isNode(
|
|
164
|
-
keyOrNodeOrEntryOrRawElement: R |
|
|
164
|
+
keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>
|
|
165
165
|
): keyOrNodeOrEntryOrRawElement is NODE {
|
|
166
166
|
return keyOrNodeOrEntryOrRawElement instanceof AVLTreeMultiMapNode;
|
|
167
167
|
}
|
|
@@ -169,8 +169,8 @@ export class AVLTreeMultiMap<
|
|
|
169
169
|
/**
|
|
170
170
|
* The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
|
|
171
171
|
* a node object.
|
|
172
|
-
* @param {R |
|
|
173
|
-
* `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>`.
|
|
174
174
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
175
175
|
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
176
176
|
* value is provided, it will default to `undefined`.
|
|
@@ -179,7 +179,7 @@ export class AVLTreeMultiMap<
|
|
|
179
179
|
* @returns either a NODE object or undefined.
|
|
180
180
|
*/
|
|
181
181
|
override keyValueOrEntryOrRawElementToNode(
|
|
182
|
-
keyOrNodeOrEntryOrRawElement: R |
|
|
182
|
+
keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
|
|
183
183
|
value?: V,
|
|
184
184
|
count = 1
|
|
185
185
|
): NODE | undefined {
|
|
@@ -213,9 +213,9 @@ export class AVLTreeMultiMap<
|
|
|
213
213
|
*
|
|
214
214
|
* The function overrides the add method of a TypeScript class to add a new node to a data structure
|
|
215
215
|
* and update the count.
|
|
216
|
-
* @param {R |
|
|
216
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
217
217
|
* `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which can be any type. It
|
|
218
|
-
* can also accept a value of type `
|
|
218
|
+
* can also accept a value of type `BTNKeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
|
|
219
219
|
* entry, or raw element
|
|
220
220
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
221
221
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
@@ -224,7 +224,7 @@ export class AVLTreeMultiMap<
|
|
|
224
224
|
* be added once. However, you can specify a different value for `count` if you want to add
|
|
225
225
|
* @returns a boolean value.
|
|
226
226
|
*/
|
|
227
|
-
override add(keyOrNodeOrEntryOrRawElement: R |
|
|
227
|
+
override add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count = 1): boolean {
|
|
228
228
|
const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count);
|
|
229
229
|
if (newNode === undefined) return false;
|
|
230
230
|
|
|
@@ -13,7 +13,7 @@ import type {
|
|
|
13
13
|
BinaryTreeDeleteResult,
|
|
14
14
|
BSTNKeyOrNode,
|
|
15
15
|
BTNCallback,
|
|
16
|
-
|
|
16
|
+
BTNKeyOrNodeOrEntry
|
|
17
17
|
} from '../../types';
|
|
18
18
|
import { BTNEntry } from '../../types';
|
|
19
19
|
import { IBinaryTree } from '../../interfaces';
|
|
@@ -86,7 +86,7 @@ export class AVLTree<
|
|
|
86
86
|
* `nodeBuilder` (
|
|
87
87
|
*/
|
|
88
88
|
constructor(
|
|
89
|
-
keysOrNodesOrEntriesOrRawElements: Iterable<R |
|
|
89
|
+
keysOrNodesOrEntriesOrRawElements: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>> = [],
|
|
90
90
|
options?: AVLTreeOptions<K, V, R>
|
|
91
91
|
) {
|
|
92
92
|
super([], options);
|
|
@@ -123,13 +123,13 @@ export class AVLTree<
|
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
125
|
* The function checks if the input is an instance of AVLTreeNode.
|
|
126
|
-
* @param {R |
|
|
127
|
-
* `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>`.
|
|
128
128
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
129
129
|
* an instance of the `AVLTreeNode` class.
|
|
130
130
|
*/
|
|
131
131
|
override isNode(
|
|
132
|
-
keyOrNodeOrEntryOrRawElement: R |
|
|
132
|
+
keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>
|
|
133
133
|
): keyOrNodeOrEntryOrRawElement is NODE {
|
|
134
134
|
return keyOrNodeOrEntryOrRawElement instanceof AVLTreeNode;
|
|
135
135
|
}
|
|
@@ -146,14 +146,14 @@ export class AVLTree<
|
|
|
146
146
|
*
|
|
147
147
|
* The function overrides the add method of a class and inserts a key-value pair into a data
|
|
148
148
|
* structure, then balances the path.
|
|
149
|
-
* @param {R |
|
|
150
|
-
* `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
|
|
151
151
|
* `RawElement`.
|
|
152
152
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
153
153
|
* the key or node being added to the data structure.
|
|
154
154
|
* @returns The method is returning a boolean value.
|
|
155
155
|
*/
|
|
156
|
-
override add(keyOrNodeOrEntryOrRawElement: R |
|
|
156
|
+
override add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean {
|
|
157
157
|
if (keyOrNodeOrEntryOrRawElement === null) return false;
|
|
158
158
|
const inserted = super.add(keyOrNodeOrEntryOrRawElement, value);
|
|
159
159
|
if (inserted) this._balancePath(keyOrNodeOrEntryOrRawElement);
|
|
@@ -488,10 +488,10 @@ export class AVLTree<
|
|
|
488
488
|
*
|
|
489
489
|
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
490
490
|
* to restore balance in an AVL tree after inserting a node.
|
|
491
|
-
* @param {R |
|
|
492
|
-
* `
|
|
491
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The `node` parameter can be of type `R` or
|
|
492
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
493
493
|
*/
|
|
494
|
-
protected _balancePath(node: R |
|
|
494
|
+
protected _balancePath(node: R | BTNKeyOrNodeOrEntry<K, V, NODE>): void {
|
|
495
495
|
node = this.ensureNode(node);
|
|
496
496
|
const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
|
|
497
497
|
for (let i = 0; i < path.length; i++) {
|