data-structure-typed 1.53.8 → 1.53.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/CONTRIBUTING.md +1 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.js +4 -4
- 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 +36 -17
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +64 -35
- 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 +12 -8
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +19 -6
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +53 -40
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +75 -71
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +35 -30
- package/dist/cjs/data-structures/binary-tree/bst.js +54 -40
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +43 -22
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js +50 -55
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +33 -17
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +62 -36
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.js +2 -2
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +1 -1
- package/dist/cjs/data-structures/hash/hash-map.js +5 -5
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +10 -10
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +12 -12
- 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 +10 -10
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +16 -16
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +3 -4
- package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -3
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -4
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +4 -5
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -5
- package/dist/mjs/data-structures/base/iterable-entry-base.js +4 -4
- package/dist/mjs/data-structures/base/iterable-entry-base.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +36 -17
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +64 -35
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +12 -8
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +19 -6
- package/dist/mjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +53 -40
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +75 -71
- package/dist/mjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +35 -30
- package/dist/mjs/data-structures/binary-tree/bst.js +70 -56
- package/dist/mjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/red-black-tree.d.ts +43 -22
- package/dist/mjs/data-structures/binary-tree/red-black-tree.js +50 -55
- package/dist/mjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +33 -17
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +62 -36
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/mjs/data-structures/graph/abstract-graph.js +2 -2
- package/dist/mjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/mjs/data-structures/hash/hash-map.d.ts +1 -1
- package/dist/mjs/data-structures/hash/hash-map.js +5 -5
- package/dist/mjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +10 -10
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +12 -12
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +10 -10
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +16 -16
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/mjs/interfaces/binary-tree.d.ts +3 -4
- package/dist/mjs/types/data-structures/base/base.d.ts +1 -1
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -3
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +3 -4
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +4 -5
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -5
- package/dist/umd/data-structure-typed.js +337 -253
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +6 -6
- package/src/data-structures/base/iterable-entry-base.ts +4 -4
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +81 -54
- package/src/data-structures/binary-tree/avl-tree.ts +32 -15
- package/src/data-structures/binary-tree/binary-tree.ts +88 -83
- package/src/data-structures/binary-tree/bst.ts +87 -74
- package/src/data-structures/binary-tree/red-black-tree.ts +55 -54
- package/src/data-structures/binary-tree/tree-multi-map.ts +79 -49
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/hash/hash-map.ts +7 -7
- package/src/data-structures/linked-list/doubly-linked-list.ts +13 -13
- package/src/data-structures/linked-list/singly-linked-list.ts +17 -17
- package/src/interfaces/binary-tree.ts +3 -13
- package/src/types/data-structures/base/base.ts +1 -1
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -4
- package/src/types/data-structures/binary-tree/avl-tree.ts +2 -4
- package/src/types/data-structures/binary-tree/binary-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/bst.ts +3 -5
- package/src/types/data-structures/binary-tree/rb-tree.ts +4 -6
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +4 -6
- package/test/integration/index.html +3 -3
- package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +12 -12
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +10 -10
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +10 -10
- package/test/unit/data-structures/binary-tree/bst.test.ts +11 -11
- package/test/unit/data-structures/binary-tree/data/cost-of-living-by-country.ts +259 -0
- package/test/unit/data-structures/binary-tree/overall.test.ts +2 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +30 -10
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +10 -10
- package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
- package/test/unit/data-structures/hash/hash-map.test.ts +12 -12
|
@@ -231,7 +231,7 @@ var dataStructureTyped = (() => {
|
|
|
231
231
|
every(predicate, thisArg) {
|
|
232
232
|
let index = 0;
|
|
233
233
|
for (const item of this) {
|
|
234
|
-
if (!predicate.call(thisArg, item[
|
|
234
|
+
if (!predicate.call(thisArg, item[0], item[1], index++, this)) {
|
|
235
235
|
return false;
|
|
236
236
|
}
|
|
237
237
|
}
|
|
@@ -255,7 +255,7 @@ var dataStructureTyped = (() => {
|
|
|
255
255
|
some(predicate, thisArg) {
|
|
256
256
|
let index = 0;
|
|
257
257
|
for (const item of this) {
|
|
258
|
-
if (predicate.call(thisArg, item[
|
|
258
|
+
if (predicate.call(thisArg, item[0], item[1], index++, this)) {
|
|
259
259
|
return true;
|
|
260
260
|
}
|
|
261
261
|
}
|
|
@@ -278,7 +278,7 @@ var dataStructureTyped = (() => {
|
|
|
278
278
|
let index = 0;
|
|
279
279
|
for (const item of this) {
|
|
280
280
|
const [key, value] = item;
|
|
281
|
-
callbackfn.call(thisArg,
|
|
281
|
+
callbackfn.call(thisArg, key, value, index++, this);
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
284
|
/**
|
|
@@ -302,7 +302,7 @@ var dataStructureTyped = (() => {
|
|
|
302
302
|
let index = 0;
|
|
303
303
|
for (const item of this) {
|
|
304
304
|
const [key, value] = item;
|
|
305
|
-
if (callbackfn.call(thisArg,
|
|
305
|
+
if (callbackfn.call(thisArg, key, value, index++, this)) return item;
|
|
306
306
|
}
|
|
307
307
|
return;
|
|
308
308
|
}
|
|
@@ -951,7 +951,7 @@ var dataStructureTyped = (() => {
|
|
|
951
951
|
const resultMap = new _HashMap();
|
|
952
952
|
let index = 0;
|
|
953
953
|
for (const [key, value] of this) {
|
|
954
|
-
resultMap.set(key, callbackfn.call(thisArg,
|
|
954
|
+
resultMap.set(key, callbackfn.call(thisArg, key, value, index++, this));
|
|
955
955
|
}
|
|
956
956
|
return resultMap;
|
|
957
957
|
}
|
|
@@ -975,7 +975,7 @@ var dataStructureTyped = (() => {
|
|
|
975
975
|
const filteredMap = new _HashMap();
|
|
976
976
|
let index = 0;
|
|
977
977
|
for (const [key, value] of this) {
|
|
978
|
-
if (predicate.call(thisArg,
|
|
978
|
+
if (predicate.call(thisArg, key, value, index++, this)) {
|
|
979
979
|
filteredMap.set(key, value);
|
|
980
980
|
}
|
|
981
981
|
}
|
|
@@ -1420,7 +1420,7 @@ var dataStructureTyped = (() => {
|
|
|
1420
1420
|
const filteredMap = new _LinkedHashMap();
|
|
1421
1421
|
let index = 0;
|
|
1422
1422
|
for (const [key, value] of this) {
|
|
1423
|
-
if (predicate.call(thisArg,
|
|
1423
|
+
if (predicate.call(thisArg, key, value, index, this)) {
|
|
1424
1424
|
filteredMap.set(key, value);
|
|
1425
1425
|
}
|
|
1426
1426
|
index++;
|
|
@@ -1448,8 +1448,8 @@ var dataStructureTyped = (() => {
|
|
|
1448
1448
|
const mappedMap = new _LinkedHashMap();
|
|
1449
1449
|
let index = 0;
|
|
1450
1450
|
for (const [key, value] of this) {
|
|
1451
|
-
const newValue = callback.call(thisArg,
|
|
1452
|
-
mappedMap.set(
|
|
1451
|
+
const [newKey, newValue] = callback.call(thisArg, key, value, index, this);
|
|
1452
|
+
mappedMap.set(newKey, newValue);
|
|
1453
1453
|
index++;
|
|
1454
1454
|
}
|
|
1455
1455
|
return mappedMap;
|
|
@@ -1585,6 +1585,22 @@ var dataStructureTyped = (() => {
|
|
|
1585
1585
|
get size() {
|
|
1586
1586
|
return this._size;
|
|
1587
1587
|
}
|
|
1588
|
+
/**
|
|
1589
|
+
* Time Complexity: O(n)
|
|
1590
|
+
* Space Complexity: O(n)
|
|
1591
|
+
*
|
|
1592
|
+
* The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
|
|
1593
|
+
* array.
|
|
1594
|
+
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
1595
|
+
* @returns The `fromArray` function returns a `SinglyLinkedList` object.
|
|
1596
|
+
*/
|
|
1597
|
+
static fromArray(data) {
|
|
1598
|
+
const singlyLinkedList = new _SinglyLinkedList();
|
|
1599
|
+
for (const item of data) {
|
|
1600
|
+
singlyLinkedList.push(item);
|
|
1601
|
+
}
|
|
1602
|
+
return singlyLinkedList;
|
|
1603
|
+
}
|
|
1588
1604
|
/**
|
|
1589
1605
|
* Time Complexity: O(1)
|
|
1590
1606
|
* Space Complexity: O(1)
|
|
@@ -2170,22 +2186,6 @@ var dataStructureTyped = (() => {
|
|
|
2170
2186
|
current = current.next;
|
|
2171
2187
|
}
|
|
2172
2188
|
}
|
|
2173
|
-
/**
|
|
2174
|
-
* Time Complexity: O(n)
|
|
2175
|
-
* Space Complexity: O(n)
|
|
2176
|
-
*
|
|
2177
|
-
* The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
|
|
2178
|
-
* array.
|
|
2179
|
-
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
2180
|
-
* @returns The `fromArray` function returns a `SinglyLinkedList` object.
|
|
2181
|
-
*/
|
|
2182
|
-
static fromArray(data) {
|
|
2183
|
-
const singlyLinkedList = new _SinglyLinkedList();
|
|
2184
|
-
for (const item of data) {
|
|
2185
|
-
singlyLinkedList.push(item);
|
|
2186
|
-
}
|
|
2187
|
-
return singlyLinkedList;
|
|
2188
|
-
}
|
|
2189
2189
|
/**
|
|
2190
2190
|
* The _isPredicate function in TypeScript checks if the input is a function that takes a
|
|
2191
2191
|
* SinglyLinkedListNode as an argument and returns a boolean.
|
|
@@ -2356,6 +2356,18 @@ var dataStructureTyped = (() => {
|
|
|
2356
2356
|
var _a;
|
|
2357
2357
|
return (_a = this.tail) == null ? void 0 : _a.value;
|
|
2358
2358
|
}
|
|
2359
|
+
/**
|
|
2360
|
+
* Time Complexity: O(n)
|
|
2361
|
+
* Space Complexity: O(n)
|
|
2362
|
+
*
|
|
2363
|
+
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
2364
|
+
* given array.
|
|
2365
|
+
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
2366
|
+
* @returns The `fromArray` function returns a DoublyLinkedList object.
|
|
2367
|
+
*/
|
|
2368
|
+
static fromArray(data) {
|
|
2369
|
+
return new _DoublyLinkedList(data);
|
|
2370
|
+
}
|
|
2359
2371
|
/**
|
|
2360
2372
|
* Time Complexity: O(1)
|
|
2361
2373
|
* Space Complexity: O(1)
|
|
@@ -2962,18 +2974,6 @@ var dataStructureTyped = (() => {
|
|
|
2962
2974
|
}
|
|
2963
2975
|
return count;
|
|
2964
2976
|
}
|
|
2965
|
-
/**
|
|
2966
|
-
* Time Complexity: O(n)
|
|
2967
|
-
* Space Complexity: O(n)
|
|
2968
|
-
*
|
|
2969
|
-
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
2970
|
-
* given array.
|
|
2971
|
-
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
2972
|
-
* @returns The `fromArray` function returns a DoublyLinkedList object.
|
|
2973
|
-
*/
|
|
2974
|
-
static fromArray(data) {
|
|
2975
|
-
return new _DoublyLinkedList(data);
|
|
2976
|
-
}
|
|
2977
2977
|
/**
|
|
2978
2978
|
* The function returns an iterator that iterates over the values of a linked list.
|
|
2979
2979
|
*/
|
|
@@ -6192,7 +6192,7 @@ var dataStructureTyped = (() => {
|
|
|
6192
6192
|
const filtered = [];
|
|
6193
6193
|
let index = 0;
|
|
6194
6194
|
for (const [key, value] of this) {
|
|
6195
|
-
if (predicate.call(thisArg,
|
|
6195
|
+
if (predicate.call(thisArg, key, value, index, this)) {
|
|
6196
6196
|
filtered.push([key, value]);
|
|
6197
6197
|
}
|
|
6198
6198
|
index++;
|
|
@@ -6216,7 +6216,7 @@ var dataStructureTyped = (() => {
|
|
|
6216
6216
|
const mapped = [];
|
|
6217
6217
|
let index = 0;
|
|
6218
6218
|
for (const [key, value] of this) {
|
|
6219
|
-
mapped.push(callback.call(thisArg,
|
|
6219
|
+
mapped.push(callback.call(thisArg, key, value, index, this));
|
|
6220
6220
|
index++;
|
|
6221
6221
|
}
|
|
6222
6222
|
return mapped;
|
|
@@ -7471,6 +7471,9 @@ var dataStructureTyped = (() => {
|
|
|
7471
7471
|
return this._toEntryFn;
|
|
7472
7472
|
}
|
|
7473
7473
|
/**
|
|
7474
|
+
* Time Complexity: O(1)
|
|
7475
|
+
* Space Complexity: O(1)
|
|
7476
|
+
*
|
|
7474
7477
|
* The function creates a new binary tree node with a specified key and optional value.
|
|
7475
7478
|
* @param {K} key - The `key` parameter is the key of the node being created in the binary tree.
|
|
7476
7479
|
* @param {V} [value] - The `value` parameter in the `createNode` function is optional, meaning it is
|
|
@@ -7483,12 +7486,18 @@ var dataStructureTyped = (() => {
|
|
|
7483
7486
|
return new BinaryTreeNode(key, this._isMapMode ? void 0 : value);
|
|
7484
7487
|
}
|
|
7485
7488
|
/**
|
|
7486
|
-
*
|
|
7487
|
-
*
|
|
7488
|
-
*
|
|
7489
|
-
* `
|
|
7490
|
-
* of
|
|
7491
|
-
*
|
|
7489
|
+
* Time Complexity: O(1)
|
|
7490
|
+
* Space Complexity: O(1)
|
|
7491
|
+
*
|
|
7492
|
+
* The `createTree` function creates a new binary tree based on the provided options.
|
|
7493
|
+
* @param [options] - The `options` parameter in the `createTree` method is of type
|
|
7494
|
+
* `BinaryTreeOptions<K, V, R>`. This type likely contains configuration options for creating a
|
|
7495
|
+
* binary tree, such as the iteration type, whether the tree is in map mode, and functions for
|
|
7496
|
+
* converting entries.
|
|
7497
|
+
* @returns The `createTree` method is returning an instance of the `BinaryTree` class with the
|
|
7498
|
+
* provided options. The method is creating a new `BinaryTree` object with an empty array as the
|
|
7499
|
+
* initial data, and then setting various options such as `iterationType`, `isMapMode`, and
|
|
7500
|
+
* `toEntryFn` based on the current object's properties and the provided `options`. Finally, it
|
|
7492
7501
|
*/
|
|
7493
7502
|
createTree(options) {
|
|
7494
7503
|
return new _BinaryTree([], __spreadValues({
|
|
@@ -7497,40 +7506,6 @@ var dataStructureTyped = (() => {
|
|
|
7497
7506
|
toEntryFn: this._toEntryFn
|
|
7498
7507
|
}, options));
|
|
7499
7508
|
}
|
|
7500
|
-
/**
|
|
7501
|
-
* The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
|
|
7502
|
-
* or returns null.
|
|
7503
|
-
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
|
|
7504
|
-
* `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeEntryOrRaw`, which
|
|
7505
|
-
* can be of type `BTNRep<K, V, NODE>` or `R`. This parameter represents either a key, a
|
|
7506
|
-
* node, an entry
|
|
7507
|
-
* @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
|
|
7508
|
-
* an optional parameter of type `V`. It represents the value associated with the key in the node
|
|
7509
|
-
* being created. If a `value` is provided, it will be used when creating the node. If
|
|
7510
|
-
* @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
|
|
7511
|
-
* (`OptNodeOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
|
|
7512
|
-
* input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
|
|
7513
|
-
* value.
|
|
7514
|
-
*/
|
|
7515
|
-
_keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
|
|
7516
|
-
if (keyNodeEntryOrRaw === void 0) return [void 0, void 0];
|
|
7517
|
-
if (keyNodeEntryOrRaw === null) return [null, void 0];
|
|
7518
|
-
if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
|
|
7519
|
-
if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
7520
|
-
const [key, entryValue] = keyNodeEntryOrRaw;
|
|
7521
|
-
if (key === void 0) return [void 0, void 0];
|
|
7522
|
-
else if (key === null) return [null, void 0];
|
|
7523
|
-
const finalValue = value != null ? value : entryValue;
|
|
7524
|
-
return [this.createNode(key, finalValue), finalValue];
|
|
7525
|
-
}
|
|
7526
|
-
if (this.isRaw(keyNodeEntryOrRaw)) {
|
|
7527
|
-
const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
7528
|
-
const finalValue = value != null ? value : entryValue;
|
|
7529
|
-
if (this.isKey(key)) return [this.createNode(key, finalValue), finalValue];
|
|
7530
|
-
}
|
|
7531
|
-
if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value), value];
|
|
7532
|
-
return [void 0, void 0];
|
|
7533
|
-
}
|
|
7534
7509
|
/**
|
|
7535
7510
|
* Time Complexity: O(n)
|
|
7536
7511
|
* Space Complexity: O(log n)
|
|
@@ -8733,7 +8708,7 @@ var dataStructureTyped = (() => {
|
|
|
8733
8708
|
const newTree = this.createTree();
|
|
8734
8709
|
let index = 0;
|
|
8735
8710
|
for (const [key, value] of this) {
|
|
8736
|
-
if (predicate.call(thisArg,
|
|
8711
|
+
if (predicate.call(thisArg, key, value, index++, this)) {
|
|
8737
8712
|
newTree.add([key, value]);
|
|
8738
8713
|
}
|
|
8739
8714
|
}
|
|
@@ -8743,34 +8718,29 @@ var dataStructureTyped = (() => {
|
|
|
8743
8718
|
* Time Complexity: O(n)
|
|
8744
8719
|
* Space Complexity: O(n)
|
|
8745
8720
|
*
|
|
8746
|
-
* The `map` function
|
|
8747
|
-
*
|
|
8748
|
-
* @param callback -
|
|
8749
|
-
*
|
|
8750
|
-
*
|
|
8751
|
-
*
|
|
8752
|
-
*
|
|
8753
|
-
*
|
|
8754
|
-
*
|
|
8755
|
-
*
|
|
8756
|
-
|
|
8757
|
-
|
|
8758
|
-
|
|
8721
|
+
* The `map` function in TypeScript creates a new BinaryTree by applying a callback function to each
|
|
8722
|
+
* entry in the original BinaryTree.
|
|
8723
|
+
* @param callback - A function that will be called for each entry in the current binary tree. It
|
|
8724
|
+
* takes the key, value (which can be undefined), and an array containing the mapped key and value as
|
|
8725
|
+
* arguments.
|
|
8726
|
+
* @param [options] - The `options` parameter in the `map` method is of type `BinaryTreeOptions<MK,
|
|
8727
|
+
* MV, MR>`. It is an optional parameter that allows you to specify additional options for the binary
|
|
8728
|
+
* tree being created during the mapping process. These options could include things like custom
|
|
8729
|
+
* comparators, initial
|
|
8730
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `map` method is used to specify the value
|
|
8731
|
+
* of `this` when executing the `callback` function. It allows you to set the context (value of
|
|
8732
|
+
* `this`) within the callback function. If `thisArg` is provided, it will be passed
|
|
8733
|
+
* @returns The `map` function is returning a new `BinaryTree` instance filled with entries that are
|
|
8734
|
+
* the result of applying the provided `callback` function to each entry in the original tree.
|
|
8735
|
+
*/
|
|
8736
|
+
map(callback, options, thisArg) {
|
|
8737
|
+
const newTree = new _BinaryTree([], options);
|
|
8759
8738
|
let index = 0;
|
|
8760
8739
|
for (const [key, value] of this) {
|
|
8761
|
-
newTree.add(
|
|
8740
|
+
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
8762
8741
|
}
|
|
8763
8742
|
return newTree;
|
|
8764
8743
|
}
|
|
8765
|
-
// // TODO Type error, need to return a TREE<NV> that is a value type only for callback function.
|
|
8766
|
-
// // map<NV>(callback: (entry: [K, V | undefined], tree: this) => NV) {
|
|
8767
|
-
// // const newTree = this.createTree();
|
|
8768
|
-
// // for (const [key, value] of this) {
|
|
8769
|
-
// // newTree.add(key, callback([key, value], this));
|
|
8770
|
-
// // }
|
|
8771
|
-
// // return newTree;
|
|
8772
|
-
// // }
|
|
8773
|
-
//
|
|
8774
8744
|
/**
|
|
8775
8745
|
* Time Complexity: O(n)
|
|
8776
8746
|
* Space Complexity: O(n)
|
|
@@ -8801,7 +8771,7 @@ var dataStructureTyped = (() => {
|
|
|
8801
8771
|
if (opts.isShowRedBlackNIL) output += `S for Sentinel Node(NIL)
|
|
8802
8772
|
`;
|
|
8803
8773
|
const display = (root) => {
|
|
8804
|
-
const [lines, ,
|
|
8774
|
+
const [lines, ,] = this._displayAux(root, opts);
|
|
8805
8775
|
let paragraph = "";
|
|
8806
8776
|
for (const line of lines) {
|
|
8807
8777
|
paragraph += line + "\n";
|
|
@@ -8829,6 +8799,40 @@ var dataStructureTyped = (() => {
|
|
|
8829
8799
|
print(options, startNode = this._root) {
|
|
8830
8800
|
console.log(this.toVisual(startNode, options));
|
|
8831
8801
|
}
|
|
8802
|
+
/**
|
|
8803
|
+
* The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
|
|
8804
|
+
* or returns null.
|
|
8805
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
|
|
8806
|
+
* `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeEntryOrRaw`, which
|
|
8807
|
+
* can be of type `BTNRep<K, V, NODE>` or `R`. This parameter represents either a key, a
|
|
8808
|
+
* node, an entry
|
|
8809
|
+
* @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
|
|
8810
|
+
* an optional parameter of type `V`. It represents the value associated with the key in the node
|
|
8811
|
+
* being created. If a `value` is provided, it will be used when creating the node. If
|
|
8812
|
+
* @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
|
|
8813
|
+
* (`OptNodeOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
|
|
8814
|
+
* input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
|
|
8815
|
+
* value.
|
|
8816
|
+
*/
|
|
8817
|
+
_keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
|
|
8818
|
+
if (keyNodeEntryOrRaw === void 0) return [void 0, void 0];
|
|
8819
|
+
if (keyNodeEntryOrRaw === null) return [null, void 0];
|
|
8820
|
+
if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
|
|
8821
|
+
if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
8822
|
+
const [key, entryValue] = keyNodeEntryOrRaw;
|
|
8823
|
+
if (key === void 0) return [void 0, void 0];
|
|
8824
|
+
else if (key === null) return [null, void 0];
|
|
8825
|
+
const finalValue = value != null ? value : entryValue;
|
|
8826
|
+
return [this.createNode(key, finalValue), finalValue];
|
|
8827
|
+
}
|
|
8828
|
+
if (this.isRaw(keyNodeEntryOrRaw)) {
|
|
8829
|
+
const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
8830
|
+
const finalValue = value != null ? value : entryValue;
|
|
8831
|
+
if (this.isKey(key)) return [this.createNode(key, finalValue), finalValue];
|
|
8832
|
+
}
|
|
8833
|
+
if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value), value];
|
|
8834
|
+
return [void 0, void 0];
|
|
8835
|
+
}
|
|
8832
8836
|
/**
|
|
8833
8837
|
* Time complexity: O(n)
|
|
8834
8838
|
* Space complexity: O(n)
|
|
@@ -9301,22 +9305,22 @@ var dataStructureTyped = (() => {
|
|
|
9301
9305
|
if (a < b) return -1;
|
|
9302
9306
|
return 0;
|
|
9303
9307
|
}
|
|
9304
|
-
if (this.
|
|
9305
|
-
if (this.
|
|
9306
|
-
if (this.
|
|
9308
|
+
if (this._specifyComparable) {
|
|
9309
|
+
if (this._specifyComparable(a) > this._specifyComparable(b)) return 1;
|
|
9310
|
+
if (this._specifyComparable(a) < this._specifyComparable(b)) return -1;
|
|
9307
9311
|
return 0;
|
|
9308
9312
|
}
|
|
9309
9313
|
if (typeof a === "object" || typeof b === "object") {
|
|
9310
9314
|
throw TypeError(
|
|
9311
|
-
`When comparing object types, a custom
|
|
9315
|
+
`When comparing object types, a custom specifyComparable must be defined in the constructor's options parameter.`
|
|
9312
9316
|
);
|
|
9313
9317
|
}
|
|
9314
9318
|
return 0;
|
|
9315
9319
|
});
|
|
9316
|
-
__publicField(this, "
|
|
9320
|
+
__publicField(this, "_specifyComparable");
|
|
9317
9321
|
if (options) {
|
|
9318
|
-
const {
|
|
9319
|
-
if (typeof
|
|
9322
|
+
const { specifyComparable, isReverse } = options;
|
|
9323
|
+
if (typeof specifyComparable === "function") this._specifyComparable = specifyComparable;
|
|
9320
9324
|
if (isReverse !== void 0) this._isReverse = isReverse;
|
|
9321
9325
|
}
|
|
9322
9326
|
if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
|
|
@@ -9336,6 +9340,21 @@ var dataStructureTyped = (() => {
|
|
|
9336
9340
|
get isReverse() {
|
|
9337
9341
|
return this._isReverse;
|
|
9338
9342
|
}
|
|
9343
|
+
/**
|
|
9344
|
+
* The function returns the value of the _comparator property.
|
|
9345
|
+
* @returns The `_comparator` property is being returned.
|
|
9346
|
+
*/
|
|
9347
|
+
get comparator() {
|
|
9348
|
+
return this._comparator;
|
|
9349
|
+
}
|
|
9350
|
+
/**
|
|
9351
|
+
* This function returns the value of the `_specifyComparable` property.
|
|
9352
|
+
* @returns The method `specifyComparable()` is being returned, which is a getter method for the
|
|
9353
|
+
* `_specifyComparable` property.
|
|
9354
|
+
*/
|
|
9355
|
+
get specifyComparable() {
|
|
9356
|
+
return this._specifyComparable;
|
|
9357
|
+
}
|
|
9339
9358
|
/**
|
|
9340
9359
|
* The function creates a new BSTNode with the given key and value and returns it.
|
|
9341
9360
|
* @param {K} key - The key parameter is of type K, which represents the type of the key for the node
|
|
@@ -9348,35 +9367,26 @@ var dataStructureTyped = (() => {
|
|
|
9348
9367
|
return new BSTNode(key, this._isMapMode ? void 0 : value);
|
|
9349
9368
|
}
|
|
9350
9369
|
/**
|
|
9351
|
-
*
|
|
9352
|
-
*
|
|
9353
|
-
*
|
|
9354
|
-
*
|
|
9355
|
-
*
|
|
9370
|
+
* Time Complexity: O(1)
|
|
9371
|
+
* Space Complexity: O(1)
|
|
9372
|
+
*
|
|
9373
|
+
* The `createTree` function in TypeScript overrides the default options with the provided options to
|
|
9374
|
+
* create a new Binary Search Tree.
|
|
9375
|
+
* @param [options] - The `options` parameter in the `createTree` method is an optional object that
|
|
9376
|
+
* can contain the following properties:
|
|
9377
|
+
* @returns A new instance of a Binary Search Tree (BST) is being returned with the specified options
|
|
9378
|
+
* and properties inherited from the current instance.
|
|
9356
9379
|
*/
|
|
9380
|
+
// @ts-ignore
|
|
9357
9381
|
createTree(options) {
|
|
9358
9382
|
return new _BST([], __spreadValues({
|
|
9359
9383
|
iterationType: this.iterationType,
|
|
9360
9384
|
isMapMode: this._isMapMode,
|
|
9361
|
-
|
|
9385
|
+
specifyComparable: this._specifyComparable,
|
|
9362
9386
|
toEntryFn: this._toEntryFn,
|
|
9363
9387
|
isReverse: this._isReverse
|
|
9364
9388
|
}, options));
|
|
9365
9389
|
}
|
|
9366
|
-
/**
|
|
9367
|
-
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
9368
|
-
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - A variable that can be of
|
|
9369
|
-
* type R or BTNRep<K, V, NODE>. It represents either a key, a node, an entry, or a raw
|
|
9370
|
-
* element.
|
|
9371
|
-
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
9372
|
-
* value associated with a key in a key-value pair.
|
|
9373
|
-
* @returns either a NODE object or undefined.
|
|
9374
|
-
*/
|
|
9375
|
-
_keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
|
|
9376
|
-
const [node, entryValue] = super._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
|
|
9377
|
-
if (node === null) return [void 0, void 0];
|
|
9378
|
-
return [node, value != null ? value : entryValue];
|
|
9379
|
-
}
|
|
9380
9390
|
/**
|
|
9381
9391
|
* Time Complexity: O(log n)
|
|
9382
9392
|
* Space Complexity: O(log n)
|
|
@@ -9415,7 +9425,7 @@ var dataStructureTyped = (() => {
|
|
|
9415
9425
|
* this._DEFAULT_COMPARATOR`.
|
|
9416
9426
|
*/
|
|
9417
9427
|
isKey(key) {
|
|
9418
|
-
return isComparable(key, this.
|
|
9428
|
+
return isComparable(key, this._specifyComparable !== void 0);
|
|
9419
9429
|
}
|
|
9420
9430
|
/**
|
|
9421
9431
|
* Time Complexity: O(log n)
|
|
@@ -9934,20 +9944,28 @@ var dataStructureTyped = (() => {
|
|
|
9934
9944
|
}
|
|
9935
9945
|
return balanced;
|
|
9936
9946
|
}
|
|
9937
|
-
|
|
9938
|
-
|
|
9939
|
-
|
|
9940
|
-
|
|
9941
|
-
|
|
9942
|
-
|
|
9947
|
+
// @ts-ignore
|
|
9948
|
+
map(callback, options, thisArg) {
|
|
9949
|
+
const newTree = new _BST([], options);
|
|
9950
|
+
let index = 0;
|
|
9951
|
+
for (const [key, value] of this) {
|
|
9952
|
+
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
9953
|
+
}
|
|
9954
|
+
return newTree;
|
|
9943
9955
|
}
|
|
9944
9956
|
/**
|
|
9945
|
-
*
|
|
9946
|
-
* @
|
|
9947
|
-
*
|
|
9957
|
+
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
9958
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - A variable that can be of
|
|
9959
|
+
* type R or BTNRep<K, V, NODE>. It represents either a key, a node, an entry, or a raw
|
|
9960
|
+
* element.
|
|
9961
|
+
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
9962
|
+
* value associated with a key in a key-value pair.
|
|
9963
|
+
* @returns either a NODE object or undefined.
|
|
9948
9964
|
*/
|
|
9949
|
-
|
|
9950
|
-
|
|
9965
|
+
_keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
|
|
9966
|
+
const [node, entryValue] = super._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
|
|
9967
|
+
if (node === null) return [void 0, void 0];
|
|
9968
|
+
return [node, value != null ? value : entryValue];
|
|
9951
9969
|
}
|
|
9952
9970
|
/**
|
|
9953
9971
|
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
@@ -10588,17 +10606,21 @@ var dataStructureTyped = (() => {
|
|
|
10588
10606
|
return new AVLTreeNode(key, this._isMapMode ? void 0 : value);
|
|
10589
10607
|
}
|
|
10590
10608
|
/**
|
|
10591
|
-
* The function
|
|
10592
|
-
*
|
|
10593
|
-
*
|
|
10594
|
-
*
|
|
10595
|
-
*
|
|
10596
|
-
|
|
10609
|
+
* The function `createTree` in TypeScript overrides the default AVLTree creation with the provided
|
|
10610
|
+
* options.
|
|
10611
|
+
* @param [options] - The `options` parameter in the `createTree` function is an object that contains
|
|
10612
|
+
* configuration options for creating an AVL tree. These options can include properties such as
|
|
10613
|
+
* `iterationType`, `isMapMode`, `specifyComparable`, `toEntryFn`, and `isReverse`. The function
|
|
10614
|
+
* creates a
|
|
10615
|
+
* @returns An AVLTree object is being returned with the specified options and properties inherited
|
|
10616
|
+
* from the current object.
|
|
10617
|
+
*/
|
|
10618
|
+
// @ts-ignore
|
|
10597
10619
|
createTree(options) {
|
|
10598
10620
|
return new _AVLTree([], __spreadValues({
|
|
10599
10621
|
iterationType: this.iterationType,
|
|
10600
10622
|
isMapMode: this._isMapMode,
|
|
10601
|
-
|
|
10623
|
+
specifyComparable: this._specifyComparable,
|
|
10602
10624
|
toEntryFn: this._toEntryFn,
|
|
10603
10625
|
isReverse: this._isReverse
|
|
10604
10626
|
}, options));
|
|
@@ -10654,6 +10676,15 @@ var dataStructureTyped = (() => {
|
|
|
10654
10676
|
}
|
|
10655
10677
|
return deletedResults;
|
|
10656
10678
|
}
|
|
10679
|
+
// @ts-ignore
|
|
10680
|
+
map(callback, options, thisArg) {
|
|
10681
|
+
const newTree = new _AVLTree([], options);
|
|
10682
|
+
let index = 0;
|
|
10683
|
+
for (const [key, value] of this) {
|
|
10684
|
+
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
10685
|
+
}
|
|
10686
|
+
return newTree;
|
|
10687
|
+
}
|
|
10657
10688
|
/**
|
|
10658
10689
|
* Time Complexity: O(1)
|
|
10659
10690
|
* Space Complexity: O(1)
|
|
@@ -10970,9 +11001,9 @@ var dataStructureTyped = (() => {
|
|
|
10970
11001
|
* This is the constructor function for a Red-Black Tree data structure in TypeScript.
|
|
10971
11002
|
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
|
|
10972
11003
|
* iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
|
|
10973
|
-
* initialize the
|
|
11004
|
+
* initialize the RedBlackTree with the provided elements.
|
|
10974
11005
|
* @param [options] - The `options` parameter is an optional object that can be passed to the
|
|
10975
|
-
* constructor. It is of type `
|
|
11006
|
+
* constructor. It is of type `RedBlackTreeOptions<K, V, R>`. This object can contain various options for
|
|
10976
11007
|
* configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
|
|
10977
11008
|
* depend on the implementation
|
|
10978
11009
|
*/
|
|
@@ -11009,16 +11040,20 @@ var dataStructureTyped = (() => {
|
|
|
11009
11040
|
return new RedBlackTreeNode(key, this._isMapMode ? void 0 : value, color);
|
|
11010
11041
|
}
|
|
11011
11042
|
/**
|
|
11012
|
-
* The function
|
|
11013
|
-
*
|
|
11014
|
-
*
|
|
11015
|
-
*
|
|
11043
|
+
* The function `createTree` overrides the default implementation to create a Red-Black Tree with
|
|
11044
|
+
* specified options in TypeScript.
|
|
11045
|
+
* @param [options] - The `options` parameter in the `createTree` method is of type `RedBlackTreeOptions<K,
|
|
11046
|
+
* V, R>`, which is a generic type with three type parameters `K`, `V`, and `R`. This parameter
|
|
11047
|
+
* allows you to pass additional configuration options when creating a new Red-
|
|
11048
|
+
* @returns A new instance of a RedBlackTree with the specified options and properties from the
|
|
11049
|
+
* current object is being returned.
|
|
11016
11050
|
*/
|
|
11051
|
+
// @ts-ignore
|
|
11017
11052
|
createTree(options) {
|
|
11018
11053
|
return new _RedBlackTree([], __spreadValues({
|
|
11019
11054
|
iterationType: this.iterationType,
|
|
11020
11055
|
isMapMode: this._isMapMode,
|
|
11021
|
-
|
|
11056
|
+
specifyComparable: this._specifyComparable,
|
|
11022
11057
|
toEntryFn: this._toEntryFn
|
|
11023
11058
|
}, options));
|
|
11024
11059
|
}
|
|
@@ -11035,41 +11070,6 @@ var dataStructureTyped = (() => {
|
|
|
11035
11070
|
isNode(keyNodeEntryOrRaw) {
|
|
11036
11071
|
return keyNodeEntryOrRaw instanceof RedBlackTreeNode;
|
|
11037
11072
|
}
|
|
11038
|
-
// /**
|
|
11039
|
-
// * Time Complexity: O(1)
|
|
11040
|
-
// * Space Complexity: O(1)
|
|
11041
|
-
// */
|
|
11042
|
-
//
|
|
11043
|
-
// /**
|
|
11044
|
-
// * Time Complexity: O(1)
|
|
11045
|
-
// * Space Complexity: O(1)
|
|
11046
|
-
// *
|
|
11047
|
-
// * The function `keyValueNodeEntryRawToNodeAndValue` takes a key, value, or entry and returns a node if it is
|
|
11048
|
-
// * valid, otherwise it returns undefined.
|
|
11049
|
-
// * @param {BTNRep<K, V, NODE>} keyNodeEntryOrRaw - The key, value, or entry to convert.
|
|
11050
|
-
// * @param {V} [value] - The value associated with the key (if `keyNodeEntryOrRaw` is a key).
|
|
11051
|
-
// * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
|
|
11052
|
-
// */
|
|
11053
|
-
// override keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V): NODE | undefined {
|
|
11054
|
-
//
|
|
11055
|
-
// if (keyNodeEntryOrRaw === null || keyNodeEntryOrRaw === undefined) return;
|
|
11056
|
-
// if (this.isNode(keyNodeEntryOrRaw)) return keyNodeEntryOrRaw;
|
|
11057
|
-
//
|
|
11058
|
-
// if (this._toEntryFn) {
|
|
11059
|
-
// const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw as R);
|
|
11060
|
-
// if (this.isKey(key)) return this.createNode(key, value ?? entryValue, 'RED');
|
|
11061
|
-
// }
|
|
11062
|
-
//
|
|
11063
|
-
// if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
11064
|
-
// const [key, value] = keyNodeEntryOrRaw;
|
|
11065
|
-
// if (key === undefined || key === null) return;
|
|
11066
|
-
// else return this.createNode(key, value, 'RED');
|
|
11067
|
-
// }
|
|
11068
|
-
//
|
|
11069
|
-
// if (this.isKey(keyNodeEntryOrRaw)) return this.createNode(keyNodeEntryOrRaw, value, 'RED');
|
|
11070
|
-
//
|
|
11071
|
-
// return ;
|
|
11072
|
-
// }
|
|
11073
11073
|
/**
|
|
11074
11074
|
* Time Complexity: O(1)
|
|
11075
11075
|
* Space Complexity: O(1)
|
|
@@ -11179,6 +11179,35 @@ var dataStructureTyped = (() => {
|
|
|
11179
11179
|
results.push({ deleted: nodeToDelete, needBalanced: void 0 });
|
|
11180
11180
|
return results;
|
|
11181
11181
|
}
|
|
11182
|
+
/**
|
|
11183
|
+
* Time Complexity: O(n)
|
|
11184
|
+
* Space Complexity: O(n)
|
|
11185
|
+
*
|
|
11186
|
+
* The `map` function in TypeScript overrides the default behavior to create a new Red-Black Tree by
|
|
11187
|
+
* applying a callback to each entry in the original tree.
|
|
11188
|
+
* @param callback - A function that will be called for each entry in the tree, with parameters
|
|
11189
|
+
* representing the key, value, index, and the tree itself. It should return an entry for the new
|
|
11190
|
+
* tree.
|
|
11191
|
+
* @param [options] - The `options` parameter in the `map` method is of type `RedBlackTreeOptions<MK, MV,
|
|
11192
|
+
* MR>`. This parameter allows you to specify additional options or configurations for the Red-Black
|
|
11193
|
+
* Tree that will be created during the mapping process. These options could include things like
|
|
11194
|
+
* custom comparators
|
|
11195
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
|
|
11196
|
+
* the value of `this` when executing the `callback` function. It allows you to set the context
|
|
11197
|
+
* (value of `this`) for the callback function. This can be useful when you want to access properties
|
|
11198
|
+
* or
|
|
11199
|
+
* @returns A new Red-Black Tree is being returned, where each entry has been transformed using the
|
|
11200
|
+
* provided callback function.
|
|
11201
|
+
*/
|
|
11202
|
+
// @ts-ignore
|
|
11203
|
+
map(callback, options, thisArg) {
|
|
11204
|
+
const newTree = new _RedBlackTree([], options);
|
|
11205
|
+
let index = 0;
|
|
11206
|
+
for (const [key, value] of this) {
|
|
11207
|
+
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
11208
|
+
}
|
|
11209
|
+
return newTree;
|
|
11210
|
+
}
|
|
11182
11211
|
/**
|
|
11183
11212
|
* Time Complexity: O(1)
|
|
11184
11213
|
* Space Complexity: O(1)
|
|
@@ -11240,7 +11269,7 @@ var dataStructureTyped = (() => {
|
|
|
11240
11269
|
node.parent = parent;
|
|
11241
11270
|
if (!parent) {
|
|
11242
11271
|
this._setRoot(node);
|
|
11243
|
-
} else if (node.key
|
|
11272
|
+
} else if (this._compare(node.key, parent.key) < 0) {
|
|
11244
11273
|
parent.left = node;
|
|
11245
11274
|
} else {
|
|
11246
11275
|
parent.right = node;
|
|
@@ -11538,11 +11567,12 @@ var dataStructureTyped = (() => {
|
|
|
11538
11567
|
* @returns a new instance of the AVLTreeMultiMap class, with the specified options, as a TREE
|
|
11539
11568
|
* object.
|
|
11540
11569
|
*/
|
|
11570
|
+
// @ts-ignore
|
|
11541
11571
|
createTree(options) {
|
|
11542
11572
|
return new _AVLTreeMultiMap([], __spreadValues({
|
|
11543
11573
|
iterationType: this.iterationType,
|
|
11544
11574
|
isMapMode: this._isMapMode,
|
|
11545
|
-
|
|
11575
|
+
specifyComparable: this._specifyComparable,
|
|
11546
11576
|
toEntryFn: this._toEntryFn,
|
|
11547
11577
|
isReverse: this._isReverse
|
|
11548
11578
|
}, options));
|
|
@@ -11557,35 +11587,6 @@ var dataStructureTyped = (() => {
|
|
|
11557
11587
|
isNode(keyNodeEntryOrRaw) {
|
|
11558
11588
|
return keyNodeEntryOrRaw instanceof AVLTreeMultiMapNode;
|
|
11559
11589
|
}
|
|
11560
|
-
/**
|
|
11561
|
-
* The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
|
|
11562
|
-
* a node object.
|
|
11563
|
-
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
|
|
11564
|
-
* `keyNodeEntryOrRaw` parameter can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
11565
|
-
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
11566
|
-
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
11567
|
-
* value is provided, it will default to `undefined`.
|
|
11568
|
-
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
11569
|
-
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
11570
|
-
* @returns either a NODE object or undefined.
|
|
11571
|
-
*/
|
|
11572
|
-
_keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
|
|
11573
|
-
if (keyNodeEntryOrRaw === void 0 || keyNodeEntryOrRaw === null) return [void 0, void 0];
|
|
11574
|
-
if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
|
|
11575
|
-
if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
11576
|
-
const [key, entryValue] = keyNodeEntryOrRaw;
|
|
11577
|
-
if (key === void 0 || key === null) return [void 0, void 0];
|
|
11578
|
-
const finalValue = value != null ? value : entryValue;
|
|
11579
|
-
return [this.createNode(key, finalValue, count), finalValue];
|
|
11580
|
-
}
|
|
11581
|
-
if (this.isRaw(keyNodeEntryOrRaw)) {
|
|
11582
|
-
const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
11583
|
-
const finalValue = value != null ? value : entryValue;
|
|
11584
|
-
if (this.isKey(key)) return [this.createNode(key, finalValue, count), finalValue];
|
|
11585
|
-
}
|
|
11586
|
-
if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, count), value];
|
|
11587
|
-
return [void 0, void 0];
|
|
11588
|
-
}
|
|
11589
11590
|
/**
|
|
11590
11591
|
* Time Complexity: O(log n)
|
|
11591
11592
|
* Space Complexity: O(1)
|
|
@@ -11745,6 +11746,7 @@ var dataStructureTyped = (() => {
|
|
|
11745
11746
|
* The function overrides the clone method to create a deep copy of a tree object.
|
|
11746
11747
|
* @returns The `clone()` method is returning a cloned instance of the `TREE` object.
|
|
11747
11748
|
*/
|
|
11749
|
+
// @ts-ignore
|
|
11748
11750
|
clone() {
|
|
11749
11751
|
const cloned = this.createTree();
|
|
11750
11752
|
if (this._isMapMode) this.bfs((node) => cloned.add(node.key, void 0, node.count));
|
|
@@ -11752,6 +11754,62 @@ var dataStructureTyped = (() => {
|
|
|
11752
11754
|
if (this._isMapMode) cloned._store = this._store;
|
|
11753
11755
|
return cloned;
|
|
11754
11756
|
}
|
|
11757
|
+
/**
|
|
11758
|
+
* The `map` function in TypeScript overrides the default behavior to create a new AVLTreeMultiMap
|
|
11759
|
+
* with modified entries based on a provided callback.
|
|
11760
|
+
* @param callback - The `callback` parameter is a function that will be called for each entry in the
|
|
11761
|
+
* AVLTreeMultiMap. It takes four arguments:
|
|
11762
|
+
* @param [options] - The `options` parameter in the `override map` function is of type
|
|
11763
|
+
* `AVLTreeMultiMapOptions<MK, MV, MR>`. This parameter allows you to provide additional
|
|
11764
|
+
* configuration options when creating a new `AVLTreeMultiMap` instance within the `map` function.
|
|
11765
|
+
* These options
|
|
11766
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
|
|
11767
|
+
* the value of `this` when executing the `callback` function. It allows you to set the context
|
|
11768
|
+
* (value of `this`) for the callback function. This can be useful when you want to access properties
|
|
11769
|
+
* or
|
|
11770
|
+
* @returns The `map` method is returning a new `AVLTreeMultiMap` instance with the entries
|
|
11771
|
+
* transformed by the provided `callback` function. Each entry in the original tree is passed to the
|
|
11772
|
+
* `callback` function along with the index and the original tree itself. The transformed entries are
|
|
11773
|
+
* then added to the new `AVLTreeMultiMap` instance, which is returned at the end.
|
|
11774
|
+
*/
|
|
11775
|
+
// @ts-ignore
|
|
11776
|
+
map(callback, options, thisArg) {
|
|
11777
|
+
const newTree = new _AVLTreeMultiMap([], options);
|
|
11778
|
+
let index = 0;
|
|
11779
|
+
for (const [key, value] of this) {
|
|
11780
|
+
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
11781
|
+
}
|
|
11782
|
+
return newTree;
|
|
11783
|
+
}
|
|
11784
|
+
/**
|
|
11785
|
+
* The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
|
|
11786
|
+
* a node object.
|
|
11787
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
|
|
11788
|
+
* `keyNodeEntryOrRaw` parameter can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
11789
|
+
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
11790
|
+
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
11791
|
+
* value is provided, it will default to `undefined`.
|
|
11792
|
+
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
11793
|
+
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
11794
|
+
* @returns either a NODE object or undefined.
|
|
11795
|
+
*/
|
|
11796
|
+
_keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
|
|
11797
|
+
if (keyNodeEntryOrRaw === void 0 || keyNodeEntryOrRaw === null) return [void 0, void 0];
|
|
11798
|
+
if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
|
|
11799
|
+
if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
11800
|
+
const [key, entryValue] = keyNodeEntryOrRaw;
|
|
11801
|
+
if (key === void 0 || key === null) return [void 0, void 0];
|
|
11802
|
+
const finalValue = value != null ? value : entryValue;
|
|
11803
|
+
return [this.createNode(key, finalValue, count), finalValue];
|
|
11804
|
+
}
|
|
11805
|
+
if (this.isRaw(keyNodeEntryOrRaw)) {
|
|
11806
|
+
const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
11807
|
+
const finalValue = value != null ? value : entryValue;
|
|
11808
|
+
if (this.isKey(key)) return [this.createNode(key, finalValue, count), finalValue];
|
|
11809
|
+
}
|
|
11810
|
+
if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, count), value];
|
|
11811
|
+
return [void 0, void 0];
|
|
11812
|
+
}
|
|
11755
11813
|
/**
|
|
11756
11814
|
* Time Complexity: O(1)
|
|
11757
11815
|
* Space Complexity: O(1)
|
|
@@ -11898,43 +11956,15 @@ var dataStructureTyped = (() => {
|
|
|
11898
11956
|
* @returns a new instance of the `TreeMultiMap` class, with the provided options merged with the
|
|
11899
11957
|
* existing `iterationType` property. The returned value is casted as `TREE`.
|
|
11900
11958
|
*/
|
|
11959
|
+
// @ts-ignore
|
|
11901
11960
|
createTree(options) {
|
|
11902
11961
|
return new _TreeMultiMap([], __spreadValues({
|
|
11903
11962
|
iterationType: this.iterationType,
|
|
11904
11963
|
isMapMode: this._isMapMode,
|
|
11905
|
-
|
|
11964
|
+
specifyComparable: this._specifyComparable,
|
|
11906
11965
|
toEntryFn: this._toEntryFn
|
|
11907
11966
|
}, options));
|
|
11908
11967
|
}
|
|
11909
|
-
/**
|
|
11910
|
-
* The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
|
|
11911
|
-
* node based on the input.
|
|
11912
|
-
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
11913
|
-
* `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
11914
|
-
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
11915
|
-
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
11916
|
-
* an existing node.
|
|
11917
|
-
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
11918
|
-
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
11919
|
-
* @returns either a NODE object or undefined.
|
|
11920
|
-
*/
|
|
11921
|
-
_keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
|
|
11922
|
-
if (keyNodeEntryOrRaw === void 0 || keyNodeEntryOrRaw === null) return [void 0, void 0];
|
|
11923
|
-
if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
|
|
11924
|
-
if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
11925
|
-
const [key, entryValue] = keyNodeEntryOrRaw;
|
|
11926
|
-
if (key === void 0 || key === null) return [void 0, void 0];
|
|
11927
|
-
const finalValue = value != null ? value : entryValue;
|
|
11928
|
-
if (this.isKey(key)) return [this.createNode(key, finalValue, "BLACK", count), finalValue];
|
|
11929
|
-
}
|
|
11930
|
-
if (this.isRaw(keyNodeEntryOrRaw)) {
|
|
11931
|
-
const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
11932
|
-
const finalValue = value != null ? value : entryValue;
|
|
11933
|
-
if (this.isKey(key)) return [this.createNode(key, finalValue, "BLACK", count), finalValue];
|
|
11934
|
-
}
|
|
11935
|
-
if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, "BLACK", count), value];
|
|
11936
|
-
return [void 0, void 0];
|
|
11937
|
-
}
|
|
11938
11968
|
/**
|
|
11939
11969
|
* The function checks if the input is an instance of the TreeMultiMapNode class.
|
|
11940
11970
|
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
@@ -12133,12 +12163,66 @@ var dataStructureTyped = (() => {
|
|
|
12133
12163
|
* The function overrides the clone method to create a deep copy of a tree object.
|
|
12134
12164
|
* @returns The `clone()` method is returning a cloned instance of the `TREE` object.
|
|
12135
12165
|
*/
|
|
12166
|
+
// @ts-ignore
|
|
12136
12167
|
clone() {
|
|
12137
12168
|
const cloned = this.createTree();
|
|
12138
12169
|
this.bfs((node) => cloned.add(node.key, void 0, node.count));
|
|
12139
12170
|
if (this._isMapMode) cloned._store = this._store;
|
|
12140
12171
|
return cloned;
|
|
12141
12172
|
}
|
|
12173
|
+
/**
|
|
12174
|
+
* The `map` function in TypeScript overrides the default behavior to create a new TreeMultiMap with
|
|
12175
|
+
* modified entries based on a provided callback.
|
|
12176
|
+
* @param callback - The `callback` parameter is a function that will be called for each entry in the
|
|
12177
|
+
* map. It takes four arguments:
|
|
12178
|
+
* @param [options] - The `options` parameter in the `override map` function is of type
|
|
12179
|
+
* `TreeMultiMapOptions<MK, MV, MR>`. This parameter allows you to provide additional configuration
|
|
12180
|
+
* options when creating a new `TreeMultiMap` instance within the `map` function. These options could
|
|
12181
|
+
* include things like
|
|
12182
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
|
|
12183
|
+
* the value of `this` when executing the `callback` function. It allows you to set the context
|
|
12184
|
+
* (value of `this`) for the callback function when it is called within the `map` function. This
|
|
12185
|
+
* @returns A new TreeMultiMap instance is being returned, which is populated with entries generated
|
|
12186
|
+
* by the provided callback function.
|
|
12187
|
+
*/
|
|
12188
|
+
// @ts-ignore
|
|
12189
|
+
map(callback, options, thisArg) {
|
|
12190
|
+
const newTree = new _TreeMultiMap([], options);
|
|
12191
|
+
let index = 0;
|
|
12192
|
+
for (const [key, value] of this) {
|
|
12193
|
+
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
12194
|
+
}
|
|
12195
|
+
return newTree;
|
|
12196
|
+
}
|
|
12197
|
+
/**
|
|
12198
|
+
* The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
|
|
12199
|
+
* node based on the input.
|
|
12200
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
12201
|
+
* `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
12202
|
+
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
12203
|
+
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
12204
|
+
* an existing node.
|
|
12205
|
+
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
12206
|
+
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
12207
|
+
* @returns either a NODE object or undefined.
|
|
12208
|
+
*/
|
|
12209
|
+
_keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
|
|
12210
|
+
if (keyNodeEntryOrRaw === void 0 || keyNodeEntryOrRaw === null) return [void 0, void 0];
|
|
12211
|
+
if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
|
|
12212
|
+
if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
12213
|
+
const [key, entryValue] = keyNodeEntryOrRaw;
|
|
12214
|
+
if (key === void 0 || key === null) return [void 0, void 0];
|
|
12215
|
+
const finalValue = value != null ? value : entryValue;
|
|
12216
|
+
if (this.isKey(key)) return [this.createNode(key, finalValue, "BLACK", count), finalValue];
|
|
12217
|
+
}
|
|
12218
|
+
if (this.isRaw(keyNodeEntryOrRaw)) {
|
|
12219
|
+
const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
12220
|
+
const finalValue = value != null ? value : entryValue;
|
|
12221
|
+
if (this.isKey(key)) return [this.createNode(key, finalValue, "BLACK", count), finalValue];
|
|
12222
|
+
}
|
|
12223
|
+
if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, "BLACK", count), value];
|
|
12224
|
+
return [void 0, void 0];
|
|
12225
|
+
}
|
|
12142
12226
|
/**
|
|
12143
12227
|
* Time Complexity: O(1)
|
|
12144
12228
|
* Space Complexity: O(1)
|