data-structure-typed 1.52.5 → 1.52.7
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 +33 -30
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +156 -156
- package/dist/cjs/constants/index.d.ts +4 -0
- package/dist/cjs/constants/index.js +9 -0
- package/dist/cjs/constants/index.js.map +1 -0
- package/dist/cjs/data-structures/base/iterable-element-base.d.ts +8 -1
- package/dist/cjs/data-structures/base/iterable-element-base.js +10 -1
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +8 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.js +10 -10
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +43 -44
- 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 +23 -24
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +71 -64
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +2 -2
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +534 -402
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +669 -598
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +72 -65
- package/dist/cjs/data-structures/binary-tree/bst.js +115 -113
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +21 -24
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +40 -39
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +2 -2
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +2 -2
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +44 -43
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/cjs/data-structures/graph/abstract-graph.js +7 -4
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/cjs/data-structures/graph/directed-graph.js +4 -2
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +2 -2
- package/dist/cjs/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/cjs/data-structures/hash/hash-map.js +1 -1
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.js +3 -3
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +7 -7
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +6 -6
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/matrix/matrix.d.ts +2 -2
- package/dist/cjs/data-structures/matrix/navigator.d.ts +2 -2
- package/dist/cjs/data-structures/matrix/navigator.js +4 -2
- package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +3 -3
- package/dist/cjs/data-structures/queue/deque.js +29 -29
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +2 -2
- package/dist/cjs/data-structures/tree/tree.js +2 -0
- package/dist/cjs/data-structures/tree/tree.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +2 -2
- package/dist/cjs/data-structures/trie/trie.js +1 -1
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -6
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/mjs/constants/index.d.ts +4 -0
- package/dist/mjs/constants/index.js +5 -0
- package/dist/mjs/data-structures/base/iterable-element-base.d.ts +8 -1
- package/dist/mjs/data-structures/base/iterable-element-base.js +10 -1
- package/dist/mjs/data-structures/base/iterable-entry-base.d.ts +8 -1
- package/dist/mjs/data-structures/base/iterable-entry-base.js +10 -10
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +44 -44
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +23 -24
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +72 -64
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +2 -2
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +534 -402
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +668 -592
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +72 -65
- package/dist/mjs/data-structures/binary-tree/bst.js +116 -112
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +21 -24
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +41 -38
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +2 -2
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +45 -42
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/mjs/data-structures/graph/abstract-graph.js +7 -4
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/mjs/data-structures/graph/directed-graph.js +4 -2
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +2 -2
- package/dist/mjs/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/mjs/data-structures/hash/hash-map.js +1 -1
- package/dist/mjs/data-structures/heap/heap.js +3 -3
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +7 -7
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +6 -6
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/matrix/matrix.d.ts +2 -2
- package/dist/mjs/data-structures/matrix/navigator.d.ts +2 -2
- package/dist/mjs/data-structures/matrix/navigator.js +4 -2
- package/dist/mjs/data-structures/queue/deque.d.ts +3 -3
- package/dist/mjs/data-structures/queue/deque.js +29 -29
- package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/mjs/data-structures/stack/stack.d.ts +2 -2
- package/dist/mjs/data-structures/tree/tree.js +2 -0
- package/dist/mjs/data-structures/trie/trie.d.ts +2 -2
- package/dist/mjs/data-structures/trie/trie.js +1 -1
- package/dist/mjs/index.d.ts +1 -0
- package/dist/mjs/index.js +1 -0
- package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +1 -5
- package/dist/umd/data-structure-typed.js +1344 -1614
- package/dist/umd/data-structure-typed.min.js +10 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/eslint.config.mjs +69 -0
- package/package.json +30 -28
- package/src/constants/index.ts +4 -0
- package/src/data-structures/base/iterable-element-base.ts +11 -1
- package/src/data-structures/base/iterable-entry-base.ts +11 -19
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +47 -50
- package/src/data-structures/binary-tree/avl-tree.ts +69 -71
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +2 -2
- package/src/data-structures/binary-tree/binary-tree.ts +698 -726
- package/src/data-structures/binary-tree/bst.ts +123 -129
- package/src/data-structures/binary-tree/rb-tree.ts +44 -46
- package/src/data-structures/binary-tree/segment-tree.ts +2 -2
- package/src/data-structures/binary-tree/tree-multi-map.ts +48 -49
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +4 -4
- package/src/data-structures/graph/undirected-graph.ts +2 -2
- package/src/data-structures/hash/hash-map.ts +3 -3
- package/src/data-structures/heap/heap.ts +3 -3
- package/src/data-structures/linked-list/doubly-linked-list.ts +9 -9
- package/src/data-structures/linked-list/singly-linked-list.ts +8 -8
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/matrix/matrix.ts +2 -2
- package/src/data-structures/matrix/navigator.ts +4 -4
- package/src/data-structures/queue/deque.ts +31 -31
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/data-structures/stack/stack.ts +2 -2
- package/src/data-structures/trie/trie.ts +3 -3
- package/src/index.ts +1 -0
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +3 -5
- package/test/config.ts +1 -7
- package/test/integration/all-in-one.test.ts +2 -2
- package/test/integration/avl-tree.test.ts +3 -3
- package/test/integration/bst.test.ts +19 -18
- package/test/integration/heap.test.js +6 -1
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +39 -39
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +140 -112
- package/test/unit/data-structures/binary-tree/bst.test.ts +41 -13
- package/test/unit/data-structures/binary-tree/overall.test.ts +0 -6
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +6 -6
- package/test/unit/data-structures/binary-tree/segment-tree.test.ts +88 -34
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +42 -42
- package/test/unit/data-structures/graph/abstract-graph.test.ts +1 -1
- package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
- package/test/unit/data-structures/graph/undirected-graph.test.ts +14 -2
- package/test/unit/data-structures/hash/hash-map.test.ts +1 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/matrix/navigator.test.ts +2 -2
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +4 -4
- package/test/unit/data-structures/stack/stack.test.ts +6 -0
- package/test/unit/unrestricted-interconversion.test.ts +24 -24
- package/test/utils/big-o.ts +5 -4
- package/.eslintrc.js +0 -64
|
@@ -34,7 +34,7 @@ export class RedBlackTreeNode extends BSTNode {
|
|
|
34
34
|
export class RedBlackTree extends BST {
|
|
35
35
|
/**
|
|
36
36
|
* This is the constructor function for a Red-Black Tree data structure in TypeScript.
|
|
37
|
-
* @param
|
|
37
|
+
* @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
|
|
38
38
|
* iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
|
|
39
39
|
* initialize the RBTree with the provided elements.
|
|
40
40
|
* @param [options] - The `options` parameter is an optional object that can be passed to the
|
|
@@ -42,11 +42,11 @@ export class RedBlackTree extends BST {
|
|
|
42
42
|
* configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
|
|
43
43
|
* depend on the implementation
|
|
44
44
|
*/
|
|
45
|
-
constructor(
|
|
45
|
+
constructor(keysOrNodesOrEntriesOrRaws = [], options) {
|
|
46
46
|
super([], options);
|
|
47
47
|
this._root = this.NIL;
|
|
48
|
-
if (
|
|
49
|
-
this.addMany(
|
|
48
|
+
if (keysOrNodesOrEntriesOrRaws) {
|
|
49
|
+
this.addMany(keysOrNodesOrEntriesOrRaws);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
_root;
|
|
@@ -83,6 +83,8 @@ export class RedBlackTree extends BST {
|
|
|
83
83
|
createTree(options) {
|
|
84
84
|
return new RedBlackTree([], {
|
|
85
85
|
iterationType: this.iterationType,
|
|
86
|
+
comparator: this._comparator,
|
|
87
|
+
toEntryFn: this._toEntryFn,
|
|
86
88
|
...options
|
|
87
89
|
});
|
|
88
90
|
}
|
|
@@ -91,13 +93,13 @@ export class RedBlackTree extends BST {
|
|
|
91
93
|
* Space Complexity: O(1)
|
|
92
94
|
*
|
|
93
95
|
* The function checks if the input is an instance of the RedBlackTreeNode class.
|
|
94
|
-
* @param {
|
|
95
|
-
* `
|
|
96
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
96
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
|
|
97
|
+
* `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
98
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
|
|
97
99
|
* an instance of the `RedBlackTreeNode` class.
|
|
98
100
|
*/
|
|
99
|
-
isNode(
|
|
100
|
-
return
|
|
101
|
+
isNode(keyOrNodeOrEntryOrRaw) {
|
|
102
|
+
return keyOrNodeOrEntryOrRaw instanceof RedBlackTreeNode;
|
|
101
103
|
}
|
|
102
104
|
// /**
|
|
103
105
|
// * Time Complexity: O(1)
|
|
@@ -110,27 +112,27 @@ export class RedBlackTree extends BST {
|
|
|
110
112
|
// *
|
|
111
113
|
// * The function `keyValueOrEntryOrRawElementToNode` takes a key, value, or entry and returns a node if it is
|
|
112
114
|
// * valid, otherwise it returns undefined.
|
|
113
|
-
// * @param {BTNKeyOrNodeOrEntry<K, V, NODE>}
|
|
114
|
-
// * @param {V} [value] - The value associated with the key (if `
|
|
115
|
+
// * @param {BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRaw - The key, value, or entry to convert.
|
|
116
|
+
// * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntryOrRaw` is a key).
|
|
115
117
|
// * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
|
|
116
118
|
// */
|
|
117
|
-
// override keyValueOrEntryOrRawElementToNode(
|
|
119
|
+
// override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V): NODE | undefined {
|
|
118
120
|
//
|
|
119
|
-
// if (
|
|
120
|
-
// if (this.isNode(
|
|
121
|
+
// if (keyOrNodeOrEntryOrRaw === null || keyOrNodeOrEntryOrRaw === undefined) return;
|
|
122
|
+
// if (this.isNode(keyOrNodeOrEntryOrRaw)) return keyOrNodeOrEntryOrRaw;
|
|
121
123
|
//
|
|
122
|
-
// if (this.
|
|
123
|
-
// const [key, entryValue] = this.
|
|
124
|
+
// if (this._toEntryFn) {
|
|
125
|
+
// const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw as R);
|
|
124
126
|
// if (this.isKey(key)) return this.createNode(key, entryValue ?? value, 'RED');
|
|
125
127
|
// }
|
|
126
128
|
//
|
|
127
|
-
// if (this.isEntry(
|
|
128
|
-
// const [key, value] =
|
|
129
|
+
// if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
|
|
130
|
+
// const [key, value] = keyOrNodeOrEntryOrRaw;
|
|
129
131
|
// if (key === undefined || key === null) return;
|
|
130
132
|
// else return this.createNode(key, value, 'RED');
|
|
131
133
|
// }
|
|
132
134
|
//
|
|
133
|
-
// if (this.isKey(
|
|
135
|
+
// if (this.isKey(keyOrNodeOrEntryOrRaw)) return this.createNode(keyOrNodeOrEntryOrRaw, value, 'RED');
|
|
134
136
|
//
|
|
135
137
|
// return ;
|
|
136
138
|
// }
|
|
@@ -151,8 +153,8 @@ export class RedBlackTree extends BST {
|
|
|
151
153
|
*
|
|
152
154
|
* The function adds a new node to a binary search tree and returns true if the node was successfully
|
|
153
155
|
* added.
|
|
154
|
-
* @param {
|
|
155
|
-
* `
|
|
156
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
|
|
157
|
+
* `keyOrNodeOrEntryOrRaw` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
156
158
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
157
159
|
* the key in the data structure. It represents the value that you want to add or update in the data
|
|
158
160
|
* structure.
|
|
@@ -160,8 +162,8 @@ export class RedBlackTree extends BST {
|
|
|
160
162
|
* the method returns true. If the node already exists and its value is updated, the method also
|
|
161
163
|
* returns true. If the node cannot be added or updated, the method returns false.
|
|
162
164
|
*/
|
|
163
|
-
add(
|
|
164
|
-
const newNode = this.keyValueOrEntryOrRawElementToNode(
|
|
165
|
+
add(keyOrNodeOrEntryOrRaw, value) {
|
|
166
|
+
const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value);
|
|
165
167
|
if (!this.isRealNode(newNode))
|
|
166
168
|
return false;
|
|
167
169
|
const insertStatus = this._insert(newNode);
|
|
@@ -183,24 +185,25 @@ export class RedBlackTree extends BST {
|
|
|
183
185
|
* Time Complexity: O(log n)
|
|
184
186
|
* Space Complexity: O(1)
|
|
185
187
|
*
|
|
186
|
-
* The function overrides the delete method
|
|
187
|
-
*
|
|
188
|
-
* @param {
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
* @
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* that extends the `BTNCallback
|
|
196
|
-
* @returns an array of BinaryTreeDeleteResult<NODE> objects.
|
|
188
|
+
* The function overrides the delete method in a binary tree data structure to remove a node based on
|
|
189
|
+
* a given predicate and maintain the binary search tree properties.
|
|
190
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
|
|
191
|
+
* parameter in the `override delete` method is used to specify the condition or key based on which a
|
|
192
|
+
* node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
|
|
193
|
+
* function that determines which node(s) should be deleted.
|
|
194
|
+
* @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<NODE>`
|
|
195
|
+
* objects. Each object in the array contains information about the deleted node and whether
|
|
196
|
+
* balancing is needed.
|
|
197
197
|
*/
|
|
198
|
-
delete(
|
|
199
|
-
if (
|
|
198
|
+
delete(predicate) {
|
|
199
|
+
if (predicate === null)
|
|
200
200
|
return [];
|
|
201
201
|
const results = [];
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
let nodeToDelete;
|
|
203
|
+
if (this._isPredicated(predicate))
|
|
204
|
+
nodeToDelete = this.getNode(predicate);
|
|
205
|
+
else
|
|
206
|
+
nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate);
|
|
204
207
|
if (!nodeToDelete) {
|
|
205
208
|
return results;
|
|
206
209
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* data-structure-typed
|
|
3
3
|
*
|
|
4
|
-
* @author
|
|
5
|
-
* @copyright Copyright (c) 2022
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { SegmentTreeNodeVal } from '../../types';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* data-structure-typed
|
|
3
3
|
*
|
|
4
|
-
* @author
|
|
5
|
-
* @copyright Copyright (c) 2022
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
export class SegmentTreeNode {
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* data-structure-typed
|
|
3
3
|
*
|
|
4
|
-
* @author
|
|
5
|
-
* @copyright Copyright (c) 2022
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeDeleteResult, BSTNKeyOrNode,
|
|
9
|
-
import { BTNEntry } from '../../types';
|
|
8
|
+
import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, BTNPredicate, IterationType, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions, BTNEntry } from '../../types';
|
|
10
9
|
import { IBinaryTree } from '../../interfaces';
|
|
11
10
|
import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
|
|
12
11
|
export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>> extends RedBlackTreeNode<K, V, NODE> {
|
|
@@ -39,14 +38,14 @@ export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMa
|
|
|
39
38
|
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> {
|
|
40
39
|
/**
|
|
41
40
|
* The constructor function initializes a TreeMultiMap object with optional initial data.
|
|
42
|
-
* @param
|
|
41
|
+
* @param keysOrNodesOrEntriesOrRaws - The parameter `keysOrNodesOrEntriesOrRaws` is an
|
|
43
42
|
* iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
|
|
44
43
|
* TreeMultiMap with initial data.
|
|
45
44
|
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
46
45
|
* behavior of the `TreeMultiMap` constructor. It can include properties such as `compareKeys` and
|
|
47
46
|
* `compareValues`, which are functions used to compare keys and values respectively.
|
|
48
47
|
*/
|
|
49
|
-
constructor(
|
|
48
|
+
constructor(keysOrNodesOrEntriesOrRaws?: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: TreeMultiMapOptions<K, V, R>);
|
|
50
49
|
protected _count: number;
|
|
51
50
|
/**
|
|
52
51
|
* The function calculates the sum of the count property of all nodes in a tree structure.
|
|
@@ -88,8 +87,8 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
88
87
|
/**
|
|
89
88
|
* The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
|
|
90
89
|
* node based on the input.
|
|
91
|
-
* @param {
|
|
92
|
-
* `
|
|
90
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
|
|
91
|
+
* `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
93
92
|
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
94
93
|
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
95
94
|
* an existing node.
|
|
@@ -97,23 +96,23 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
97
96
|
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
98
97
|
* @returns either a NODE object or undefined.
|
|
99
98
|
*/
|
|
100
|
-
keyValueOrEntryOrRawElementToNode(
|
|
99
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V, count?: number): NODE | undefined;
|
|
101
100
|
/**
|
|
102
101
|
* The function checks if the input is an instance of the TreeMultiMapNode class.
|
|
103
|
-
* @param {
|
|
104
|
-
* `
|
|
105
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
102
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
|
|
103
|
+
* `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
104
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
|
|
106
105
|
* an instance of the `TreeMultiMapNode` class.
|
|
107
106
|
*/
|
|
108
|
-
isNode(
|
|
107
|
+
isNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE;
|
|
109
108
|
/**
|
|
110
109
|
* Time Complexity: O(log n)
|
|
111
110
|
* Space Complexity: O(1)
|
|
112
111
|
*
|
|
113
112
|
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
114
113
|
* the count and returning a boolean indicating success.
|
|
115
|
-
* @param {
|
|
116
|
-
* `
|
|
114
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
|
|
115
|
+
* `keyOrNodeOrEntryOrRaw` parameter can accept one of the following types:
|
|
117
116
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
118
117
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
119
118
|
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
@@ -122,26 +121,24 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
122
121
|
* @returns The method is returning a boolean value. It returns true if the addition of the new node
|
|
123
122
|
* was successful, and false otherwise.
|
|
124
123
|
*/
|
|
125
|
-
add(
|
|
124
|
+
add(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V, count?: number): boolean;
|
|
126
125
|
/**
|
|
127
126
|
* Time Complexity: O(log n)
|
|
128
127
|
* Space Complexity: O(1)
|
|
129
128
|
*
|
|
130
|
-
* The function `delete`
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* the
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
*/
|
|
144
|
-
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback?: C, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
|
|
129
|
+
* The function `delete` in TypeScript overrides the deletion operation in a binary tree data
|
|
130
|
+
* structure, handling cases where nodes have children and maintaining balance in the tree.
|
|
131
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
|
|
132
|
+
* parameter in the `delete` method is used to specify the condition or key based on which a node
|
|
133
|
+
* should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
|
|
134
|
+
* function.
|
|
135
|
+
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
136
|
+
* boolean flag that determines whether to ignore the count of nodes when performing deletion. If
|
|
137
|
+
* `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
|
|
138
|
+
* `ignoreCount` is `false
|
|
139
|
+
* @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<NODE>` objects.
|
|
140
|
+
*/
|
|
141
|
+
delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
|
|
145
142
|
/**
|
|
146
143
|
* Time Complexity: O(1)
|
|
147
144
|
* Space Complexity: O(1)
|
|
@@ -36,17 +36,17 @@ export class TreeMultiMapNode extends RedBlackTreeNode {
|
|
|
36
36
|
export class TreeMultiMap extends RedBlackTree {
|
|
37
37
|
/**
|
|
38
38
|
* The constructor function initializes a TreeMultiMap object with optional initial data.
|
|
39
|
-
* @param
|
|
39
|
+
* @param keysOrNodesOrEntriesOrRaws - The parameter `keysOrNodesOrEntriesOrRaws` is an
|
|
40
40
|
* iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
|
|
41
41
|
* TreeMultiMap with initial data.
|
|
42
42
|
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
43
43
|
* behavior of the `TreeMultiMap` constructor. It can include properties such as `compareKeys` and
|
|
44
44
|
* `compareValues`, which are functions used to compare keys and values respectively.
|
|
45
45
|
*/
|
|
46
|
-
constructor(
|
|
46
|
+
constructor(keysOrNodesOrEntriesOrRaws = [], options) {
|
|
47
47
|
super([], options);
|
|
48
|
-
if (
|
|
49
|
-
this.addMany(
|
|
48
|
+
if (keysOrNodesOrEntriesOrRaws)
|
|
49
|
+
this.addMany(keysOrNodesOrEntriesOrRaws);
|
|
50
50
|
}
|
|
51
51
|
_count = 0;
|
|
52
52
|
// TODO the _count is not accurate after nodes count modified
|
|
@@ -97,14 +97,16 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
97
97
|
createTree(options) {
|
|
98
98
|
return new TreeMultiMap([], {
|
|
99
99
|
iterationType: this.iterationType,
|
|
100
|
+
comparator: this._comparator,
|
|
101
|
+
toEntryFn: this._toEntryFn,
|
|
100
102
|
...options
|
|
101
103
|
});
|
|
102
104
|
}
|
|
103
105
|
/**
|
|
104
106
|
* The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
|
|
105
107
|
* node based on the input.
|
|
106
|
-
* @param {
|
|
107
|
-
* `
|
|
108
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
|
|
109
|
+
* `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
108
110
|
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
109
111
|
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
110
112
|
* an existing node.
|
|
@@ -112,36 +114,36 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
112
114
|
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
113
115
|
* @returns either a NODE object or undefined.
|
|
114
116
|
*/
|
|
115
|
-
keyValueOrEntryOrRawElementToNode(
|
|
116
|
-
if (
|
|
117
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count = 1) {
|
|
118
|
+
if (keyOrNodeOrEntryOrRaw === undefined || keyOrNodeOrEntryOrRaw === null)
|
|
117
119
|
return;
|
|
118
|
-
if (this.isNode(
|
|
119
|
-
return
|
|
120
|
-
if (this.isEntry(
|
|
121
|
-
const [key, entryValue] =
|
|
120
|
+
if (this.isNode(keyOrNodeOrEntryOrRaw))
|
|
121
|
+
return keyOrNodeOrEntryOrRaw;
|
|
122
|
+
if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
|
|
123
|
+
const [key, entryValue] = keyOrNodeOrEntryOrRaw;
|
|
122
124
|
if (key === undefined || key === null)
|
|
123
125
|
return;
|
|
124
126
|
if (this.isKey(key))
|
|
125
127
|
return this.createNode(key, value ?? entryValue, 'BLACK', count);
|
|
126
128
|
}
|
|
127
|
-
if (this.
|
|
128
|
-
const [key, entryValue] = this.
|
|
129
|
+
if (this._toEntryFn) {
|
|
130
|
+
const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw);
|
|
129
131
|
if (this.isKey(key))
|
|
130
132
|
return this.createNode(key, value ?? entryValue, 'BLACK', count);
|
|
131
133
|
}
|
|
132
|
-
if (this.isKey(
|
|
133
|
-
return this.createNode(
|
|
134
|
+
if (this.isKey(keyOrNodeOrEntryOrRaw))
|
|
135
|
+
return this.createNode(keyOrNodeOrEntryOrRaw, value, 'BLACK', count);
|
|
134
136
|
return;
|
|
135
137
|
}
|
|
136
138
|
/**
|
|
137
139
|
* The function checks if the input is an instance of the TreeMultiMapNode class.
|
|
138
|
-
* @param {
|
|
139
|
-
* `
|
|
140
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
140
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
|
|
141
|
+
* `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
142
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
|
|
141
143
|
* an instance of the `TreeMultiMapNode` class.
|
|
142
144
|
*/
|
|
143
|
-
isNode(
|
|
144
|
-
return
|
|
145
|
+
isNode(keyOrNodeOrEntryOrRaw) {
|
|
146
|
+
return keyOrNodeOrEntryOrRaw instanceof TreeMultiMapNode;
|
|
145
147
|
}
|
|
146
148
|
/**
|
|
147
149
|
* Time Complexity: O(log n)
|
|
@@ -149,8 +151,8 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
149
151
|
*
|
|
150
152
|
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
151
153
|
* the count and returning a boolean indicating success.
|
|
152
|
-
* @param {
|
|
153
|
-
* `
|
|
154
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
|
|
155
|
+
* `keyOrNodeOrEntryOrRaw` parameter can accept one of the following types:
|
|
154
156
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
155
157
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
156
158
|
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
@@ -159,8 +161,8 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
159
161
|
* @returns The method is returning a boolean value. It returns true if the addition of the new node
|
|
160
162
|
* was successful, and false otherwise.
|
|
161
163
|
*/
|
|
162
|
-
add(
|
|
163
|
-
const newNode = this.keyValueOrEntryOrRawElementToNode(
|
|
164
|
+
add(keyOrNodeOrEntryOrRaw, value, count = 1) {
|
|
165
|
+
const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count);
|
|
164
166
|
const orgCount = newNode?.count || 0;
|
|
165
167
|
const isSuccessAdded = super.add(newNode);
|
|
166
168
|
if (isSuccessAdded) {
|
|
@@ -175,26 +177,27 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
175
177
|
* Time Complexity: O(log n)
|
|
176
178
|
* Space Complexity: O(1)
|
|
177
179
|
*
|
|
178
|
-
* The function `delete`
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
* the
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* it. If set to false, the count of the node will be decremented by 1 before deleting it.
|
|
190
|
-
* @returns an array of BinaryTreeDeleteResult<NODE> objects.
|
|
180
|
+
* The function `delete` in TypeScript overrides the deletion operation in a binary tree data
|
|
181
|
+
* structure, handling cases where nodes have children and maintaining balance in the tree.
|
|
182
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
|
|
183
|
+
* parameter in the `delete` method is used to specify the condition or key based on which a node
|
|
184
|
+
* should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
|
|
185
|
+
* function.
|
|
186
|
+
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
187
|
+
* boolean flag that determines whether to ignore the count of nodes when performing deletion. If
|
|
188
|
+
* `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
|
|
189
|
+
* `ignoreCount` is `false
|
|
190
|
+
* @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<NODE>` objects.
|
|
191
191
|
*/
|
|
192
|
-
delete(
|
|
193
|
-
if (
|
|
192
|
+
delete(predicate, ignoreCount = false) {
|
|
193
|
+
if (predicate === null)
|
|
194
194
|
return [];
|
|
195
195
|
const results = [];
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
let nodeToDelete;
|
|
197
|
+
if (this._isPredicated(predicate))
|
|
198
|
+
nodeToDelete = this.getNode(predicate);
|
|
199
|
+
else
|
|
200
|
+
nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate);
|
|
198
201
|
if (!nodeToDelete) {
|
|
199
202
|
return results;
|
|
200
203
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* data-structure-typed
|
|
3
3
|
*
|
|
4
|
-
* @author
|
|
5
|
-
* @copyright Copyright (c) 2022
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { DijkstraResult, EntryCallback, VertexKey } from '../../types';
|
|
@@ -459,7 +459,7 @@ export class AbstractGraph extends IterableEntryBase {
|
|
|
459
459
|
}
|
|
460
460
|
}
|
|
461
461
|
}
|
|
462
|
-
getMinDist
|
|
462
|
+
if (getMinDist)
|
|
463
463
|
distMap.forEach((d, v) => {
|
|
464
464
|
if (v !== srcVertex) {
|
|
465
465
|
if (d < minDist) {
|
|
@@ -469,7 +469,8 @@ export class AbstractGraph extends IterableEntryBase {
|
|
|
469
469
|
}
|
|
470
470
|
}
|
|
471
471
|
});
|
|
472
|
-
|
|
472
|
+
if (genPaths)
|
|
473
|
+
getPaths(minDest);
|
|
473
474
|
return { distMap, preMap, seen, paths, minDist, minPath };
|
|
474
475
|
}
|
|
475
476
|
/**
|
|
@@ -641,7 +642,8 @@ export class AbstractGraph extends IterableEntryBase {
|
|
|
641
642
|
if (sWeight !== undefined && dWeight !== undefined) {
|
|
642
643
|
if (distMap.get(s) !== Infinity && sWeight + weight < dWeight) {
|
|
643
644
|
distMap.set(d, sWeight + weight);
|
|
644
|
-
|
|
645
|
+
if (genPath)
|
|
646
|
+
preMap.set(d, s);
|
|
645
647
|
}
|
|
646
648
|
}
|
|
647
649
|
}
|
|
@@ -765,7 +767,8 @@ export class AbstractGraph extends IterableEntryBase {
|
|
|
765
767
|
visited.add(vertex);
|
|
766
768
|
currentPath.push(vertex.key);
|
|
767
769
|
for (const neighbor of this.getNeighbors(vertex)) {
|
|
768
|
-
|
|
770
|
+
if (neighbor)
|
|
771
|
+
dfs(neighbor, currentPath, visited);
|
|
769
772
|
}
|
|
770
773
|
visited.delete(vertex);
|
|
771
774
|
currentPath.pop();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* data-structure-typed
|
|
3
3
|
*
|
|
4
|
-
* @author
|
|
5
|
-
* @copyright Copyright (c) 2022
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { VertexKey } from '../../types';
|
|
@@ -217,8 +217,10 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
217
217
|
if (v1 && v2) {
|
|
218
218
|
const v1ToV2 = this.deleteEdgeSrcToDest(v1, v2);
|
|
219
219
|
const v2ToV1 = this.deleteEdgeSrcToDest(v2, v1);
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
if (v1ToV2)
|
|
221
|
+
removed.push(v1ToV2);
|
|
222
|
+
if (v2ToV1)
|
|
223
|
+
removed.push(v2ToV1);
|
|
222
224
|
}
|
|
223
225
|
return removed;
|
|
224
226
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* data-structure-typed
|
|
3
3
|
*
|
|
4
|
-
* @author
|
|
5
|
-
* @copyright Copyright (c) 2022
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { VertexKey } from '../../types';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* data-structure-typed
|
|
3
3
|
*
|
|
4
|
-
* @author
|
|
5
|
-
* @copyright Copyright (c) 2022
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { EntryCallback, HashMapLinkedNode, HashMapOptions, HashMapStoreItem, LinkedHashMapOptions } from '../../types';
|
|
@@ -86,7 +86,7 @@ export class HashMap extends IterableEntryBase {
|
|
|
86
86
|
* @returns A boolean value indicating whether the size of the object is 0 or not.
|
|
87
87
|
*/
|
|
88
88
|
isEmpty() {
|
|
89
|
-
return this.
|
|
89
|
+
return this._size === 0;
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
92
|
* The clear() function resets the state of an object by clearing its internal store, object map, and
|
|
@@ -577,7 +577,7 @@ export class FibonacciHeap {
|
|
|
577
577
|
* @returns The top element or undefined if the heap is empty.
|
|
578
578
|
*/
|
|
579
579
|
pop() {
|
|
580
|
-
if (this.
|
|
580
|
+
if (this._size === 0)
|
|
581
581
|
return undefined;
|
|
582
582
|
const z = this.min;
|
|
583
583
|
if (z.child) {
|
|
@@ -710,7 +710,7 @@ export class FibonacciHeap {
|
|
|
710
710
|
* @protected
|
|
711
711
|
*/
|
|
712
712
|
_consolidate() {
|
|
713
|
-
const A = new Array(this.
|
|
713
|
+
const A = new Array(this._size);
|
|
714
714
|
const elements = this.consumeLinkedList(this.root);
|
|
715
715
|
let x, y, d, t;
|
|
716
716
|
for (const node of elements) {
|
|
@@ -729,7 +729,7 @@ export class FibonacciHeap {
|
|
|
729
729
|
}
|
|
730
730
|
A[d] = x;
|
|
731
731
|
}
|
|
732
|
-
for (let i = 0; i < this.
|
|
732
|
+
for (let i = 0; i < this._size; i++) {
|
|
733
733
|
if (A[i] && this.comparator(A[i].element, this.min.element) <= 0) {
|
|
734
734
|
this._min = A[i];
|
|
735
735
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* data-structure-typed
|
|
3
3
|
*
|
|
4
|
-
* @author
|
|
5
|
-
* @copyright Copyright (c) 2022
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { DoublyLinkedListOptions, ElementCallback } from '../../types';
|