undirected-graph-typed 1.53.7 → 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.
Files changed (68) hide show
  1. package/dist/common/index.js +5 -0
  2. package/dist/data-structures/base/iterable-entry-base.js +4 -4
  3. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +36 -17
  4. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +65 -36
  5. package/dist/data-structures/binary-tree/avl-tree.d.ts +12 -8
  6. package/dist/data-structures/binary-tree/avl-tree.js +19 -6
  7. package/dist/data-structures/binary-tree/binary-tree.d.ts +53 -40
  8. package/dist/data-structures/binary-tree/binary-tree.js +76 -72
  9. package/dist/data-structures/binary-tree/bst.d.ts +87 -52
  10. package/dist/data-structures/binary-tree/bst.js +111 -63
  11. package/dist/data-structures/binary-tree/index.d.ts +1 -1
  12. package/dist/data-structures/binary-tree/index.js +1 -1
  13. package/dist/data-structures/binary-tree/{rb-tree.d.ts → red-black-tree.d.ts} +83 -10
  14. package/dist/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +91 -44
  15. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +34 -18
  16. package/dist/data-structures/binary-tree/tree-multi-map.js +66 -40
  17. package/dist/data-structures/graph/abstract-graph.js +2 -2
  18. package/dist/data-structures/hash/hash-map.d.ts +31 -1
  19. package/dist/data-structures/hash/hash-map.js +35 -5
  20. package/dist/data-structures/heap/heap.d.ts +20 -3
  21. package/dist/data-structures/heap/heap.js +31 -11
  22. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +46 -11
  23. package/dist/data-structures/linked-list/doubly-linked-list.js +68 -21
  24. package/dist/data-structures/linked-list/singly-linked-list.d.ts +44 -11
  25. package/dist/data-structures/linked-list/singly-linked-list.js +70 -26
  26. package/dist/data-structures/queue/deque.d.ts +37 -8
  27. package/dist/data-structures/queue/deque.js +73 -29
  28. package/dist/data-structures/queue/queue.d.ts +41 -1
  29. package/dist/data-structures/queue/queue.js +51 -9
  30. package/dist/data-structures/stack/stack.d.ts +27 -10
  31. package/dist/data-structures/stack/stack.js +39 -20
  32. package/dist/data-structures/trie/trie.d.ts +8 -3
  33. package/dist/data-structures/trie/trie.js +8 -3
  34. package/dist/interfaces/binary-tree.d.ts +3 -4
  35. package/dist/types/data-structures/base/base.d.ts +1 -1
  36. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
  37. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
  38. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -3
  39. package/dist/types/data-structures/binary-tree/bst.d.ts +3 -4
  40. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +4 -5
  41. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -5
  42. package/package.json +2 -2
  43. package/src/common/index.ts +7 -1
  44. package/src/data-structures/base/iterable-entry-base.ts +4 -4
  45. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +82 -55
  46. package/src/data-structures/binary-tree/avl-tree.ts +32 -15
  47. package/src/data-structures/binary-tree/binary-tree.ts +89 -84
  48. package/src/data-structures/binary-tree/bst.ts +149 -97
  49. package/src/data-structures/binary-tree/index.ts +1 -1
  50. package/src/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +105 -55
  51. package/src/data-structures/binary-tree/tree-multi-map.ts +81 -51
  52. package/src/data-structures/graph/abstract-graph.ts +2 -2
  53. package/src/data-structures/hash/hash-map.ts +37 -7
  54. package/src/data-structures/heap/heap.ts +33 -10
  55. package/src/data-structures/linked-list/doubly-linked-list.ts +75 -21
  56. package/src/data-structures/linked-list/singly-linked-list.ts +77 -27
  57. package/src/data-structures/queue/deque.ts +72 -28
  58. package/src/data-structures/queue/queue.ts +50 -7
  59. package/src/data-structures/stack/stack.ts +39 -20
  60. package/src/data-structures/trie/trie.ts +8 -3
  61. package/src/interfaces/binary-tree.ts +3 -13
  62. package/src/types/data-structures/base/base.ts +1 -1
  63. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -4
  64. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -4
  65. package/src/types/data-structures/binary-tree/binary-tree.ts +3 -3
  66. package/src/types/data-structures/binary-tree/bst.ts +3 -5
  67. package/src/types/data-structures/binary-tree/rb-tree.ts +4 -6
  68. package/src/types/data-structures/binary-tree/tree-multi-map.ts +4 -6
@@ -5,9 +5,9 @@
5
5
  * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeDeleteResult, BSTNOptKeyOrNode, BTNRep, IterationType, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
8
+ import type { BinaryTreeDeleteResult, BSTNOptKeyOrNode, BTNRep, EntryCallback, IterationType, RBTNColor, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
9
9
  import { IBinaryTree } from '../../interfaces';
10
- import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
10
+ import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
11
11
  export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>> extends RedBlackTreeNode<K, V, NODE> {
12
12
  /**
13
13
  * The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
@@ -35,7 +35,7 @@ export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMa
35
35
  */
36
36
  set count(value: number);
37
37
  }
38
- export declare class TreeMultiMap<K = any, V = any, R = object, 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> {
38
+ export declare class TreeMultiMap<K = any, V = any, R = object, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>> extends RedBlackTree<K, V, R, NODE> implements IBinaryTree<K, V, R, NODE> {
39
39
  /**
40
40
  * The constructor function initializes a TreeMultiMap object with optional initial data.
41
41
  * @param keysNodesEntriesOrRaws - The parameter `keysNodesEntriesOrRaws` is an
@@ -83,20 +83,7 @@ export declare class TreeMultiMap<K = any, V = any, R = object, NODE extends Tre
83
83
  * @returns a new instance of the `TreeMultiMap` class, with the provided options merged with the
84
84
  * existing `iterationType` property. The returned value is casted as `TREE`.
85
85
  */
86
- createTree(options?: TreeMultiMapOptions<K, V, R>): TREE;
87
- /**
88
- * The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
89
- * node based on the input.
90
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
91
- * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
92
- * @param {V} [value] - The `value` parameter is an optional value that represents the value
93
- * associated with the key in the node. It is used when creating a new node or updating the value of
94
- * an existing node.
95
- * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
96
- * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
97
- * @returns either a NODE object or undefined.
98
- */
99
- keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V, count?: number): [NODE | undefined, V | undefined];
86
+ createTree(options?: TreeMultiMapOptions<K, V, R>): TreeMultiMap<K, V, R, NODE>;
100
87
  /**
101
88
  * The function checks if the input is an instance of the TreeMultiMapNode class.
102
89
  * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
@@ -167,7 +154,36 @@ export declare class TreeMultiMap<K = any, V = any, R = object, NODE extends Tre
167
154
  * The function overrides the clone method to create a deep copy of a tree object.
168
155
  * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
169
156
  */
170
- clone(): TREE;
157
+ clone(): TreeMultiMap<K, V, R, NODE>;
158
+ /**
159
+ * The `map` function in TypeScript overrides the default behavior to create a new TreeMultiMap with
160
+ * modified entries based on a provided callback.
161
+ * @param callback - The `callback` parameter is a function that will be called for each entry in the
162
+ * map. It takes four arguments:
163
+ * @param [options] - The `options` parameter in the `override map` function is of type
164
+ * `TreeMultiMapOptions<MK, MV, MR>`. This parameter allows you to provide additional configuration
165
+ * options when creating a new `TreeMultiMap` instance within the `map` function. These options could
166
+ * include things like
167
+ * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
168
+ * the value of `this` when executing the `callback` function. It allows you to set the context
169
+ * (value of `this`) for the callback function when it is called within the `map` function. This
170
+ * @returns A new TreeMultiMap instance is being returned, which is populated with entries generated
171
+ * by the provided callback function.
172
+ */
173
+ map<MK, MV, MR>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: TreeMultiMapOptions<MK, MV, MR>, thisArg?: any): TreeMultiMap<MK, MV, MR, TreeMultiMapNode<MK, MV, TreeMultiMapNodeNested<MK, MV>>>;
174
+ /**
175
+ * The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
176
+ * node based on the input.
177
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
178
+ * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
179
+ * @param {V} [value] - The `value` parameter is an optional value that represents the value
180
+ * associated with the key in the node. It is used when creating a new node or updating the value of
181
+ * an existing node.
182
+ * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
183
+ * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
184
+ * @returns either a NODE object or undefined.
185
+ */
186
+ protected _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V, count?: number): [NODE | undefined, V | undefined];
171
187
  /**
172
188
  * Time Complexity: O(1)
173
189
  * Space Complexity: O(1)
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TreeMultiMap = exports.TreeMultiMapNode = void 0;
4
- const rb_tree_1 = require("./rb-tree");
5
- class TreeMultiMapNode extends rb_tree_1.RedBlackTreeNode {
4
+ const red_black_tree_1 = require("./red-black-tree");
5
+ class TreeMultiMapNode extends red_black_tree_1.RedBlackTreeNode {
6
6
  /**
7
7
  * The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
8
8
  * @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
@@ -37,7 +37,7 @@ class TreeMultiMapNode extends rb_tree_1.RedBlackTreeNode {
37
37
  }
38
38
  }
39
39
  exports.TreeMultiMapNode = TreeMultiMapNode;
40
- class TreeMultiMap extends rb_tree_1.RedBlackTree {
40
+ class TreeMultiMap extends red_black_tree_1.RedBlackTree {
41
41
  /**
42
42
  * The constructor function initializes a TreeMultiMap object with optional initial data.
43
43
  * @param keysNodesEntriesOrRaws - The parameter `keysNodesEntriesOrRaws` is an
@@ -98,43 +98,9 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
98
98
  * @returns a new instance of the `TreeMultiMap` class, with the provided options merged with the
99
99
  * existing `iterationType` property. The returned value is casted as `TREE`.
100
100
  */
101
+ // @ts-ignore
101
102
  createTree(options) {
102
- return new TreeMultiMap([], Object.assign({ iterationType: this.iterationType, isMapMode: this._isMapMode, extractComparable: this._extractComparable, toEntryFn: this._toEntryFn }, options));
103
- }
104
- /**
105
- * The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
106
- * node based on the input.
107
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
108
- * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
109
- * @param {V} [value] - The `value` parameter is an optional value that represents the value
110
- * associated with the key in the node. It is used when creating a new node or updating the value of
111
- * an existing node.
112
- * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
113
- * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
114
- * @returns either a NODE object or undefined.
115
- */
116
- keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
117
- if (keyNodeEntryOrRaw === undefined || keyNodeEntryOrRaw === null)
118
- return [undefined, undefined];
119
- if (this.isNode(keyNodeEntryOrRaw))
120
- return [keyNodeEntryOrRaw, value];
121
- if (this.isEntry(keyNodeEntryOrRaw)) {
122
- const [key, entryValue] = keyNodeEntryOrRaw;
123
- if (key === undefined || key === null)
124
- return [undefined, undefined];
125
- const finalValue = value !== null && value !== void 0 ? value : entryValue;
126
- if (this.isKey(key))
127
- return [this.createNode(key, finalValue, 'BLACK', count), finalValue];
128
- }
129
- if (this.isRaw(keyNodeEntryOrRaw)) {
130
- const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
131
- const finalValue = value !== null && value !== void 0 ? value : entryValue;
132
- if (this.isKey(key))
133
- return [this.createNode(key, finalValue, 'BLACK', count), finalValue];
134
- }
135
- if (this.isKey(keyNodeEntryOrRaw))
136
- return [this.createNode(keyNodeEntryOrRaw, value, 'BLACK', count), value];
137
- return [undefined, undefined];
103
+ return new TreeMultiMap([], Object.assign({ iterationType: this.iterationType, isMapMode: this._isMapMode, specifyComparable: this._specifyComparable, toEntryFn: this._toEntryFn }, options));
138
104
  }
139
105
  /**
140
106
  * The function checks if the input is an instance of the TreeMultiMapNode class.
@@ -163,7 +129,7 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
163
129
  * was successful, and false otherwise.
164
130
  */
165
131
  add(keyNodeEntryOrRaw, value, count = 1) {
166
- const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count);
132
+ const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count);
167
133
  const orgCount = (newNode === null || newNode === void 0 ? void 0 : newNode.count) || 0;
168
134
  const isSuccessAdded = super.add(newNode, newValue);
169
135
  if (isSuccessAdded) {
@@ -353,6 +319,7 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
353
319
  * The function overrides the clone method to create a deep copy of a tree object.
354
320
  * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
355
321
  */
322
+ // @ts-ignore
356
323
  clone() {
357
324
  const cloned = this.createTree();
358
325
  this.bfs(node => cloned.add(node.key, undefined, node.count));
@@ -360,6 +327,65 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
360
327
  cloned._store = this._store;
361
328
  return cloned;
362
329
  }
330
+ /**
331
+ * The `map` function in TypeScript overrides the default behavior to create a new TreeMultiMap with
332
+ * modified entries based on a provided callback.
333
+ * @param callback - The `callback` parameter is a function that will be called for each entry in the
334
+ * map. It takes four arguments:
335
+ * @param [options] - The `options` parameter in the `override map` function is of type
336
+ * `TreeMultiMapOptions<MK, MV, MR>`. This parameter allows you to provide additional configuration
337
+ * options when creating a new `TreeMultiMap` instance within the `map` function. These options could
338
+ * include things like
339
+ * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
340
+ * the value of `this` when executing the `callback` function. It allows you to set the context
341
+ * (value of `this`) for the callback function when it is called within the `map` function. This
342
+ * @returns A new TreeMultiMap instance is being returned, which is populated with entries generated
343
+ * by the provided callback function.
344
+ */
345
+ // @ts-ignore
346
+ map(callback, options, thisArg) {
347
+ const newTree = new TreeMultiMap([], options);
348
+ let index = 0;
349
+ for (const [key, value] of this) {
350
+ newTree.add(callback.call(thisArg, key, value, index++, this));
351
+ }
352
+ return newTree;
353
+ }
354
+ /**
355
+ * The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
356
+ * node based on the input.
357
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
358
+ * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
359
+ * @param {V} [value] - The `value` parameter is an optional value that represents the value
360
+ * associated with the key in the node. It is used when creating a new node or updating the value of
361
+ * an existing node.
362
+ * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
363
+ * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
364
+ * @returns either a NODE object or undefined.
365
+ */
366
+ _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
367
+ if (keyNodeEntryOrRaw === undefined || keyNodeEntryOrRaw === null)
368
+ return [undefined, undefined];
369
+ if (this.isNode(keyNodeEntryOrRaw))
370
+ return [keyNodeEntryOrRaw, value];
371
+ if (this.isEntry(keyNodeEntryOrRaw)) {
372
+ const [key, entryValue] = keyNodeEntryOrRaw;
373
+ if (key === undefined || key === null)
374
+ return [undefined, undefined];
375
+ const finalValue = value !== null && value !== void 0 ? value : entryValue;
376
+ if (this.isKey(key))
377
+ return [this.createNode(key, finalValue, 'BLACK', count), finalValue];
378
+ }
379
+ if (this.isRaw(keyNodeEntryOrRaw)) {
380
+ const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
381
+ const finalValue = value !== null && value !== void 0 ? value : entryValue;
382
+ if (this.isKey(key))
383
+ return [this.createNode(key, finalValue, 'BLACK', count), finalValue];
384
+ }
385
+ if (this.isKey(keyNodeEntryOrRaw))
386
+ return [this.createNode(keyNodeEntryOrRaw, value, 'BLACK', count), value];
387
+ return [undefined, undefined];
388
+ }
363
389
  /**
364
390
  * Time Complexity: O(1)
365
391
  * Space Complexity: O(1)
@@ -813,7 +813,7 @@ class AbstractGraph extends base_1.IterableEntryBase {
813
813
  const filtered = [];
814
814
  let index = 0;
815
815
  for (const [key, value] of this) {
816
- if (predicate.call(thisArg, value, key, index, this)) {
816
+ if (predicate.call(thisArg, key, value, index, this)) {
817
817
  filtered.push([key, value]);
818
818
  }
819
819
  index++;
@@ -837,7 +837,7 @@ class AbstractGraph extends base_1.IterableEntryBase {
837
837
  const mapped = [];
838
838
  let index = 0;
839
839
  for (const [key, value] of this) {
840
- mapped.push(callback.call(thisArg, value, key, index, this));
840
+ mapped.push(callback.call(thisArg, key, value, index, this));
841
841
  index++;
842
842
  }
843
843
  return mapped;
@@ -62,6 +62,9 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
62
62
  */
63
63
  get hashFn(): (key: K) => string;
64
64
  /**
65
+ * Time Complexity: O(1)
66
+ * Space Complexity: O(1)
67
+ *
65
68
  * The function checks if a given element is an array with exactly two elements.
66
69
  * @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
67
70
  * data type.
@@ -69,16 +72,25 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
69
72
  */
70
73
  isEntry(rawElement: any): rawElement is [K, V];
71
74
  /**
75
+ * Time Complexity: O(1)
76
+ * Space Complexity: O(1)
77
+ *
72
78
  * The function checks if the size of an object is equal to zero and returns a boolean value.
73
79
  * @returns A boolean value indicating whether the size of the object is 0 or not.
74
80
  */
75
81
  isEmpty(): boolean;
76
82
  /**
83
+ * Time Complexity: O(1)
84
+ * Space Complexity: O(1)
85
+ *
77
86
  * The clear() function resets the state of an object by clearing its internal store, object map, and
78
87
  * size.
79
88
  */
80
89
  clear(): void;
81
90
  /**
91
+ * Time Complexity: O(1)
92
+ * Space Complexity: O(1)
93
+ *
82
94
  * The `set` function adds a key-value pair to a map-like data structure, incrementing the size if
83
95
  * the key is not already present.
84
96
  * @param {K} key - The key parameter is the key used to identify the value in the data structure. It
@@ -89,6 +101,9 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
89
101
  */
90
102
  set(key: K, value: V): boolean;
91
103
  /**
104
+ * Time Complexity: O(k)
105
+ * Space Complexity: O(k)
106
+ *
92
107
  * The function `setMany` takes an iterable collection of objects, maps each object to a key-value
93
108
  * pair using a mapping function, and sets each key-value pair in the current object.
94
109
  * @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements of a type
@@ -97,6 +112,9 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
97
112
  */
98
113
  setMany(entryOrRawElements: Iterable<R | [K, V]>): boolean[];
99
114
  /**
115
+ * Time Complexity: O(1)
116
+ * Space Complexity: O(1)
117
+ *
100
118
  * The `get` function retrieves a value from a map based on a given key, either from an object map or
101
119
  * a string map.
102
120
  * @param {K} key - The `key` parameter is the key used to retrieve a value from the map. It can be
@@ -106,6 +124,9 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
106
124
  */
107
125
  get(key: K): V | undefined;
108
126
  /**
127
+ * Time Complexity: O(1)
128
+ * Space Complexity: O(1)
129
+ *
109
130
  * The `has` function checks if a given key exists in the `_objMap` or `_store` based on whether it
110
131
  * is an object key or not.
111
132
  * @param {K} key - The parameter "key" is of type K, which means it can be any type.
@@ -113,6 +134,9 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
113
134
  */
114
135
  has(key: K): boolean;
115
136
  /**
137
+ * Time Complexity: O(1)
138
+ * Space Complexity: O(1)
139
+ *
116
140
  * The `delete` function removes an element from a map-like data structure based on the provided key.
117
141
  * @param {K} key - The `key` parameter is the key of the element that you want to delete from the
118
142
  * data structure.
@@ -292,6 +316,9 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
292
316
  */
293
317
  set(key: K, value?: V): boolean;
294
318
  /**
319
+ * Time Complexity: O(k)
320
+ * Space Complexity: O(k)
321
+ *
295
322
  * The function `setMany` takes an iterable collection, converts each element into a key-value pair
296
323
  * using a provided function, and sets each key-value pair in the current object, returning an array
297
324
  * of booleans indicating the success of each set operation.
@@ -301,6 +328,9 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
301
328
  */
302
329
  setMany(entryOrRawElements: Iterable<R | [K, V]>): boolean[];
303
330
  /**
331
+ * Time Complexity: O(1)
332
+ * Space Complexity: O(1)
333
+ *
304
334
  * The function checks if a given key exists in a map, using different logic depending on whether the
305
335
  * key is a weak key or not.
306
336
  * @param {K} key - The `key` parameter is the key that is being checked for existence in the map.
@@ -420,7 +450,7 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
420
450
  * @returns a new `LinkedHashMap` object with the values mapped according to the provided callback
421
451
  * function.
422
452
  */
423
- map<VM>(callback: EntryCallback<K, V, VM>, thisArg?: any): LinkedHashMap<K, VM>;
453
+ map<MK, MV>(callback: EntryCallback<K, V, [MK, MV]>, thisArg?: any): LinkedHashMap<MK, MV>;
424
454
  /**
425
455
  * Time Complexity: O(n)
426
456
  * Space Complexity: O(1)
@@ -75,6 +75,9 @@ class HashMap extends base_1.IterableEntryBase {
75
75
  return this._hashFn;
76
76
  }
77
77
  /**
78
+ * Time Complexity: O(1)
79
+ * Space Complexity: O(1)
80
+ *
78
81
  * The function checks if a given element is an array with exactly two elements.
79
82
  * @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
80
83
  * data type.
@@ -84,6 +87,9 @@ class HashMap extends base_1.IterableEntryBase {
84
87
  return Array.isArray(rawElement) && rawElement.length === 2;
85
88
  }
86
89
  /**
90
+ * Time Complexity: O(1)
91
+ * Space Complexity: O(1)
92
+ *
87
93
  * The function checks if the size of an object is equal to zero and returns a boolean value.
88
94
  * @returns A boolean value indicating whether the size of the object is 0 or not.
89
95
  */
@@ -91,6 +97,9 @@ class HashMap extends base_1.IterableEntryBase {
91
97
  return this._size === 0;
92
98
  }
93
99
  /**
100
+ * Time Complexity: O(1)
101
+ * Space Complexity: O(1)
102
+ *
94
103
  * The clear() function resets the state of an object by clearing its internal store, object map, and
95
104
  * size.
96
105
  */
@@ -100,6 +109,9 @@ class HashMap extends base_1.IterableEntryBase {
100
109
  this._size = 0;
101
110
  }
102
111
  /**
112
+ * Time Complexity: O(1)
113
+ * Space Complexity: O(1)
114
+ *
103
115
  * The `set` function adds a key-value pair to a map-like data structure, incrementing the size if
104
116
  * the key is not already present.
105
117
  * @param {K} key - The key parameter is the key used to identify the value in the data structure. It
@@ -125,6 +137,9 @@ class HashMap extends base_1.IterableEntryBase {
125
137
  return true;
126
138
  }
127
139
  /**
140
+ * Time Complexity: O(k)
141
+ * Space Complexity: O(k)
142
+ *
128
143
  * The function `setMany` takes an iterable collection of objects, maps each object to a key-value
129
144
  * pair using a mapping function, and sets each key-value pair in the current object.
130
145
  * @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements of a type
@@ -150,6 +165,9 @@ class HashMap extends base_1.IterableEntryBase {
150
165
  return results;
151
166
  }
152
167
  /**
168
+ * Time Complexity: O(1)
169
+ * Space Complexity: O(1)
170
+ *
153
171
  * The `get` function retrieves a value from a map based on a given key, either from an object map or
154
172
  * a string map.
155
173
  * @param {K} key - The `key` parameter is the key used to retrieve a value from the map. It can be
@@ -168,6 +186,9 @@ class HashMap extends base_1.IterableEntryBase {
168
186
  }
169
187
  }
170
188
  /**
189
+ * Time Complexity: O(1)
190
+ * Space Complexity: O(1)
191
+ *
171
192
  * The `has` function checks if a given key exists in the `_objMap` or `_store` based on whether it
172
193
  * is an object key or not.
173
194
  * @param {K} key - The parameter "key" is of type K, which means it can be any type.
@@ -183,6 +204,9 @@ class HashMap extends base_1.IterableEntryBase {
183
204
  }
184
205
  }
185
206
  /**
207
+ * Time Complexity: O(1)
208
+ * Space Complexity: O(1)
209
+ *
186
210
  * The `delete` function removes an element from a map-like data structure based on the provided key.
187
211
  * @param {K} key - The `key` parameter is the key of the element that you want to delete from the
188
212
  * data structure.
@@ -237,7 +261,7 @@ class HashMap extends base_1.IterableEntryBase {
237
261
  const resultMap = new HashMap();
238
262
  let index = 0;
239
263
  for (const [key, value] of this) {
240
- resultMap.set(key, callbackfn.call(thisArg, value, key, index++, this));
264
+ resultMap.set(key, callbackfn.call(thisArg, key, value, index++, this));
241
265
  }
242
266
  return resultMap;
243
267
  }
@@ -261,7 +285,7 @@ class HashMap extends base_1.IterableEntryBase {
261
285
  const filteredMap = new HashMap();
262
286
  let index = 0;
263
287
  for (const [key, value] of this) {
264
- if (predicate.call(thisArg, value, key, index++, this)) {
288
+ if (predicate.call(thisArg, key, value, index++, this)) {
265
289
  filteredMap.set(key, value);
266
290
  }
267
291
  }
@@ -523,6 +547,9 @@ class LinkedHashMap extends base_1.IterableEntryBase {
523
547
  return true;
524
548
  }
525
549
  /**
550
+ * Time Complexity: O(k)
551
+ * Space Complexity: O(k)
552
+ *
526
553
  * The function `setMany` takes an iterable collection, converts each element into a key-value pair
527
554
  * using a provided function, and sets each key-value pair in the current object, returning an array
528
555
  * of booleans indicating the success of each set operation.
@@ -549,6 +576,9 @@ class LinkedHashMap extends base_1.IterableEntryBase {
549
576
  return results;
550
577
  }
551
578
  /**
579
+ * Time Complexity: O(1)
580
+ * Space Complexity: O(1)
581
+ *
552
582
  * The function checks if a given key exists in a map, using different logic depending on whether the
553
583
  * key is a weak key or not.
554
584
  * @param {K} key - The `key` parameter is the key that is being checked for existence in the map.
@@ -728,7 +758,7 @@ class LinkedHashMap extends base_1.IterableEntryBase {
728
758
  const filteredMap = new LinkedHashMap();
729
759
  let index = 0;
730
760
  for (const [key, value] of this) {
731
- if (predicate.call(thisArg, value, key, index, this)) {
761
+ if (predicate.call(thisArg, key, value, index, this)) {
732
762
  filteredMap.set(key, value);
733
763
  }
734
764
  index++;
@@ -756,8 +786,8 @@ class LinkedHashMap extends base_1.IterableEntryBase {
756
786
  const mappedMap = new LinkedHashMap();
757
787
  let index = 0;
758
788
  for (const [key, value] of this) {
759
- const newValue = callback.call(thisArg, value, key, index, this);
760
- mappedMap.set(key, newValue);
789
+ const [newKey, newValue] = callback.call(thisArg, key, value, index, this);
790
+ mappedMap.set(newKey, newValue);
761
791
  index++;
762
792
  }
763
793
  return mappedMap;
@@ -224,10 +224,27 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R, He
224
224
  * Time Complexity: O(log n)
225
225
  * Space Complexity: O(1)
226
226
  *
227
- * Insert an element into the heap and maintain the heap properties.
228
- * @param element - The element to be inserted.
227
+ * The add function pushes an element into an array and then triggers a bubble-up operation.
228
+ * @param {E} element - The `element` parameter represents the element that you want to add to the
229
+ * data structure.
230
+ * @returns The `add` method is returning a boolean value, which is the result of calling the
231
+ * `_bubbleUp` method with the index `this.elements.length - 1` as an argument.
229
232
  */
230
233
  add(element: E): boolean;
234
+ /**
235
+ * Time Complexity: O(k log n)
236
+ * Space Complexity: O(1)
237
+ *
238
+ * The `addMany` function iterates over elements and adds them to a collection, returning an array of
239
+ * boolean values indicating success or failure.
240
+ * @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `addMany` method is
241
+ * an iterable containing elements of type `E` or `R`. The method iterates over each element in the
242
+ * iterable and adds them to the data structure. If a transformation function `_toElementFn` is
243
+ * provided, it transforms the element
244
+ * @returns The `addMany` method returns an array of boolean values indicating whether each element
245
+ * in the input iterable was successfully added to the data structure.
246
+ */
247
+ addMany(elements: Iterable<E> | Iterable<R>): boolean[];
231
248
  /**
232
249
  * Time Complexity: O(log n)
233
250
  * Space Complexity: O(1)
@@ -340,7 +357,7 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R, He
340
357
  */
341
358
  filter(callback: ElementCallback<E, R, boolean, Heap<E, R>>, thisArg?: any): Heap<E, R>;
342
359
  /**
343
- * Time Complexity: O(n log n)
360
+ * Time Complexity: O(n)
344
361
  * Space Complexity: O(n)
345
362
  *
346
363
  * The `map` function creates a new heap by applying a callback function to each element of the
@@ -218,14 +218,7 @@ class Heap extends base_1.IterableElementBase {
218
218
  if (comparator)
219
219
  this._comparator = comparator;
220
220
  }
221
- if (elements) {
222
- for (const el of elements) {
223
- if (this.toElementFn)
224
- this.add(this.toElementFn(el));
225
- else
226
- this.add(el);
227
- }
228
- }
221
+ this.addMany(elements);
229
222
  }
230
223
  /**
231
224
  * The function returns an array of elements.
@@ -261,13 +254,40 @@ class Heap extends base_1.IterableElementBase {
261
254
  * Time Complexity: O(log n)
262
255
  * Space Complexity: O(1)
263
256
  *
264
- * Insert an element into the heap and maintain the heap properties.
265
- * @param element - The element to be inserted.
257
+ * The add function pushes an element into an array and then triggers a bubble-up operation.
258
+ * @param {E} element - The `element` parameter represents the element that you want to add to the
259
+ * data structure.
260
+ * @returns The `add` method is returning a boolean value, which is the result of calling the
261
+ * `_bubbleUp` method with the index `this.elements.length - 1` as an argument.
266
262
  */
267
263
  add(element) {
268
264
  this._elements.push(element);
269
265
  return this._bubbleUp(this.elements.length - 1);
270
266
  }
267
+ /**
268
+ * Time Complexity: O(k log n)
269
+ * Space Complexity: O(1)
270
+ *
271
+ * The `addMany` function iterates over elements and adds them to a collection, returning an array of
272
+ * boolean values indicating success or failure.
273
+ * @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `addMany` method is
274
+ * an iterable containing elements of type `E` or `R`. The method iterates over each element in the
275
+ * iterable and adds them to the data structure. If a transformation function `_toElementFn` is
276
+ * provided, it transforms the element
277
+ * @returns The `addMany` method returns an array of boolean values indicating whether each element
278
+ * in the input iterable was successfully added to the data structure.
279
+ */
280
+ addMany(elements) {
281
+ const ans = [];
282
+ for (const el of elements) {
283
+ if (this._toElementFn) {
284
+ ans.push(this.add(this._toElementFn(el)));
285
+ continue;
286
+ }
287
+ ans.push(this.add(el));
288
+ }
289
+ return ans;
290
+ }
271
291
  /**
272
292
  * Time Complexity: O(log n)
273
293
  * Space Complexity: O(1)
@@ -470,7 +490,7 @@ class Heap extends base_1.IterableElementBase {
470
490
  return filteredList;
471
491
  }
472
492
  /**
473
- * Time Complexity: O(n log n)
493
+ * Time Complexity: O(n)
474
494
  * Space Complexity: O(n)
475
495
  *
476
496
  * The `map` function creates a new heap by applying a callback function to each element of the