data-structure-typed 1.48.9 → 1.49.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/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +16 -11
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +12 -4
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +70 -61
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +25 -21
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +20 -13
- package/dist/cjs/data-structures/binary-tree/bst.js +12 -3
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +19 -25
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +21 -35
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +20 -13
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +12 -3
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +9 -3
- package/dist/cjs/data-structures/graph/abstract-graph.js +27 -31
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +8 -1
- package/dist/cjs/data-structures/graph/directed-graph.js +1 -8
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +8 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js +1 -8
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +14 -2
- package/dist/cjs/data-structures/hash/hash-map.js +19 -8
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-table.d.ts +2 -2
- package/dist/cjs/data-structures/hash/hash-table.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +14 -3
- package/dist/cjs/data-structures/heap/heap.js +12 -0
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -1
- package/dist/cjs/data-structures/heap/max-heap.js +10 -7
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.d.ts +11 -1
- package/dist/cjs/data-structures/heap/min-heap.js +10 -7
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +8 -2
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +6 -7
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +0 -7
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +0 -7
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +0 -7
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +9 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -7
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +6 -5
- package/dist/cjs/data-structures/queue/deque.js +6 -12
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +18 -3
- package/dist/cjs/data-structures/queue/queue.js +16 -6
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +15 -5
- package/dist/cjs/data-structures/stack/stack.js +7 -4
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +13 -3
- package/dist/cjs/data-structures/trie/trie.js +11 -8
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +4 -4
- package/dist/cjs/types/common.d.ts +32 -8
- package/dist/cjs/types/common.js +22 -1
- package/dist/cjs/types/common.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -22
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +16 -11
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +12 -4
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +70 -61
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +25 -21
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +20 -13
- package/dist/mjs/data-structures/binary-tree/bst.js +12 -3
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +19 -25
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +21 -34
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +20 -13
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +12 -3
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +9 -3
- package/dist/mjs/data-structures/graph/abstract-graph.js +27 -31
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +8 -1
- package/dist/mjs/data-structures/graph/directed-graph.js +1 -8
- package/dist/mjs/data-structures/graph/map-graph.d.ts +1 -1
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +8 -1
- package/dist/mjs/data-structures/graph/undirected-graph.js +1 -8
- package/dist/mjs/data-structures/hash/hash-map.d.ts +14 -2
- package/dist/mjs/data-structures/hash/hash-map.js +18 -7
- package/dist/mjs/data-structures/hash/hash-table.d.ts +2 -2
- package/dist/mjs/data-structures/heap/heap.d.ts +14 -3
- package/dist/mjs/data-structures/heap/heap.js +13 -1
- package/dist/mjs/data-structures/heap/max-heap.d.ts +11 -1
- package/dist/mjs/data-structures/heap/max-heap.js +9 -6
- package/dist/mjs/data-structures/heap/min-heap.d.ts +11 -1
- package/dist/mjs/data-structures/heap/min-heap.js +9 -6
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +8 -2
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +7 -8
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +0 -7
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +0 -7
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +0 -7
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +9 -1
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +7 -6
- package/dist/mjs/data-structures/queue/deque.d.ts +6 -5
- package/dist/mjs/data-structures/queue/deque.js +6 -12
- package/dist/mjs/data-structures/queue/queue.d.ts +18 -3
- package/dist/mjs/data-structures/queue/queue.js +16 -6
- package/dist/mjs/data-structures/stack/stack.d.ts +15 -5
- package/dist/mjs/data-structures/stack/stack.js +8 -5
- package/dist/mjs/data-structures/trie/trie.d.ts +13 -3
- package/dist/mjs/data-structures/trie/trie.js +12 -9
- package/dist/mjs/interfaces/binary-tree.d.ts +4 -4
- package/dist/mjs/types/common.d.ts +32 -8
- package/dist/mjs/types/common.js +21 -0
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +1 -21
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
- package/dist/umd/data-structure-typed.js +241 -216
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/binary-tree/avl-tree.ts +23 -13
- package/src/data-structures/binary-tree/binary-tree.ts +93 -97
- package/src/data-structures/binary-tree/bst.ts +26 -15
- package/src/data-structures/binary-tree/rb-tree.ts +33 -48
- package/src/data-structures/binary-tree/tree-multimap.ts +32 -14
- package/src/data-structures/graph/abstract-graph.ts +35 -25
- package/src/data-structures/graph/directed-graph.ts +2 -2
- package/src/data-structures/graph/map-graph.ts +1 -1
- package/src/data-structures/graph/undirected-graph.ts +2 -2
- package/src/data-structures/hash/hash-map.ts +20 -3
- package/src/data-structures/hash/hash-table.ts +3 -3
- package/src/data-structures/heap/heap.ts +14 -3
- package/src/data-structures/heap/max-heap.ts +11 -2
- package/src/data-structures/heap/min-heap.ts +11 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +9 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +3 -3
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/priority-queue.ts +9 -2
- package/src/data-structures/queue/deque.ts +7 -9
- package/src/data-structures/queue/queue.ts +18 -3
- package/src/data-structures/stack/stack.ts +16 -6
- package/src/data-structures/trie/trie.ts +13 -4
- package/src/interfaces/binary-tree.ts +5 -5
- package/src/types/common.ts +37 -12
- package/src/types/data-structures/binary-tree/avl-tree.ts +0 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -26
- package/src/types/data-structures/binary-tree/bst.ts +0 -1
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
- package/test/unit/data-structures/graph/directed-graph.test.ts +21 -1
- package/test/unit/data-structures/graph/undirected-graph.test.ts +39 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.49.1",
|
|
4
4
|
"description": "Data Structures of Javascript & TypeScript. 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",
|
|
@@ -10,11 +10,12 @@ import type {
|
|
|
10
10
|
AVLTreeNested,
|
|
11
11
|
AVLTreeNodeNested,
|
|
12
12
|
AVLTreeOptions,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
BinaryTreeDeleteResult,
|
|
14
|
+
BSTNKeyOrNode,
|
|
15
|
+
BTNCallback,
|
|
16
|
+
BTNExemplar,
|
|
17
|
+
BTNKeyOrNode
|
|
16
18
|
} from '../../types';
|
|
17
|
-
import { BTNCallback } from '../../types';
|
|
18
19
|
import { IBinaryTree } from '../../interfaces';
|
|
19
20
|
|
|
20
21
|
export class AVLTreeNode<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, N> {
|
|
@@ -34,7 +35,6 @@ export class AVLTreeNode<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLT
|
|
|
34
35
|
* 5. Efficient Lookups: Offers O(log n) search time, where 'n' is the number of nodes, due to its balanced nature.
|
|
35
36
|
* 6. Complex Insertions and Deletions: Due to rebalancing, these operations are more complex than in a regular BST.
|
|
36
37
|
* 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.
|
|
37
|
-
* 8. Memory Overhead: Stores balance factors (or heights) at each node, leading to slightly higher memory usage compared to a regular BST.
|
|
38
38
|
*/
|
|
39
39
|
export class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, TREE extends AVLTree<K, V, N, TREE> = AVLTree<K, V, N, AVLTreeNested<K, V, N>>>
|
|
40
40
|
extends BST<K, V, N, TREE>
|
|
@@ -42,14 +42,14 @@ export class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeN
|
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* The constructor function initializes an AVLTree object with optional elements and options.
|
|
45
|
-
* @param [elements] - The `elements` parameter is an optional iterable of `
|
|
45
|
+
* @param [elements] - The `elements` parameter is an optional iterable of `BTNExemplar<K, V, N>`
|
|
46
46
|
* objects. It represents a collection of elements that will be added to the AVL tree during
|
|
47
47
|
* initialization.
|
|
48
48
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
49
49
|
* behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
|
|
50
50
|
* provide only a subset of the properties defined in the `AVLTreeOptions` interface.
|
|
51
51
|
*/
|
|
52
|
-
constructor(elements?: Iterable<
|
|
52
|
+
constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<AVLTreeOptions<K>>) {
|
|
53
53
|
super([], options);
|
|
54
54
|
if (elements) super.addMany(elements);
|
|
55
55
|
}
|
|
@@ -83,13 +83,23 @@ export class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeN
|
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* The function checks if an exemplar is an instance of AVLTreeNode.
|
|
86
|
-
* @param exemplar - The `exemplar` parameter is of type `
|
|
86
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
|
|
87
87
|
* @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
|
|
88
88
|
*/
|
|
89
|
-
override isNode(exemplar:
|
|
89
|
+
override isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N {
|
|
90
90
|
return exemplar instanceof AVLTreeNode;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
/**
|
|
94
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
95
|
+
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
96
|
+
* data type.
|
|
97
|
+
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
98
|
+
*/
|
|
99
|
+
override isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K {
|
|
100
|
+
return !(potentialKey instanceof AVLTreeNode)
|
|
101
|
+
}
|
|
102
|
+
|
|
93
103
|
/**
|
|
94
104
|
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
95
105
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -108,7 +118,7 @@ export class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeN
|
|
|
108
118
|
* being added to the binary tree.
|
|
109
119
|
* @returns The method is returning either the inserted node or undefined.
|
|
110
120
|
*/
|
|
111
|
-
override add(keyOrNodeOrEntry:
|
|
121
|
+
override add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V): N | undefined {
|
|
112
122
|
if (keyOrNodeOrEntry === null) return undefined;
|
|
113
123
|
const inserted = super.add(keyOrNodeOrEntry, value);
|
|
114
124
|
if (inserted) this._balancePath(inserted);
|
|
@@ -133,12 +143,12 @@ export class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeN
|
|
|
133
143
|
* that is deleted from the binary tree. It is an optional parameter and if not provided, it will
|
|
134
144
|
* default to the `_defaultOneParamCallback` function. The `callback` function should have a single
|
|
135
145
|
* parameter of type `N
|
|
136
|
-
* @returns The method is returning an array of `
|
|
146
|
+
* @returns The method is returning an array of `BinaryTreeDeleteResult<N>`.
|
|
137
147
|
*/
|
|
138
148
|
override delete<C extends BTNCallback<N>>(
|
|
139
149
|
identifier: ReturnType<C>,
|
|
140
150
|
callback: C = this._defaultOneParamCallback as C
|
|
141
|
-
):
|
|
151
|
+
): BinaryTreeDeleteResult<N>[] {
|
|
142
152
|
if ((identifier as any) instanceof AVLTreeNode) callback = (node => node) as C;
|
|
143
153
|
const deletedResults = super.delete(identifier, callback);
|
|
144
154
|
for (const { needBalanced } of deletedResults) {
|
|
@@ -160,7 +170,7 @@ export class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeN
|
|
|
160
170
|
* @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
|
|
161
171
|
* if either `srcNode` or `destNode` is undefined.
|
|
162
172
|
*/
|
|
163
|
-
protected override _swapProperties(srcNode:
|
|
173
|
+
protected override _swapProperties(srcNode: BSTNKeyOrNode<K, N>, destNode: BSTNKeyOrNode<K, N>): N | undefined {
|
|
164
174
|
srcNode = this.ensureNode(srcNode);
|
|
165
175
|
destNode = this.ensureNode(destNode);
|
|
166
176
|
|