data-structure-typed 1.51.8 → 1.52.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/CHANGELOG.md +1 -1
- package/README.md +13 -13
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +152 -152
- package/dist/cjs/data-structures/base/index.d.ts +2 -1
- package/dist/cjs/data-structures/base/index.js +2 -1
- package/dist/cjs/data-structures/base/index.js.map +1 -1
- package/dist/cjs/data-structures/base/iterable-element-base.d.ts +171 -0
- package/dist/cjs/data-structures/base/iterable-element-base.js +226 -0
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -0
- package/dist/cjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
- package/dist/cjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +13 -190
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +106 -68
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
- 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 +78 -59
- 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 -226
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +475 -363
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +192 -202
- package/dist/cjs/data-structures/binary-tree/bst.js +207 -249
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +73 -74
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +107 -98
- 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 -75
- 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 +33 -40
- 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 +43 -114
- package/dist/cjs/data-structures/heap/heap.js +59 -127
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.d.ts +50 -4
- package/dist/cjs/data-structures/heap/max-heap.js +76 -10
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.d.ts +51 -5
- package/dist/cjs/data-structures/heap/min-heap.js +68 -11
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +26 -28
- 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 +22 -25
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +29 -26
- 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 +50 -4
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +79 -10
- 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 +51 -5
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +71 -11
- 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 +50 -4
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +70 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +21 -20
- package/dist/cjs/data-structures/queue/deque.js +29 -23
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +8 -28
- package/dist/cjs/data-structures/queue/queue.js +15 -31
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +17 -22
- package/dist/cjs/data-structures/stack/stack.js +25 -24
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +19 -14
- package/dist/cjs/data-structures/trie/trie.js +27 -16
- 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 +1 -2
- package/dist/cjs/types/data-structures/base/base.d.ts +5 -2
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -4
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -4
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +4 -5
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -4
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
- package/dist/cjs/types/data-structures/heap/heap.d.ts +3 -2
- package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/cjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/cjs/types/data-structures/queue/deque.d.ts +3 -2
- package/dist/cjs/types/data-structures/queue/queue.d.ts +2 -1
- package/dist/cjs/types/data-structures/stack/stack.d.ts +2 -1
- package/dist/cjs/types/data-structures/trie/trie.d.ts +3 -2
- package/dist/cjs/utils/utils.js +3 -5
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/base/index.d.ts +2 -1
- package/dist/mjs/data-structures/base/index.js +2 -1
- package/dist/mjs/data-structures/base/iterable-element-base.d.ts +171 -0
- package/dist/mjs/data-structures/base/iterable-element-base.js +222 -0
- package/dist/mjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
- package/dist/mjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +10 -186
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +106 -68
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +82 -62
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +78 -59
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +318 -226
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +476 -364
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +192 -202
- package/dist/mjs/data-structures/binary-tree/bst.js +211 -255
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +73 -74
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +107 -98
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +92 -75
- 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 +33 -40
- package/dist/mjs/data-structures/hash/hash-map.js +41 -55
- package/dist/mjs/data-structures/heap/heap.d.ts +43 -114
- package/dist/mjs/data-structures/heap/heap.js +60 -128
- package/dist/mjs/data-structures/heap/max-heap.d.ts +50 -4
- package/dist/mjs/data-structures/heap/max-heap.js +79 -10
- package/dist/mjs/data-structures/heap/min-heap.d.ts +51 -5
- package/dist/mjs/data-structures/heap/min-heap.js +68 -11
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +26 -28
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +29 -26
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +82 -10
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +71 -11
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +70 -1
- package/dist/mjs/data-structures/queue/deque.d.ts +21 -20
- package/dist/mjs/data-structures/queue/deque.js +29 -23
- package/dist/mjs/data-structures/queue/queue.d.ts +8 -28
- package/dist/mjs/data-structures/queue/queue.js +15 -31
- package/dist/mjs/data-structures/stack/stack.d.ts +17 -22
- package/dist/mjs/data-structures/stack/stack.js +25 -24
- package/dist/mjs/data-structures/trie/trie.d.ts +19 -14
- package/dist/mjs/data-structures/trie/trie.js +27 -16
- package/dist/mjs/interfaces/binary-tree.d.ts +7 -7
- package/dist/mjs/types/common.d.ts +1 -2
- package/dist/mjs/types/data-structures/base/base.d.ts +5 -2
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -4
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -4
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +4 -5
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -4
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
- package/dist/mjs/types/data-structures/heap/heap.d.ts +3 -2
- package/dist/mjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/mjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/mjs/types/data-structures/queue/deque.d.ts +3 -2
- package/dist/mjs/types/data-structures/queue/queue.d.ts +2 -1
- package/dist/mjs/types/data-structures/stack/stack.d.ts +2 -1
- package/dist/mjs/types/data-structures/trie/trie.d.ts +3 -2
- package/dist/mjs/utils/utils.js +3 -5
- package/dist/umd/data-structure-typed.js +1949 -1481
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +6 -6
- 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 +144 -95
- package/src/data-structures/binary-tree/avl-tree.ts +96 -69
- package/src/data-structures/binary-tree/binary-tree.ts +535 -403
- package/src/data-structures/binary-tree/bst.ts +247 -277
- package/src/data-structures/binary-tree/rb-tree.ts +123 -103
- package/src/data-structures/binary-tree/tree-multi-map.ts +127 -102
- package/src/data-structures/graph/abstract-graph.ts +10 -10
- package/src/data-structures/hash/hash-map.ts +46 -53
- 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 +37 -26
- package/src/data-structures/queue/queue.ts +23 -36
- package/src/data-structures/stack/stack.ts +31 -26
- package/src/data-structures/trie/trie.ts +35 -20
- package/src/interfaces/binary-tree.ts +9 -9
- package/src/types/common.ts +1 -2
- package/src/types/data-structures/base/base.ts +14 -6
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -4
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -4
- package/src/types/data-structures/binary-tree/binary-tree.ts +6 -6
- package/src/types/data-structures/binary-tree/bst.ts +4 -5
- package/src/types/data-structures/binary-tree/rb-tree.ts +3 -4
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -4
- 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 +3 -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
- package/src/utils/utils.ts +3 -3
- package/test/integration/avl-tree.test.ts +2 -2
- package/test/integration/bst.test.ts +3 -3
- package/test/integration/index.html +25 -11
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +68 -0
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +56 -0
- package/test/unit/data-structures/graph/directed-graph.test.ts +2 -2
- package/test/unit/data-structures/heap/heap.test.ts +80 -0
- package/test/unit/data-structures/heap/max-heap.test.ts +44 -1
- package/test/unit/data-structures/heap/min-heap.test.ts +18 -1
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +42 -0
- package/test/unit/data-structures/queue/deque.test.ts +30 -0
- package/test/unit/data-structures/queue/queue.test.ts +56 -0
- package/test/utils/big-o.ts +12 -6
- package/tsconfig-base.json +1 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +0 -1
|
@@ -5,10 +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,
|
|
8
|
+
import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, IterationType, KeyOrNodeOrEntry, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
|
|
9
|
+
import { BTNEntry } from '../../types';
|
|
9
10
|
import { IBinaryTree } from '../../interfaces';
|
|
10
11
|
import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
|
|
11
|
-
export declare class TreeMultiMapNode<K
|
|
12
|
+
export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>> extends RedBlackTreeNode<K, V, NODE> {
|
|
12
13
|
/**
|
|
13
14
|
* The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
|
|
14
15
|
* @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
|
|
@@ -35,17 +36,17 @@ export declare class TreeMultiMapNode<K extends Comparable, V = any, NODE extend
|
|
|
35
36
|
*/
|
|
36
37
|
set count(value: number);
|
|
37
38
|
}
|
|
38
|
-
export declare class TreeMultiMap<K
|
|
39
|
+
export declare class TreeMultiMap<K = any, 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> {
|
|
39
40
|
/**
|
|
40
|
-
* The constructor function initializes a
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
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.
|
|
47
48
|
*/
|
|
48
|
-
constructor(
|
|
49
|
+
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: TreeMultiMapOptions<K, V, R>);
|
|
49
50
|
protected _count: number;
|
|
50
51
|
/**
|
|
51
52
|
* The function calculates the sum of the count property of all nodes in a tree structure.
|
|
@@ -68,48 +69,47 @@ export declare class TreeMultiMap<K extends Comparable, V = any, NODE extends Tr
|
|
|
68
69
|
/**
|
|
69
70
|
* The function creates a new TreeMultiMapNode with the specified key, value, color, and count.
|
|
70
71
|
* @param {K} key - The key parameter represents the key of the node being created. It is of type K,
|
|
71
|
-
* which is a generic type representing the
|
|
72
|
-
* @param {V} [value] - The `value` parameter
|
|
73
|
-
* node. It is
|
|
74
|
-
* 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.
|
|
75
75
|
* @param {RBTNColor} [color=BLACK] - The color parameter is used to specify the color of the node in
|
|
76
76
|
* a Red-Black Tree. It can have two possible values: 'RED' or 'BLACK'. The default value is 'BLACK'.
|
|
77
77
|
* @param {number} [count] - The `count` parameter represents the number of occurrences of a key in
|
|
78
78
|
* the tree. It is an optional parameter and is used to keep track of the number of values associated
|
|
79
79
|
* with a key in the tree.
|
|
80
|
-
* @returns A new instance of the TreeMultiMapNode class
|
|
80
|
+
* @returns A new instance of the TreeMultiMapNode class, casted as NODE.
|
|
81
81
|
*/
|
|
82
82
|
createNode(key: K, value?: V, color?: RBTNColor, count?: number): NODE;
|
|
83
83
|
/**
|
|
84
84
|
* The function creates a new instance of a TreeMultiMap with the specified options and returns it.
|
|
85
85
|
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
86
|
-
* configuration options for creating the `TreeMultiMap`. It
|
|
87
|
-
*
|
|
86
|
+
* configuration options for creating the `TreeMultiMap`. It is of type `TreeMultiMapOptions<K, V,
|
|
87
|
+
* R>`.
|
|
88
88
|
* @returns a new instance of the `TreeMultiMap` class, with the provided options merged with the
|
|
89
|
-
* existing `iterationType`
|
|
89
|
+
* existing `iterationType` property. The returned value is casted as `TREE`.
|
|
90
90
|
*/
|
|
91
|
-
createTree(options?: TreeMultiMapOptions<K>): TREE;
|
|
91
|
+
createTree(options?: TreeMultiMapOptions<K, V, R>): TREE;
|
|
92
92
|
/**
|
|
93
|
-
* The function `
|
|
94
|
-
*
|
|
95
|
-
* @param
|
|
96
|
-
*
|
|
97
|
-
* @param {V} [value] - The `value` parameter is an optional value
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
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.
|
|
102
103
|
*/
|
|
103
|
-
|
|
104
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): NODE | undefined;
|
|
104
105
|
/**
|
|
105
|
-
* The function
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* 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.
|
|
111
111
|
*/
|
|
112
|
-
isNode(
|
|
112
|
+
isNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
|
|
113
113
|
/**
|
|
114
114
|
* Time Complexity: O(log n)
|
|
115
115
|
* Space Complexity: O(1)
|
|
@@ -118,16 +118,19 @@ export declare class TreeMultiMap<K extends Comparable, V = any, NODE extends Tr
|
|
|
118
118
|
* Time Complexity: O(log n)
|
|
119
119
|
* Space Complexity: O(1)
|
|
120
120
|
*
|
|
121
|
-
* The function overrides the add method
|
|
122
|
-
*
|
|
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:
|
|
123
125
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
124
|
-
* data structure.
|
|
126
|
+
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
125
127
|
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
126
|
-
* be added to the data structure. By default, it is set to 1, meaning that
|
|
127
|
-
*
|
|
128
|
-
* @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.
|
|
129
132
|
*/
|
|
130
|
-
add(
|
|
133
|
+
add(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
|
|
131
134
|
/**
|
|
132
135
|
* Time Complexity: O(log n)
|
|
133
136
|
* Space Complexity: O(1)
|
|
@@ -136,20 +139,18 @@ export declare class TreeMultiMap<K extends Comparable, V = any, NODE extends Tr
|
|
|
136
139
|
* Time Complexity: O(log n)
|
|
137
140
|
* Space Complexity: O(1)
|
|
138
141
|
*
|
|
139
|
-
* The `delete`
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* and the node will be deleted regardless of its count. If set to false (default), the count of the
|
|
152
|
-
* 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.
|
|
153
154
|
* @returns an array of BinaryTreeDeleteResult<NODE> objects.
|
|
154
155
|
*/
|
|
155
156
|
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback?: C, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
|
|
@@ -175,10 +176,12 @@ export declare class TreeMultiMap<K extends Comparable, V = any, NODE extends Tr
|
|
|
175
176
|
*
|
|
176
177
|
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
|
|
177
178
|
* tree using either a recursive or iterative approach.
|
|
178
|
-
* @param iterationType - The `iterationType` parameter is an optional parameter that
|
|
179
|
-
* type of iteration to use when building the balanced binary search tree. It
|
|
180
|
-
*
|
|
181
|
-
*
|
|
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.
|
|
182
185
|
*/
|
|
183
186
|
perfectlyBalance(iterationType?: IterationType): boolean;
|
|
184
187
|
/**
|
|
@@ -194,24 +197,38 @@ export declare class TreeMultiMap<K extends Comparable, V = any, NODE extends Tr
|
|
|
194
197
|
*/
|
|
195
198
|
clone(): TREE;
|
|
196
199
|
/**
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
*
|
|
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.
|
|
202
214
|
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
203
|
-
* If
|
|
204
|
-
|
|
205
|
-
|
|
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)
|
|
206
221
|
*/
|
|
207
|
-
protected _swapProperties(srcNode: BSTNKeyOrNode<K, NODE>, destNode: BSTNKeyOrNode<K, NODE>): NODE | undefined;
|
|
208
222
|
/**
|
|
223
|
+
* Time Complexity: O(1)
|
|
224
|
+
* Space Complexity: O(1)
|
|
225
|
+
*
|
|
209
226
|
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
210
|
-
* @param {NODE} oldNode - The `oldNode` parameter is
|
|
211
|
-
*
|
|
212
|
-
* @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.
|
|
213
230
|
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
214
|
-
* superclass,
|
|
231
|
+
* superclass, which is of type `NODE`.
|
|
215
232
|
*/
|
|
216
233
|
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
|
|
217
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
|
*
|