data-structure-typed 1.51.7 → 1.51.9
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 +13 -13
- package/benchmark/report.html +1 -37
- package/benchmark/report.json +15 -387
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +103 -74
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +116 -93
- 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 +82 -62
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +90 -71
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +318 -233
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +492 -392
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +204 -251
- package/dist/cjs/data-structures/binary-tree/bst.js +256 -358
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +74 -85
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +111 -119
- 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 +92 -76
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +105 -93
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +10 -15
- package/dist/cjs/data-structures/graph/abstract-graph.js +10 -15
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +31 -38
- package/dist/cjs/data-structures/hash/hash-map.js +40 -55
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +1 -3
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +2 -3
- package/dist/cjs/data-structures/queue/deque.js +2 -3
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +1 -1
- package/dist/cjs/data-structures/trie/trie.js +1 -1
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +7 -7
- package/dist/cjs/types/common.d.ts +2 -3
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +4 -3
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +4 -3
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +6 -5
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +6 -5
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +4 -3
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -3
- package/dist/cjs/types/utils/utils.d.ts +10 -1
- package/dist/cjs/utils/utils.d.ts +2 -1
- package/dist/cjs/utils/utils.js +27 -1
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +103 -74
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +116 -93
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +82 -62
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +90 -71
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +318 -233
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +493 -393
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +204 -251
- package/dist/mjs/data-structures/binary-tree/bst.js +252 -357
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +74 -85
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +111 -119
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +92 -76
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +105 -93
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +10 -15
- package/dist/mjs/data-structures/graph/abstract-graph.js +10 -15
- package/dist/mjs/data-structures/hash/hash-map.d.ts +31 -38
- package/dist/mjs/data-structures/hash/hash-map.js +41 -55
- package/dist/mjs/data-structures/heap/heap.d.ts +1 -3
- package/dist/mjs/data-structures/queue/deque.d.ts +2 -3
- package/dist/mjs/data-structures/queue/deque.js +2 -3
- package/dist/mjs/data-structures/trie/trie.d.ts +1 -1
- package/dist/mjs/data-structures/trie/trie.js +1 -1
- package/dist/mjs/interfaces/binary-tree.d.ts +7 -7
- package/dist/mjs/types/common.d.ts +2 -3
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +4 -3
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +4 -3
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +6 -5
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +6 -5
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +4 -3
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -3
- package/dist/mjs/types/utils/utils.d.ts +10 -1
- package/dist/mjs/utils/utils.d.ts +2 -1
- package/dist/mjs/utils/utils.js +25 -0
- package/dist/umd/data-structure-typed.js +1427 -1343
- package/dist/umd/data-structure-typed.min.js +4 -4
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +6 -6
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +142 -100
- package/src/data-structures/binary-tree/avl-tree.ts +109 -80
- package/src/data-structures/binary-tree/binary-tree.ts +556 -433
- package/src/data-structures/binary-tree/bst.ts +286 -375
- package/src/data-structures/binary-tree/rb-tree.ts +132 -125
- package/src/data-structures/binary-tree/tree-multi-map.ts +129 -102
- package/src/data-structures/graph/abstract-graph.ts +10 -10
- package/src/data-structures/hash/hash-map.ts +42 -49
- package/src/data-structures/heap/heap.ts +1 -1
- package/src/data-structures/queue/deque.ts +2 -2
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/data-structures/trie/trie.ts +2 -2
- package/src/interfaces/binary-tree.ts +11 -9
- package/src/types/common.ts +2 -3
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +4 -3
- package/src/types/data-structures/binary-tree/avl-tree.ts +4 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +7 -6
- package/src/types/data-structures/binary-tree/bst.ts +6 -5
- package/src/types/data-structures/binary-tree/rb-tree.ts +4 -3
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +4 -3
- package/src/types/utils/utils.ts +14 -1
- package/src/utils/utils.ts +20 -1
- package/test/integration/all-in-one.test.ts +2 -2
- package/test/integration/avl-tree.test.ts +2 -2
- package/test/integration/bst.test.ts +3 -3
- package/test/integration/index.html +95 -11
- package/test/performance/reportor.ts +2 -3
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +75 -7
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +56 -0
- package/test/unit/data-structures/binary-tree/bst.test.ts +6 -6
- package/test/unit/data-structures/binary-tree/overall.test.ts +24 -20
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +6 -6
- package/test/unit/data-structures/graph/directed-graph.test.ts +2 -2
- package/test/unit/utils/utils.test.ts +5 -0
- package/test/utils/big-o.ts +12 -6
- package/test/utils/console.ts +1 -1
- package/tsconfig-base.json +1 -0
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, IterationType, KeyOrNodeOrEntry, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
|
|
9
|
-
import {
|
|
8
|
+
import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, Comparable, IterationType, KeyOrNodeOrEntry, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
|
|
9
|
+
import { BTNEntry } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
|
|
12
|
-
export declare class TreeMultiMapNode<K
|
|
12
|
+
export declare class TreeMultiMapNode<K extends Comparable, V = any, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>> extends RedBlackTreeNode<K, V, NODE> {
|
|
13
13
|
/**
|
|
14
14
|
* The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
|
|
15
15
|
* @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
|
|
@@ -36,17 +36,17 @@ export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMa
|
|
|
36
36
|
*/
|
|
37
37
|
set count(value: number);
|
|
38
38
|
}
|
|
39
|
-
export declare class TreeMultiMap<K
|
|
39
|
+
export declare class TreeMultiMap<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>, TREE extends TreeMultiMap<K, V, R, NODE, TREE> = TreeMultiMap<K, V, R, NODE, TreeMultiMapNested<K, V, R, NODE>>> extends RedBlackTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
|
|
40
40
|
/**
|
|
41
|
-
* The constructor function initializes a
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
41
|
+
* The constructor function initializes a TreeMultiMap object with optional initial data.
|
|
42
|
+
* @param keysOrNodesOrEntriesOrRawElements - The parameter `keysOrNodesOrEntriesOrRawElements` is an
|
|
43
|
+
* iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
|
|
44
|
+
* TreeMultiMap with initial data.
|
|
45
|
+
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
46
|
+
* behavior of the `TreeMultiMap` constructor. It can include properties such as `compareKeys` and
|
|
47
|
+
* `compareValues`, which are functions used to compare keys and values respectively.
|
|
48
48
|
*/
|
|
49
|
-
constructor(
|
|
49
|
+
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: TreeMultiMapOptions<K, V, R>);
|
|
50
50
|
protected _count: number;
|
|
51
51
|
/**
|
|
52
52
|
* The function calculates the sum of the count property of all nodes in a tree structure.
|
|
@@ -69,48 +69,47 @@ export declare class TreeMultiMap<K = any, V = any, NODE extends TreeMultiMapNod
|
|
|
69
69
|
/**
|
|
70
70
|
* The function creates a new TreeMultiMapNode with the specified key, value, color, and count.
|
|
71
71
|
* @param {K} key - The key parameter represents the key of the node being created. It is of type K,
|
|
72
|
-
* which is a generic type representing the
|
|
73
|
-
* @param {V} [value] - The `value` parameter
|
|
74
|
-
* node. It is
|
|
75
|
-
* function. If provided, it should be of type `V`.
|
|
72
|
+
* which is a generic type representing the type of keys in the tree.
|
|
73
|
+
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
74
|
+
* associated with the key in the node. It is of type `V`, which can be any data type.
|
|
76
75
|
* @param {RBTNColor} [color=BLACK] - The color parameter is used to specify the color of the node in
|
|
77
76
|
* a Red-Black Tree. It can have two possible values: 'RED' or 'BLACK'. The default value is 'BLACK'.
|
|
78
77
|
* @param {number} [count] - The `count` parameter represents the number of occurrences of a key in
|
|
79
78
|
* the tree. It is an optional parameter and is used to keep track of the number of values associated
|
|
80
79
|
* with a key in the tree.
|
|
81
|
-
* @returns A new instance of the TreeMultiMapNode class
|
|
80
|
+
* @returns A new instance of the TreeMultiMapNode class, casted as NODE.
|
|
82
81
|
*/
|
|
83
82
|
createNode(key: K, value?: V, color?: RBTNColor, count?: number): NODE;
|
|
84
83
|
/**
|
|
85
84
|
* The function creates a new instance of a TreeMultiMap with the specified options and returns it.
|
|
86
85
|
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
87
|
-
* configuration options for creating the `TreeMultiMap`. It
|
|
88
|
-
*
|
|
86
|
+
* configuration options for creating the `TreeMultiMap`. It is of type `TreeMultiMapOptions<K, V,
|
|
87
|
+
* R>`.
|
|
89
88
|
* @returns a new instance of the `TreeMultiMap` class, with the provided options merged with the
|
|
90
|
-
* existing `iterationType`
|
|
89
|
+
* existing `iterationType` property. The returned value is casted as `TREE`.
|
|
91
90
|
*/
|
|
92
|
-
createTree(options?: TreeMultiMapOptions<K>): TREE;
|
|
91
|
+
createTree(options?: TreeMultiMapOptions<K, V, R>): TREE;
|
|
93
92
|
/**
|
|
94
|
-
* The function `
|
|
95
|
-
*
|
|
96
|
-
* @param
|
|
97
|
-
*
|
|
98
|
-
* @param {V} [value] - The `value` parameter is an optional value
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
93
|
+
* The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
|
|
94
|
+
* node based on the input.
|
|
95
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
96
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
97
|
+
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
98
|
+
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
99
|
+
* an existing node.
|
|
100
|
+
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
101
|
+
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
102
|
+
* @returns either a NODE object or undefined.
|
|
103
103
|
*/
|
|
104
|
-
|
|
104
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): NODE | undefined;
|
|
105
105
|
/**
|
|
106
|
-
* The function
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* of the `TreeMultiMapNode` class.
|
|
106
|
+
* The function checks if the input is an instance of the TreeMultiMapNode class.
|
|
107
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
108
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
109
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
110
|
+
* an instance of the `TreeMultiMapNode` class.
|
|
112
111
|
*/
|
|
113
|
-
isNode(
|
|
112
|
+
isNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
|
|
114
113
|
/**
|
|
115
114
|
* Time Complexity: O(log n)
|
|
116
115
|
* Space Complexity: O(1)
|
|
@@ -119,16 +118,19 @@ export declare class TreeMultiMap<K = any, V = any, NODE extends TreeMultiMapNod
|
|
|
119
118
|
* Time Complexity: O(log n)
|
|
120
119
|
* Space Complexity: O(1)
|
|
121
120
|
*
|
|
122
|
-
* The function overrides the add method
|
|
123
|
-
*
|
|
121
|
+
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
122
|
+
* the count and returning a boolean indicating success.
|
|
123
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
124
|
+
* `keyOrNodeOrEntryOrRawElement` parameter can accept one of the following types:
|
|
124
125
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
125
|
-
* data structure.
|
|
126
|
+
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
126
127
|
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
127
|
-
* be added to the data structure. By default, it is set to 1, meaning that
|
|
128
|
-
*
|
|
129
|
-
* @returns a boolean value.
|
|
128
|
+
* be added to the data structure. By default, it is set to 1, meaning that if no value is provided
|
|
129
|
+
* for `count`, the key-value pair will be added once.
|
|
130
|
+
* @returns The method is returning a boolean value. It returns true if the addition of the new node
|
|
131
|
+
* was successful, and false otherwise.
|
|
130
132
|
*/
|
|
131
|
-
add(
|
|
133
|
+
add(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
|
|
132
134
|
/**
|
|
133
135
|
* Time Complexity: O(log n)
|
|
134
136
|
* Space Complexity: O(1)
|
|
@@ -137,20 +139,18 @@ export declare class TreeMultiMap<K = any, V = any, NODE extends TreeMultiMapNod
|
|
|
137
139
|
* Time Complexity: O(log n)
|
|
138
140
|
* Space Complexity: O(1)
|
|
139
141
|
*
|
|
140
|
-
* The `delete`
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* and the node will be deleted regardless of its count. If set to false (default), the count of the
|
|
153
|
-
* target node will be decremented
|
|
142
|
+
* The function `delete` is used to remove a node from a binary tree and fix the tree if necessary.
|
|
143
|
+
* @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value or
|
|
144
|
+
* key that is used to identify the node that needs to be deleted from the binary tree. It can be of
|
|
145
|
+
* any type that is returned by the callback function `C`. It can also be `null` or `undefined` if
|
|
146
|
+
* the node to be deleted
|
|
147
|
+
* @param {C} callback - The `callback` parameter is a function that is used to determine the
|
|
148
|
+
* equality of nodes in the binary tree. It is optional and has a default value of
|
|
149
|
+
* `this._DEFAULT_CALLBACK`. The `callback` function is used to compare nodes when searching for a
|
|
150
|
+
* specific node or when performing other operations on the
|
|
151
|
+
* @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
|
|
152
|
+
* being deleted. If set to true, the count of the node will not be taken into account when deleting
|
|
153
|
+
* it. If set to false, the count of the node will be decremented by 1 before deleting it.
|
|
154
154
|
* @returns an array of BinaryTreeDeleteResult<NODE> objects.
|
|
155
155
|
*/
|
|
156
156
|
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback?: C, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
|
|
@@ -176,10 +176,12 @@ export declare class TreeMultiMap<K = any, V = any, NODE extends TreeMultiMapNod
|
|
|
176
176
|
*
|
|
177
177
|
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
|
|
178
178
|
* tree using either a recursive or iterative approach.
|
|
179
|
-
* @param iterationType - The `iterationType` parameter is an optional parameter that
|
|
180
|
-
* type of iteration to use when building the balanced binary search tree. It
|
|
181
|
-
*
|
|
182
|
-
*
|
|
179
|
+
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
180
|
+
* specifies the type of iteration to use when building the balanced binary search tree. It has a
|
|
181
|
+
* default value of `this.iterationType`, which means it will use the iteration type specified by the
|
|
182
|
+
* `iterationType` property of the current object.
|
|
183
|
+
* @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
|
|
184
|
+
* balancing operation is successful, and `false` if there are no nodes to balance.
|
|
183
185
|
*/
|
|
184
186
|
perfectlyBalance(iterationType?: IterationType): boolean;
|
|
185
187
|
/**
|
|
@@ -195,24 +197,38 @@ export declare class TreeMultiMap<K = any, V = any, NODE extends TreeMultiMapNod
|
|
|
195
197
|
*/
|
|
196
198
|
clone(): TREE;
|
|
197
199
|
/**
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
*
|
|
200
|
+
* Time Complexity: O(1)
|
|
201
|
+
* Space Complexity: O(1)
|
|
202
|
+
*/
|
|
203
|
+
/**
|
|
204
|
+
* Time Complexity: O(1)
|
|
205
|
+
* Space Complexity: O(1)
|
|
206
|
+
*
|
|
207
|
+
* The `_swapProperties` function swaps the properties (key, value, count, color) between two nodes
|
|
208
|
+
* in a binary search tree.
|
|
209
|
+
* @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
|
|
210
|
+
* that will be swapped with the `destNode`. It can be either an instance of the `R` class or an
|
|
211
|
+
* instance of the `BSTNKeyOrNode<K, NODE>` class.
|
|
212
|
+
* @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
|
|
213
|
+
* node where the properties will be swapped with the source node.
|
|
203
214
|
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
204
|
-
* If
|
|
205
|
-
|
|
206
|
-
|
|
215
|
+
* If either `srcNode` or `destNode` is undefined, it returns undefined.
|
|
216
|
+
*/
|
|
217
|
+
protected _swapProperties(srcNode: R | BSTNKeyOrNode<K, NODE>, destNode: R | BSTNKeyOrNode<K, NODE>): NODE | undefined;
|
|
218
|
+
/**
|
|
219
|
+
* Time Complexity: O(1)
|
|
220
|
+
* Space Complexity: O(1)
|
|
207
221
|
*/
|
|
208
|
-
protected _swapProperties(srcNode: BSTNKeyOrNode<K, NODE>, destNode: BSTNKeyOrNode<K, NODE>): NODE | undefined;
|
|
209
222
|
/**
|
|
223
|
+
* Time Complexity: O(1)
|
|
224
|
+
* Space Complexity: O(1)
|
|
225
|
+
*
|
|
210
226
|
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
211
|
-
* @param {NODE} oldNode - The `oldNode` parameter is
|
|
212
|
-
*
|
|
213
|
-
* @param {NODE} newNode - The `newNode` parameter is an
|
|
227
|
+
* @param {NODE} oldNode - The `oldNode` parameter is the node that you want to replace in the data
|
|
228
|
+
* structure.
|
|
229
|
+
* @param {NODE} newNode - The `newNode` parameter is an instance of the `NODE` class.
|
|
214
230
|
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
215
|
-
* superclass,
|
|
231
|
+
* superclass, which is of type `NODE`.
|
|
216
232
|
*/
|
|
217
233
|
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
|
|
218
234
|
}
|
|
@@ -35,18 +35,18 @@ export class TreeMultiMapNode extends RedBlackTreeNode {
|
|
|
35
35
|
}
|
|
36
36
|
export class TreeMultiMap extends RedBlackTree {
|
|
37
37
|
/**
|
|
38
|
-
* The constructor function initializes a
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
38
|
+
* The constructor function initializes a TreeMultiMap object with optional initial data.
|
|
39
|
+
* @param keysOrNodesOrEntriesOrRawElements - The parameter `keysOrNodesOrEntriesOrRawElements` is an
|
|
40
|
+
* iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
|
|
41
|
+
* TreeMultiMap with initial data.
|
|
42
|
+
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
43
|
+
* behavior of the `TreeMultiMap` constructor. It can include properties such as `compareKeys` and
|
|
44
|
+
* `compareValues`, which are functions used to compare keys and values respectively.
|
|
45
45
|
*/
|
|
46
|
-
constructor(
|
|
46
|
+
constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
|
|
47
47
|
super([], options);
|
|
48
|
-
if (
|
|
49
|
-
this.addMany(
|
|
48
|
+
if (keysOrNodesOrEntriesOrRawElements)
|
|
49
|
+
this.addMany(keysOrNodesOrEntriesOrRawElements);
|
|
50
50
|
}
|
|
51
51
|
_count = 0;
|
|
52
52
|
// TODO the _count is not accurate after nodes count modified
|
|
@@ -77,16 +77,15 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
77
77
|
/**
|
|
78
78
|
* The function creates a new TreeMultiMapNode with the specified key, value, color, and count.
|
|
79
79
|
* @param {K} key - The key parameter represents the key of the node being created. It is of type K,
|
|
80
|
-
* which is a generic type representing the
|
|
81
|
-
* @param {V} [value] - The `value` parameter
|
|
82
|
-
* node. It is
|
|
83
|
-
* function. If provided, it should be of type `V`.
|
|
80
|
+
* which is a generic type representing the type of keys in the tree.
|
|
81
|
+
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
82
|
+
* associated with the key in the node. It is of type `V`, which can be any data type.
|
|
84
83
|
* @param {RBTNColor} [color=BLACK] - The color parameter is used to specify the color of the node in
|
|
85
84
|
* a Red-Black Tree. It can have two possible values: 'RED' or 'BLACK'. The default value is 'BLACK'.
|
|
86
85
|
* @param {number} [count] - The `count` parameter represents the number of occurrences of a key in
|
|
87
86
|
* the tree. It is an optional parameter and is used to keep track of the number of values associated
|
|
88
87
|
* with a key in the tree.
|
|
89
|
-
* @returns A new instance of the TreeMultiMapNode class
|
|
88
|
+
* @returns A new instance of the TreeMultiMapNode class, casted as NODE.
|
|
90
89
|
*/
|
|
91
90
|
createNode(key, value, color = 'BLACK', count) {
|
|
92
91
|
return new TreeMultiMapNode(key, value, count, color);
|
|
@@ -94,10 +93,10 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
94
93
|
/**
|
|
95
94
|
* The function creates a new instance of a TreeMultiMap with the specified options and returns it.
|
|
96
95
|
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
97
|
-
* configuration options for creating the `TreeMultiMap`. It
|
|
98
|
-
*
|
|
96
|
+
* configuration options for creating the `TreeMultiMap`. It is of type `TreeMultiMapOptions<K, V,
|
|
97
|
+
* R>`.
|
|
99
98
|
* @returns a new instance of the `TreeMultiMap` class, with the provided options merged with the
|
|
100
|
-
* existing `iterationType`
|
|
99
|
+
* existing `iterationType` property. The returned value is casted as `TREE`.
|
|
101
100
|
*/
|
|
102
101
|
createTree(options) {
|
|
103
102
|
return new TreeMultiMap([], {
|
|
@@ -106,51 +105,47 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
106
105
|
});
|
|
107
106
|
}
|
|
108
107
|
/**
|
|
109
|
-
* The function `
|
|
110
|
-
*
|
|
111
|
-
* @param
|
|
112
|
-
*
|
|
113
|
-
* @param {V} [value] - The `value` parameter is an optional value
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
108
|
+
* The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
|
|
109
|
+
* node based on the input.
|
|
110
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
111
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
112
|
+
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
113
|
+
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
114
|
+
* an existing node.
|
|
115
|
+
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
116
|
+
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
117
|
+
* @returns either a NODE object or undefined.
|
|
118
118
|
*/
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (keyOrNodeOrEntry === undefined || keyOrNodeOrEntry === null) {
|
|
119
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count = 1) {
|
|
120
|
+
if (keyOrNodeOrEntryOrRawElement === undefined || keyOrNodeOrEntryOrRawElement === null)
|
|
122
121
|
return;
|
|
122
|
+
if (this.isNode(keyOrNodeOrEntryOrRawElement))
|
|
123
|
+
return keyOrNodeOrEntryOrRawElement;
|
|
124
|
+
if (this.toEntryFn) {
|
|
125
|
+
const [key] = this.toEntryFn(keyOrNodeOrEntryOrRawElement);
|
|
126
|
+
if (key)
|
|
127
|
+
return this.getNodeByKey(key);
|
|
123
128
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
else if (this.isEntry(keyOrNodeOrEntry)) {
|
|
128
|
-
const [key, value] = keyOrNodeOrEntry;
|
|
129
|
-
if (key === undefined || key === null) {
|
|
129
|
+
if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
|
|
130
|
+
const [key, value] = keyOrNodeOrEntryOrRawElement;
|
|
131
|
+
if (key === undefined || key === null)
|
|
130
132
|
return;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
node = this.createNode(key, value, 'BLACK', count);
|
|
134
|
-
}
|
|
133
|
+
else
|
|
134
|
+
return this.createNode(key, value, 'BLACK', count);
|
|
135
135
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
else {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
return node;
|
|
136
|
+
if (this.isKey(keyOrNodeOrEntryOrRawElement))
|
|
137
|
+
return this.createNode(keyOrNodeOrEntryOrRawElement, value, 'BLACK', count);
|
|
138
|
+
return;
|
|
143
139
|
}
|
|
144
140
|
/**
|
|
145
|
-
* The function
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* of the `TreeMultiMapNode` class.
|
|
141
|
+
* The function checks if the input is an instance of the TreeMultiMapNode class.
|
|
142
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
143
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
144
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
145
|
+
* an instance of the `TreeMultiMapNode` class.
|
|
151
146
|
*/
|
|
152
|
-
isNode(
|
|
153
|
-
return
|
|
147
|
+
isNode(keyOrNodeOrEntryOrRawElement) {
|
|
148
|
+
return keyOrNodeOrEntryOrRawElement instanceof TreeMultiMapNode;
|
|
154
149
|
}
|
|
155
150
|
/**
|
|
156
151
|
* Time Complexity: O(log n)
|
|
@@ -160,17 +155,20 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
160
155
|
* Time Complexity: O(log n)
|
|
161
156
|
* Space Complexity: O(1)
|
|
162
157
|
*
|
|
163
|
-
* The function overrides the add method
|
|
164
|
-
*
|
|
158
|
+
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
159
|
+
* the count and returning a boolean indicating success.
|
|
160
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
161
|
+
* `keyOrNodeOrEntryOrRawElement` parameter can accept one of the following types:
|
|
165
162
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
166
|
-
* data structure.
|
|
163
|
+
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
167
164
|
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
168
|
-
* be added to the data structure. By default, it is set to 1, meaning that
|
|
169
|
-
*
|
|
170
|
-
* @returns a boolean value.
|
|
165
|
+
* be added to the data structure. By default, it is set to 1, meaning that if no value is provided
|
|
166
|
+
* for `count`, the key-value pair will be added once.
|
|
167
|
+
* @returns The method is returning a boolean value. It returns true if the addition of the new node
|
|
168
|
+
* was successful, and false otherwise.
|
|
171
169
|
*/
|
|
172
|
-
add(
|
|
173
|
-
const newNode = this.
|
|
170
|
+
add(keyOrNodeOrEntryOrRawElement, value, count = 1) {
|
|
171
|
+
const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count);
|
|
174
172
|
const orgCount = newNode?.count || 0;
|
|
175
173
|
const isSuccessAdded = super.add(newNode);
|
|
176
174
|
if (isSuccessAdded) {
|
|
@@ -189,20 +187,18 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
189
187
|
* Time Complexity: O(log n)
|
|
190
188
|
* Space Complexity: O(1)
|
|
191
189
|
*
|
|
192
|
-
* The `delete`
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
* and the node will be deleted regardless of its count. If set to false (default), the count of the
|
|
205
|
-
* target node will be decremented
|
|
190
|
+
* The function `delete` is used to remove a node from a binary tree and fix the tree if necessary.
|
|
191
|
+
* @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value or
|
|
192
|
+
* key that is used to identify the node that needs to be deleted from the binary tree. It can be of
|
|
193
|
+
* any type that is returned by the callback function `C`. It can also be `null` or `undefined` if
|
|
194
|
+
* the node to be deleted
|
|
195
|
+
* @param {C} callback - The `callback` parameter is a function that is used to determine the
|
|
196
|
+
* equality of nodes in the binary tree. It is optional and has a default value of
|
|
197
|
+
* `this._DEFAULT_CALLBACK`. The `callback` function is used to compare nodes when searching for a
|
|
198
|
+
* specific node or when performing other operations on the
|
|
199
|
+
* @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
|
|
200
|
+
* being deleted. If set to true, the count of the node will not be taken into account when deleting
|
|
201
|
+
* it. If set to false, the count of the node will be decremented by 1 before deleting it.
|
|
206
202
|
* @returns an array of BinaryTreeDeleteResult<NODE> objects.
|
|
207
203
|
*/
|
|
208
204
|
delete(identifier, callback = this._DEFAULT_CALLBACK, ignoreCount = false) {
|
|
@@ -318,10 +314,12 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
318
314
|
*
|
|
319
315
|
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
|
|
320
316
|
* tree using either a recursive or iterative approach.
|
|
321
|
-
* @param iterationType - The `iterationType` parameter is an optional parameter that
|
|
322
|
-
* type of iteration to use when building the balanced binary search tree. It
|
|
323
|
-
*
|
|
324
|
-
*
|
|
317
|
+
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
318
|
+
* specifies the type of iteration to use when building the balanced binary search tree. It has a
|
|
319
|
+
* default value of `this.iterationType`, which means it will use the iteration type specified by the
|
|
320
|
+
* `iterationType` property of the current object.
|
|
321
|
+
* @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
|
|
322
|
+
* balancing operation is successful, and `false` if there are no nodes to balance.
|
|
325
323
|
*/
|
|
326
324
|
perfectlyBalance(iterationType = this.iterationType) {
|
|
327
325
|
const sorted = this.dfs(node => node, 'IN'), n = sorted.length;
|
|
@@ -376,15 +374,22 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
376
374
|
return cloned;
|
|
377
375
|
}
|
|
378
376
|
/**
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
*
|
|
377
|
+
* Time Complexity: O(1)
|
|
378
|
+
* Space Complexity: O(1)
|
|
379
|
+
*/
|
|
380
|
+
/**
|
|
381
|
+
* Time Complexity: O(1)
|
|
382
|
+
* Space Complexity: O(1)
|
|
383
|
+
*
|
|
384
|
+
* The `_swapProperties` function swaps the properties (key, value, count, color) between two nodes
|
|
385
|
+
* in a binary search tree.
|
|
386
|
+
* @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
|
|
387
|
+
* that will be swapped with the `destNode`. It can be either an instance of the `R` class or an
|
|
388
|
+
* instance of the `BSTNKeyOrNode<K, NODE>` class.
|
|
389
|
+
* @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
|
|
390
|
+
* node where the properties will be swapped with the source node.
|
|
384
391
|
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
385
|
-
* If
|
|
386
|
-
* and `color` properties. If the swapping is successful, the method returns the modified `destNode`.
|
|
387
|
-
* If either `srcNode` or `destNode` is
|
|
392
|
+
* If either `srcNode` or `destNode` is undefined, it returns undefined.
|
|
388
393
|
*/
|
|
389
394
|
_swapProperties(srcNode, destNode) {
|
|
390
395
|
srcNode = this.ensureNode(srcNode);
|
|
@@ -408,12 +413,19 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
408
413
|
return undefined;
|
|
409
414
|
}
|
|
410
415
|
/**
|
|
416
|
+
* Time Complexity: O(1)
|
|
417
|
+
* Space Complexity: O(1)
|
|
418
|
+
*/
|
|
419
|
+
/**
|
|
420
|
+
* Time Complexity: O(1)
|
|
421
|
+
* Space Complexity: O(1)
|
|
422
|
+
*
|
|
411
423
|
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
412
|
-
* @param {NODE} oldNode - The `oldNode` parameter is
|
|
413
|
-
*
|
|
414
|
-
* @param {NODE} newNode - The `newNode` parameter is an
|
|
424
|
+
* @param {NODE} oldNode - The `oldNode` parameter is the node that you want to replace in the data
|
|
425
|
+
* structure.
|
|
426
|
+
* @param {NODE} newNode - The `newNode` parameter is an instance of the `NODE` class.
|
|
415
427
|
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
416
|
-
* superclass,
|
|
428
|
+
* superclass, which is of type `NODE`.
|
|
417
429
|
*/
|
|
418
430
|
_replaceNode(oldNode, newNode) {
|
|
419
431
|
newNode.count = oldNode.count + newNode.count;
|
|
@@ -231,9 +231,8 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
231
231
|
getMinPathBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean, isDFS?: boolean): VO[] | undefined;
|
|
232
232
|
/**
|
|
233
233
|
* Dijkstra algorithm time: O(VE) space: O(VO + EO)
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
/**
|
|
234
|
+
*/
|
|
235
|
+
/**
|
|
237
236
|
* Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
|
|
238
237
|
* Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
|
|
239
238
|
*/
|
|
@@ -264,9 +263,8 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
264
263
|
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edgeMap.
|
|
265
264
|
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(VO^3), where VO is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
|
|
266
265
|
*
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
/**
|
|
266
|
+
*/
|
|
267
|
+
/**
|
|
270
268
|
* Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
|
|
271
269
|
* Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
|
|
272
270
|
*/
|
|
@@ -295,9 +293,8 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
295
293
|
* Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
|
|
296
294
|
* Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
|
|
297
295
|
* one to rest pairs
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
/**
|
|
296
|
+
*/
|
|
297
|
+
/**
|
|
301
298
|
* Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
|
|
302
299
|
* Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
|
|
303
300
|
*
|
|
@@ -325,9 +322,8 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
325
322
|
};
|
|
326
323
|
/**
|
|
327
324
|
* Dijkstra algorithm time: O(logVE) space: O(VO + EO)
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
/**
|
|
325
|
+
*/
|
|
326
|
+
/**
|
|
331
327
|
* Dijkstra algorithm time: O(logVE) space: O(VO + EO)
|
|
332
328
|
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
|
|
333
329
|
*/
|
|
@@ -343,9 +339,8 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
343
339
|
* Not support graph with negative weight cycle
|
|
344
340
|
* all pairs
|
|
345
341
|
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edgeMap, and it can simultaneously compute shortest paths between any two nodes.
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
/**
|
|
342
|
+
*/
|
|
343
|
+
/**
|
|
349
344
|
* Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
|
|
350
345
|
* Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
|
|
351
346
|
*
|