directed-graph-typed 1.48.0 → 1.49.0
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 +1 -0
- package/dist/data-structures/base/index.js +17 -0
- package/dist/data-structures/base/iterable-base.d.ts +232 -0
- package/dist/data-structures/base/iterable-base.js +312 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +28 -19
- package/dist/data-structures/binary-tree/avl-tree.js +22 -11
- package/dist/data-structures/binary-tree/binary-tree.d.ts +158 -152
- package/dist/data-structures/binary-tree/binary-tree.js +241 -215
- package/dist/data-structures/binary-tree/bst.d.ts +64 -48
- package/dist/data-structures/binary-tree/bst.js +94 -65
- package/dist/data-structures/binary-tree/rb-tree.d.ts +39 -39
- package/dist/data-structures/binary-tree/rb-tree.js +42 -49
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +60 -34
- package/dist/data-structures/binary-tree/tree-multimap.js +59 -27
- package/dist/data-structures/graph/abstract-graph.d.ts +92 -53
- package/dist/data-structures/graph/abstract-graph.js +130 -103
- package/dist/data-structures/graph/directed-graph.d.ts +70 -52
- package/dist/data-structures/graph/directed-graph.js +111 -65
- package/dist/data-structures/graph/map-graph.d.ts +5 -5
- package/dist/data-structures/graph/map-graph.js +8 -8
- package/dist/data-structures/graph/undirected-graph.d.ts +51 -32
- package/dist/data-structures/graph/undirected-graph.js +117 -54
- package/dist/data-structures/hash/hash-map.d.ts +160 -44
- package/dist/data-structures/hash/hash-map.js +314 -82
- package/dist/data-structures/heap/heap.d.ts +50 -7
- package/dist/data-structures/heap/heap.js +60 -30
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +42 -55
- package/dist/data-structures/linked-list/doubly-linked-list.js +50 -77
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +36 -55
- package/dist/data-structures/linked-list/singly-linked-list.js +44 -77
- package/dist/data-structures/queue/deque.d.ts +35 -167
- package/dist/data-structures/queue/deque.js +43 -249
- package/dist/data-structures/queue/queue.d.ts +49 -48
- package/dist/data-structures/queue/queue.js +69 -82
- package/dist/data-structures/stack/stack.d.ts +43 -10
- package/dist/data-structures/stack/stack.js +50 -31
- package/dist/data-structures/trie/trie.d.ts +41 -6
- package/dist/data-structures/trie/trie.js +53 -32
- package/dist/interfaces/binary-tree.d.ts +6 -6
- package/dist/types/common.d.ts +11 -8
- package/dist/types/common.js +6 -1
- package/dist/types/data-structures/base/base.d.ts +5 -0
- package/dist/types/data-structures/base/base.js +2 -0
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/index.js +17 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +3 -3
- package/dist/types/data-structures/hash/hash-map.d.ts +4 -0
- package/dist/types/data-structures/index.d.ts +1 -0
- package/dist/types/data-structures/index.js +1 -0
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-base.ts +329 -0
- package/src/data-structures/binary-tree/avl-tree.ts +37 -25
- package/src/data-structures/binary-tree/binary-tree.ts +336 -296
- package/src/data-structures/binary-tree/bst.ts +135 -89
- package/src/data-structures/binary-tree/rb-tree.ts +60 -69
- package/src/data-structures/binary-tree/tree-multimap.ts +86 -49
- package/src/data-structures/graph/abstract-graph.ts +136 -104
- package/src/data-structures/graph/directed-graph.ts +114 -65
- package/src/data-structures/graph/map-graph.ts +8 -8
- package/src/data-structures/graph/undirected-graph.ts +124 -56
- package/src/data-structures/hash/hash-map.ts +335 -84
- package/src/data-structures/heap/heap.ts +63 -36
- package/src/data-structures/index.ts +1 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +54 -83
- package/src/data-structures/linked-list/singly-linked-list.ts +49 -84
- package/src/data-structures/queue/deque.ts +43 -275
- package/src/data-structures/queue/queue.ts +71 -86
- package/src/data-structures/stack/stack.ts +53 -34
- package/src/data-structures/trie/trie.ts +58 -35
- package/src/interfaces/binary-tree.ts +5 -6
- package/src/types/common.ts +11 -8
- package/src/types/data-structures/base/base.ts +6 -0
- package/src/types/data-structures/base/index.ts +1 -0
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +6 -5
- package/src/types/data-structures/binary-tree/bst.ts +6 -6
- package/src/types/data-structures/binary-tree/rb-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/tree-multimap.ts +3 -3
- package/src/types/data-structures/hash/hash-map.ts +2 -0
- package/src/types/data-structures/heap/heap.ts +1 -1
- package/src/types/data-structures/index.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
|
@@ -29,7 +29,7 @@ exports.AVLTreeNode = AVLTreeNode;
|
|
|
29
29
|
class AVLTree extends bst_1.BST {
|
|
30
30
|
/**
|
|
31
31
|
* The constructor function initializes an AVLTree object with optional elements and options.
|
|
32
|
-
* @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<V, N>`
|
|
32
|
+
* @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<K, V, N>`
|
|
33
33
|
* objects. It represents a collection of elements that will be added to the AVL tree during
|
|
34
34
|
* initialization.
|
|
35
35
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
@@ -43,7 +43,7 @@ class AVLTree extends bst_1.BST {
|
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
* The function creates a new AVL tree node with the specified key and value.
|
|
46
|
-
* @param {
|
|
46
|
+
* @param {K} key - The key parameter is the key value that will be associated with
|
|
47
47
|
* the new node. It is used to determine the position of the node in the binary search tree.
|
|
48
48
|
* @param [value] - The parameter `value` is an optional value that can be assigned to the node. It is of
|
|
49
49
|
* type `V`, which means it can be any value that is assignable to the `value` property of the
|
|
@@ -61,16 +61,25 @@ class AVLTree extends bst_1.BST {
|
|
|
61
61
|
* @returns a new AVLTree object.
|
|
62
62
|
*/
|
|
63
63
|
createTree(options) {
|
|
64
|
-
return new AVLTree([], Object.assign({ iterationType: this.iterationType,
|
|
64
|
+
return new AVLTree([], Object.assign({ iterationType: this.iterationType, variant: this.variant }, options));
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* The function checks if an exemplar is an instance of AVLTreeNode.
|
|
68
|
-
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<V, N>`.
|
|
68
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
|
|
69
69
|
* @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
|
|
70
70
|
*/
|
|
71
71
|
isNode(exemplar) {
|
|
72
72
|
return exemplar instanceof AVLTreeNode;
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
76
|
+
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
77
|
+
* data type.
|
|
78
|
+
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
79
|
+
*/
|
|
80
|
+
isNotNodeInstance(potentialKey) {
|
|
81
|
+
return !(potentialKey instanceof AVLTreeNode);
|
|
82
|
+
}
|
|
74
83
|
/**
|
|
75
84
|
* 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.
|
|
76
85
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -81,14 +90,16 @@ class AVLTree extends bst_1.BST {
|
|
|
81
90
|
*
|
|
82
91
|
* The function overrides the add method of a binary tree node and balances the tree after inserting
|
|
83
92
|
* a new node.
|
|
84
|
-
* @param keyOrNodeOrEntry - The
|
|
93
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
|
|
85
94
|
* entry.
|
|
86
|
-
* @
|
|
95
|
+
* @param {V} [value] - The `value` parameter represents the value associated with the key that is
|
|
96
|
+
* being added to the binary tree.
|
|
97
|
+
* @returns The method is returning either the inserted node or undefined.
|
|
87
98
|
*/
|
|
88
|
-
add(keyOrNodeOrEntry) {
|
|
99
|
+
add(keyOrNodeOrEntry, value) {
|
|
89
100
|
if (keyOrNodeOrEntry === null)
|
|
90
101
|
return undefined;
|
|
91
|
-
const inserted = super.add(keyOrNodeOrEntry);
|
|
102
|
+
const inserted = super.add(keyOrNodeOrEntry, value);
|
|
92
103
|
if (inserted)
|
|
93
104
|
this._balancePath(inserted);
|
|
94
105
|
return inserted;
|
|
@@ -126,9 +137,9 @@ class AVLTree extends bst_1.BST {
|
|
|
126
137
|
/**
|
|
127
138
|
* The `_swapProperties` function swaps the key, value, and height properties between two nodes in a binary
|
|
128
139
|
* tree.
|
|
129
|
-
* @param {
|
|
130
|
-
* needs to be swapped with the destination node. It can be of type `
|
|
131
|
-
* @param {
|
|
140
|
+
* @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node that
|
|
141
|
+
* needs to be swapped with the destination node. It can be of type `K`, `N`, or `undefined`.
|
|
142
|
+
* @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
|
|
132
143
|
* node where the values from the source node will be swapped to.
|
|
133
144
|
* @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
|
|
134
145
|
* if either `srcNode` or `destNode` is undefined.
|