min-heap-typed 1.50.1 → 1.50.2

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 (67) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +114 -9
  2. package/dist/data-structures/base/iterable-base.js +143 -7
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +43 -46
  4. package/dist/data-structures/binary-tree/avl-tree.js +68 -71
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +244 -199
  6. package/dist/data-structures/binary-tree/binary-tree.js +484 -376
  7. package/dist/data-structures/binary-tree/bst.d.ts +54 -74
  8. package/dist/data-structures/binary-tree/bst.js +30 -71
  9. package/dist/data-structures/binary-tree/rb-tree.d.ts +78 -60
  10. package/dist/data-structures/binary-tree/rb-tree.js +84 -89
  11. package/dist/data-structures/binary-tree/tree-multimap.d.ts +37 -56
  12. package/dist/data-structures/binary-tree/tree-multimap.js +64 -85
  13. package/dist/data-structures/graph/abstract-graph.d.ts +1 -0
  14. package/dist/data-structures/graph/abstract-graph.js +3 -0
  15. package/dist/data-structures/graph/directed-graph.d.ts +14 -0
  16. package/dist/data-structures/graph/directed-graph.js +26 -0
  17. package/dist/data-structures/graph/map-graph.d.ts +8 -0
  18. package/dist/data-structures/graph/map-graph.js +14 -0
  19. package/dist/data-structures/graph/undirected-graph.d.ts +16 -0
  20. package/dist/data-structures/graph/undirected-graph.js +25 -0
  21. package/dist/data-structures/hash/hash-map.d.ts +121 -15
  22. package/dist/data-structures/hash/hash-map.js +160 -25
  23. package/dist/data-structures/heap/heap.d.ts +66 -6
  24. package/dist/data-structures/heap/heap.js +66 -6
  25. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
  26. package/dist/data-structures/linked-list/doubly-linked-list.js +70 -64
  27. package/dist/data-structures/linked-list/singly-linked-list.d.ts +128 -103
  28. package/dist/data-structures/linked-list/singly-linked-list.js +130 -112
  29. package/dist/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  30. package/dist/data-structures/linked-list/skip-linked-list.js +63 -36
  31. package/dist/data-structures/matrix/matrix.d.ts +35 -4
  32. package/dist/data-structures/matrix/matrix.js +50 -11
  33. package/dist/data-structures/queue/deque.d.ts +49 -19
  34. package/dist/data-structures/queue/deque.js +101 -47
  35. package/dist/data-structures/queue/queue.d.ts +39 -5
  36. package/dist/data-structures/queue/queue.js +47 -5
  37. package/dist/data-structures/stack/stack.d.ts +16 -0
  38. package/dist/data-structures/stack/stack.js +22 -0
  39. package/dist/data-structures/trie/trie.d.ts +38 -1
  40. package/dist/data-structures/trie/trie.js +41 -0
  41. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  42. package/dist/types/data-structures/hash/hash-map.d.ts +4 -3
  43. package/dist/types/utils/utils.d.ts +1 -0
  44. package/package.json +2 -2
  45. package/src/data-structures/base/iterable-base.ts +172 -19
  46. package/src/data-structures/binary-tree/avl-tree.ts +97 -97
  47. package/src/data-structures/binary-tree/binary-tree.ts +674 -671
  48. package/src/data-structures/binary-tree/bst.ts +89 -131
  49. package/src/data-structures/binary-tree/rb-tree.ts +127 -155
  50. package/src/data-structures/binary-tree/tree-multimap.ts +96 -112
  51. package/src/data-structures/graph/abstract-graph.ts +4 -0
  52. package/src/data-structures/graph/directed-graph.ts +30 -0
  53. package/src/data-structures/graph/map-graph.ts +15 -0
  54. package/src/data-structures/graph/undirected-graph.ts +28 -0
  55. package/src/data-structures/hash/hash-map.ts +175 -34
  56. package/src/data-structures/heap/heap.ts +66 -6
  57. package/src/data-structures/linked-list/doubly-linked-list.ts +72 -66
  58. package/src/data-structures/linked-list/singly-linked-list.ts +132 -114
  59. package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
  60. package/src/data-structures/matrix/matrix.ts +52 -12
  61. package/src/data-structures/queue/deque.ts +108 -49
  62. package/src/data-structures/queue/queue.ts +51 -5
  63. package/src/data-structures/stack/stack.ts +24 -0
  64. package/src/data-structures/trie/trie.ts +45 -1
  65. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  66. package/src/types/data-structures/hash/hash-map.ts +4 -3
  67. package/src/types/utils/utils.ts +2 -0
@@ -25,13 +25,42 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
25
25
  * `T`. It is an optional parameter and its default value is an empty array `[]`.
26
26
  * @param [options] - The `options` parameter is an optional object that can contain two properties:
27
27
  */
28
- constructor(rawCollection?: Iterable<R>, options?: HashMapOptions<K, V, R>);
28
+ constructor(rawCollection?: Iterable<R | [K, V]>, options?: HashMapOptions<K, V, R>);
29
29
  protected _toEntryFn: (rawElement: R) => [K, V];
30
+ /**
31
+ * The function returns the value of the _toEntryFn property.
32
+ * @returns The function being returned is `this._toEntryFn`.
33
+ */
30
34
  get toEntryFn(): (rawElement: R) => [K, V];
35
+ /**
36
+ * The hasFn function is a function that takes in an item and returns a boolean
37
+ * indicating whether the item is contained within the hash table.
38
+ *
39
+ * @return The hash function
40
+ */
41
+ get hasFn(): (key: K) => string;
31
42
  protected _size: number;
43
+ /**
44
+ * The function returns the size of an object.
45
+ * @returns The size of the object, which is a number.
46
+ */
32
47
  get size(): number;
48
+ /**
49
+ * The function checks if a given element is an array with exactly two elements.
50
+ * @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
51
+ * data type.
52
+ * @returns a boolean value.
53
+ */
33
54
  isEntry(rawElement: any): rawElement is [K, V];
55
+ /**
56
+ * The function checks if the size of an object is equal to zero and returns a boolean value.
57
+ * @returns A boolean value indicating whether the size of the object is 0 or not.
58
+ */
34
59
  isEmpty(): boolean;
60
+ /**
61
+ * The clear() function resets the state of an object by clearing its internal store, object map, and
62
+ * size.
63
+ */
35
64
  clear(): void;
36
65
  /**
37
66
  * The `set` function adds a key-value pair to a map-like data structure, incrementing the size if
@@ -50,7 +79,7 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
50
79
  * `T`.
51
80
  * @returns The `setMany` function is returning an array of booleans.
52
81
  */
53
- setMany(rawCollection: Iterable<R>): boolean[];
82
+ setMany(rawCollection: Iterable<R | [K, V]>): boolean[];
54
83
  /**
55
84
  * The `get` function retrieves a value from a map based on a given key, either from an object map or
56
85
  * a string map.
@@ -75,6 +104,14 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
75
104
  * successfully deleted from the map, and `false` if the key was not found in the map.
76
105
  */
77
106
  delete(key: K): boolean;
107
+ /**
108
+ * The clone function creates a new HashMap with the same key-value pairs as
109
+ * this one. The clone function is useful for creating a copy of an existing
110
+ * HashMap, and then modifying that copy without affecting the original.
111
+ *
112
+ * @return A new hashmap with the same values as this one
113
+ */
114
+ clone(): HashMap<K, V, R>;
78
115
  /**
79
116
  * Time Complexity: O(n)
80
117
  * Space Complexity: O(n)
@@ -115,6 +152,14 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
115
152
  * from the original `HashMap` that pass the provided `predicate` function.
116
153
  */
117
154
  filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): HashMap<K, V>;
155
+ /**
156
+ * The put function sets a value in a data structure using a specified key.
157
+ * @param {K} key - The key parameter is of type K, which represents the type of the key being passed
158
+ * to the function.
159
+ * @param {V} value - The value parameter represents the value that you want to associate with the
160
+ * specified key in the data structure.
161
+ * @returns The method is returning a boolean value.
162
+ */
118
163
  put(key: K, value: V): boolean;
119
164
  /**
120
165
  * The function returns an iterator that yields key-value pairs from both an object store and an
@@ -130,14 +175,33 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
130
175
  * 2. Based on Hash Table and Linked List: It combines the structures of a hash table and a linked list, using the hash table to ensure fast access, while maintaining the order of entries through the linked list.
131
176
  * 3. Time Complexity: Similar to HashMap, LinkedHashMap offers constant-time performance for get and put operations in most cases.
132
177
  */
133
- export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K, V> {
178
+ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> {
134
179
  protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>>;
135
180
  protected _objMap: WeakMap<object, HashMapLinkedNode<K, V | undefined>>;
136
181
  protected _head: HashMapLinkedNode<K, V | undefined>;
137
182
  protected _tail: HashMapLinkedNode<K, V | undefined>;
138
183
  protected readonly _sentinel: HashMapLinkedNode<K, V | undefined>;
139
- constructor(entries?: Iterable<[K, V]>, options?: LinkedHashMapOptions<K>);
184
+ /**
185
+ * The constructor initializes a LinkedHashMap object with an optional raw collection and options.
186
+ * @param rawCollection - The `rawCollection` parameter is an iterable collection of elements. It is
187
+ * used to initialize the HashMapLinked instance with key-value pairs. Each element in the
188
+ * `rawCollection` is converted to a key-value pair using the `toEntryFn` function (if provided) and
189
+ * then added to the HashMap
190
+ * @param [options] - The `options` parameter is an optional object that can contain the following
191
+ * properties:
192
+ */
193
+ constructor(rawCollection?: Iterable<R>, options?: LinkedHashMapOptions<K, V, R>);
194
+ protected _toEntryFn: (rawElement: R) => [K, V];
195
+ /**
196
+ * The function returns the value of the _toEntryFn property.
197
+ * @returns The function being returned is `this._toEntryFn`.
198
+ */
199
+ get toEntryFn(): (rawElement: R) => [K, V];
140
200
  protected _size: number;
201
+ /**
202
+ * The function returns the size of an object.
203
+ * @returns The size of the object.
204
+ */
141
205
  get size(): number;
142
206
  /**
143
207
  * Time Complexity: O(1)
@@ -179,8 +243,22 @@ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K
179
243
  * @returns the size of the data structure after the key-value pair has been set.
180
244
  */
181
245
  set(key: K, value?: V): boolean;
246
+ /**
247
+ * The function `setMany` takes an iterable collection, converts each element into a key-value pair
248
+ * using a provided function, and sets each key-value pair in the current object, returning an array
249
+ * of booleans indicating the success of each set operation.
250
+ * @param rawCollection - The rawCollection parameter is an iterable collection of elements of type
251
+ * R.
252
+ * @returns The `setMany` function returns an array of booleans.
253
+ */
254
+ setMany(rawCollection: Iterable<R>): boolean[];
255
+ /**
256
+ * The function checks if a given key exists in a map, using different logic depending on whether the
257
+ * key is a weak key or not.
258
+ * @param {K} key - The `key` parameter is the key that is being checked for existence in the map.
259
+ * @returns The method `has` is returning a boolean value.
260
+ */
182
261
  has(key: K): boolean;
183
- setMany(entries: Iterable<[K, V]>): boolean[];
184
262
  /**
185
263
  * Time Complexity: O(1)
186
264
  * Space Complexity: O(1)
@@ -199,14 +277,14 @@ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K
199
277
  * Time Complexity: O(n), where n is the index.
200
278
  * Space Complexity: O(1)
201
279
  *
202
- * The function `getAt` retrieves the key-value pair at a specified index in a linked list.
280
+ * The function `at` retrieves the key-value pair at a specified index in a linked list.
203
281
  * @param {number} index - The index parameter is a number that represents the position of the
204
282
  * element we want to retrieve from the data structure.
205
- * @returns The method `getAt(index: number)` is returning an array containing the key-value pair at
283
+ * @returns The method `at(index: number)` is returning an array containing the key-value pair at
206
284
  * the specified index in the data structure. The key-value pair is represented as a tuple `[K, V]`,
207
285
  * where `K` is the key and `V` is the value.
208
286
  */
209
- getAt(index: number): V | undefined;
287
+ at(index: number): V | undefined;
210
288
  /**
211
289
  * Time Complexity: O(1)
212
290
  * Space Complexity: O(1)
@@ -219,7 +297,7 @@ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K
219
297
  */
220
298
  delete(key: K): boolean;
221
299
  /**
222
- * Time Complexity: O(n), where n is the index.
300
+ * Time Complexity: O(n)
223
301
  * Space Complexity: O(1)
224
302
  *
225
303
  * The `deleteAt` function deletes a node at a specified index in a linked list.
@@ -237,6 +315,13 @@ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K
237
315
  * not.
238
316
  */
239
317
  isEmpty(): boolean;
318
+ /**
319
+ * The function checks if a given element is an array with exactly two elements.
320
+ * @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
321
+ * data type.
322
+ * @returns a boolean value.
323
+ */
324
+ isEntry(rawElement: any): rawElement is [K, V];
240
325
  /**
241
326
  * Time Complexity: O(1)
242
327
  * Space Complexity: O(1)
@@ -244,6 +329,19 @@ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K
244
329
  * The `clear` function clears all the entries in a data structure and resets its properties.
245
330
  */
246
331
  clear(): void;
332
+ /**
333
+ * Time Complexity: O(n)
334
+ * Space Complexity: O(n)
335
+ */
336
+ /**
337
+ * Time Complexity: O(n)
338
+ * Space Complexity: O(n)
339
+ *
340
+ * The `clone` function creates a new instance of a `LinkedHashMap` with the same key-value pairs as
341
+ * the original.
342
+ * @returns The `clone()` method is returning a new instance of `LinkedHashMap<K, V>` that is a clone
343
+ * of the original `LinkedHashMap` object.
344
+ */
247
345
  clone(): LinkedHashMap<K, V>;
248
346
  /**
249
347
  * Time Complexity: O(n)
@@ -280,19 +378,27 @@ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K
280
378
  */
281
379
  map<NV>(callback: EntryCallback<K, V, NV>, thisArg?: any): LinkedHashMap<K, NV>;
282
380
  /**
283
- * Time Complexity: O(n)
284
- * Space Complexity: O(n)
381
+ * Time Complexity: O(1)
382
+ * Space Complexity: O(1)
285
383
  */
286
- put(key: K, value: V): boolean;
287
384
  /**
288
- * Time Complexity: O(n)
289
- * Space Complexity: O(n)
385
+ * Time Complexity: O(1)
386
+ * Space Complexity: O(1)
387
+ *
388
+ * The put function sets a value in a data structure using a specified key.
389
+ * @param {K} key - The key parameter is of type K, which represents the type of the key being passed
390
+ * to the function.
391
+ * @param {V} value - The value parameter represents the value that you want to associate with the
392
+ * specified key in the data structure.
393
+ * @returns The method is returning a boolean value.
290
394
  */
395
+ put(key: K, value: V): boolean;
291
396
  protected _hashFn: (key: K) => string;
292
397
  protected _objHashFn: (key: K) => object;
293
398
  /**
294
- * Time Complexity: O(n), where n is the number of entries in the LinkedHashMap.
399
+ * Time Complexity: O(n)
295
400
  * Space Complexity: O(1)
401
+ * where n is the number of entries in the LinkedHashMap.
296
402
  *
297
403
  * The above function is an iterator that yields key-value pairs from a linked list.
298
404
  */
@@ -45,18 +45,49 @@ class HashMap extends base_1.IterableEntryBase {
45
45
  this.setMany(rawCollection);
46
46
  }
47
47
  }
48
+ /**
49
+ * The function returns the value of the _toEntryFn property.
50
+ * @returns The function being returned is `this._toEntryFn`.
51
+ */
48
52
  get toEntryFn() {
49
53
  return this._toEntryFn;
50
54
  }
55
+ /**
56
+ * The hasFn function is a function that takes in an item and returns a boolean
57
+ * indicating whether the item is contained within the hash table.
58
+ *
59
+ * @return The hash function
60
+ */
61
+ get hasFn() {
62
+ return this._hashFn;
63
+ }
64
+ /**
65
+ * The function returns the size of an object.
66
+ * @returns The size of the object, which is a number.
67
+ */
51
68
  get size() {
52
69
  return this._size;
53
70
  }
71
+ /**
72
+ * The function checks if a given element is an array with exactly two elements.
73
+ * @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
74
+ * data type.
75
+ * @returns a boolean value.
76
+ */
54
77
  isEntry(rawElement) {
55
78
  return Array.isArray(rawElement) && rawElement.length === 2;
56
79
  }
80
+ /**
81
+ * The function checks if the size of an object is equal to zero and returns a boolean value.
82
+ * @returns A boolean value indicating whether the size of the object is 0 or not.
83
+ */
57
84
  isEmpty() {
58
85
  return this.size === 0;
59
86
  }
87
+ /**
88
+ * The clear() function resets the state of an object by clearing its internal store, object map, and
89
+ * size.
90
+ */
60
91
  clear() {
61
92
  this._store = {};
62
93
  this._objMap.clear();
@@ -97,7 +128,16 @@ class HashMap extends base_1.IterableEntryBase {
97
128
  setMany(rawCollection) {
98
129
  const results = [];
99
130
  for (const rawEle of rawCollection) {
100
- const [key, value] = this.toEntryFn(rawEle);
131
+ let key, value;
132
+ if (this.isEntry(rawEle)) {
133
+ key = rawEle[0];
134
+ value = rawEle[1];
135
+ }
136
+ else {
137
+ const item = this.toEntryFn(rawEle);
138
+ key = item[0];
139
+ value = item[1];
140
+ }
101
141
  results.push(this.set(key, value));
102
142
  }
103
143
  return results;
@@ -159,6 +199,16 @@ class HashMap extends base_1.IterableEntryBase {
159
199
  return false;
160
200
  }
161
201
  }
202
+ /**
203
+ * The clone function creates a new HashMap with the same key-value pairs as
204
+ * this one. The clone function is useful for creating a copy of an existing
205
+ * HashMap, and then modifying that copy without affecting the original.
206
+ *
207
+ * @return A new hashmap with the same values as this one
208
+ */
209
+ clone() {
210
+ return new HashMap(this, { hashFn: this._hashFn, toEntryFn: this.toEntryFn });
211
+ }
162
212
  /**
163
213
  * Time Complexity: O(n)
164
214
  * Space Complexity: O(n)
@@ -215,6 +265,14 @@ class HashMap extends base_1.IterableEntryBase {
215
265
  }
216
266
  return filteredMap;
217
267
  }
268
+ /**
269
+ * The put function sets a value in a data structure using a specified key.
270
+ * @param {K} key - The key parameter is of type K, which represents the type of the key being passed
271
+ * to the function.
272
+ * @param {V} value - The value parameter represents the value that you want to associate with the
273
+ * specified key in the data structure.
274
+ * @returns The method is returning a boolean value.
275
+ */
218
276
  put(key, value) {
219
277
  return this.set(key, value);
220
278
  }
@@ -259,32 +317,61 @@ exports.HashMap = HashMap;
259
317
  * 3. Time Complexity: Similar to HashMap, LinkedHashMap offers constant-time performance for get and put operations in most cases.
260
318
  */
261
319
  class LinkedHashMap extends base_1.IterableEntryBase {
262
- constructor(entries, options) {
320
+ /**
321
+ * The constructor initializes a LinkedHashMap object with an optional raw collection and options.
322
+ * @param rawCollection - The `rawCollection` parameter is an iterable collection of elements. It is
323
+ * used to initialize the HashMapLinked instance with key-value pairs. Each element in the
324
+ * `rawCollection` is converted to a key-value pair using the `toEntryFn` function (if provided) and
325
+ * then added to the HashMap
326
+ * @param [options] - The `options` parameter is an optional object that can contain the following
327
+ * properties:
328
+ */
329
+ constructor(rawCollection = [], options) {
263
330
  super();
264
331
  this._noObjMap = {};
265
332
  this._objMap = new WeakMap();
333
+ this._toEntryFn = (rawElement) => {
334
+ if (this.isEntry(rawElement)) {
335
+ // TODO, For performance optimization, it may be necessary to only inspect the first element traversed.
336
+ return rawElement;
337
+ }
338
+ else {
339
+ throw new Error("If the provided rawCollection does not adhere to the [key, value] type format, the toEntryFn in the constructor's options parameter needs to specified.");
340
+ }
341
+ };
266
342
  this._size = 0;
267
- /**
268
- * Time Complexity: O(n)
269
- * Space Complexity: O(n)
270
- */
271
343
  this._hashFn = (key) => String(key);
272
344
  this._objHashFn = (key) => key;
273
345
  this._sentinel = {};
274
346
  this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
275
347
  if (options) {
276
- const { hashFn, objHashFn } = options;
348
+ const { hashFn, objHashFn, toEntryFn } = options;
277
349
  if (hashFn)
278
350
  this._hashFn = hashFn;
279
351
  if (objHashFn)
280
352
  this._objHashFn = objHashFn;
353
+ if (toEntryFn) {
354
+ this._toEntryFn = toEntryFn;
355
+ }
281
356
  }
282
- if (entries) {
283
- for (const el of entries) {
284
- this.set(el[0], el[1]);
357
+ if (rawCollection) {
358
+ for (const el of rawCollection) {
359
+ const [key, value] = this.toEntryFn(el);
360
+ this.set(key, value);
285
361
  }
286
362
  }
287
363
  }
364
+ /**
365
+ * The function returns the value of the _toEntryFn property.
366
+ * @returns The function being returned is `this._toEntryFn`.
367
+ */
368
+ get toEntryFn() {
369
+ return this._toEntryFn;
370
+ }
371
+ /**
372
+ * The function returns the size of an object.
373
+ * @returns The size of the object.
374
+ */
288
375
  get size() {
289
376
  return this._size;
290
377
  }
@@ -390,6 +477,28 @@ class LinkedHashMap extends base_1.IterableEntryBase {
390
477
  }
391
478
  return true;
392
479
  }
480
+ /**
481
+ * The function `setMany` takes an iterable collection, converts each element into a key-value pair
482
+ * using a provided function, and sets each key-value pair in the current object, returning an array
483
+ * of booleans indicating the success of each set operation.
484
+ * @param rawCollection - The rawCollection parameter is an iterable collection of elements of type
485
+ * R.
486
+ * @returns The `setMany` function returns an array of booleans.
487
+ */
488
+ setMany(rawCollection) {
489
+ const results = [];
490
+ for (const rawEle of rawCollection) {
491
+ const [key, value] = this.toEntryFn(rawEle);
492
+ results.push(this.set(key, value));
493
+ }
494
+ return results;
495
+ }
496
+ /**
497
+ * The function checks if a given key exists in a map, using different logic depending on whether the
498
+ * key is a weak key or not.
499
+ * @param {K} key - The `key` parameter is the key that is being checked for existence in the map.
500
+ * @returns The method `has` is returning a boolean value.
501
+ */
393
502
  has(key) {
394
503
  if ((0, utils_1.isWeakKey)(key)) {
395
504
  const hash = this._objHashFn(key);
@@ -400,14 +509,6 @@ class LinkedHashMap extends base_1.IterableEntryBase {
400
509
  return hash in this._noObjMap;
401
510
  }
402
511
  }
403
- setMany(entries) {
404
- const results = [];
405
- for (const entry of entries) {
406
- const [key, value] = entry;
407
- results.push(this.set(key, value));
408
- }
409
- return results;
410
- }
411
512
  /**
412
513
  * Time Complexity: O(1)
413
514
  * Space Complexity: O(1)
@@ -437,14 +538,14 @@ class LinkedHashMap extends base_1.IterableEntryBase {
437
538
  * Time Complexity: O(n), where n is the index.
438
539
  * Space Complexity: O(1)
439
540
  *
440
- * The function `getAt` retrieves the key-value pair at a specified index in a linked list.
541
+ * The function `at` retrieves the key-value pair at a specified index in a linked list.
441
542
  * @param {number} index - The index parameter is a number that represents the position of the
442
543
  * element we want to retrieve from the data structure.
443
- * @returns The method `getAt(index: number)` is returning an array containing the key-value pair at
544
+ * @returns The method `at(index: number)` is returning an array containing the key-value pair at
444
545
  * the specified index in the data structure. The key-value pair is represented as a tuple `[K, V]`,
445
546
  * where `K` is the key and `V` is the value.
446
547
  */
447
- getAt(index) {
548
+ at(index) {
448
549
  (0, utils_1.rangeCheck)(index, 0, this._size - 1);
449
550
  let node = this._head;
450
551
  while (index--) {
@@ -489,7 +590,7 @@ class LinkedHashMap extends base_1.IterableEntryBase {
489
590
  return true;
490
591
  }
491
592
  /**
492
- * Time Complexity: O(n), where n is the index.
593
+ * Time Complexity: O(n)
493
594
  * Space Complexity: O(1)
494
595
  *
495
596
  * The `deleteAt` function deletes a node at a specified index in a linked list.
@@ -516,6 +617,15 @@ class LinkedHashMap extends base_1.IterableEntryBase {
516
617
  isEmpty() {
517
618
  return this._size === 0;
518
619
  }
620
+ /**
621
+ * The function checks if a given element is an array with exactly two elements.
622
+ * @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
623
+ * data type.
624
+ * @returns a boolean value.
625
+ */
626
+ isEntry(rawElement) {
627
+ return Array.isArray(rawElement) && rawElement.length === 2;
628
+ }
519
629
  /**
520
630
  * Time Complexity: O(1)
521
631
  * Space Complexity: O(1)
@@ -527,6 +637,19 @@ class LinkedHashMap extends base_1.IterableEntryBase {
527
637
  this._size = 0;
528
638
  this._head = this._tail = this._sentinel.prev = this._sentinel.next = this._sentinel;
529
639
  }
640
+ /**
641
+ * Time Complexity: O(n)
642
+ * Space Complexity: O(n)
643
+ */
644
+ /**
645
+ * Time Complexity: O(n)
646
+ * Space Complexity: O(n)
647
+ *
648
+ * The `clone` function creates a new instance of a `LinkedHashMap` with the same key-value pairs as
649
+ * the original.
650
+ * @returns The `clone()` method is returning a new instance of `LinkedHashMap<K, V>` that is a clone
651
+ * of the original `LinkedHashMap` object.
652
+ */
530
653
  clone() {
531
654
  const cloned = new LinkedHashMap([], { hashFn: this._hashFn, objHashFn: this._objHashFn });
532
655
  for (const entry of this) {
@@ -589,15 +712,27 @@ class LinkedHashMap extends base_1.IterableEntryBase {
589
712
  return mappedMap;
590
713
  }
591
714
  /**
592
- * Time Complexity: O(n)
593
- * Space Complexity: O(n)
715
+ * Time Complexity: O(1)
716
+ * Space Complexity: O(1)
717
+ */
718
+ /**
719
+ * Time Complexity: O(1)
720
+ * Space Complexity: O(1)
721
+ *
722
+ * The put function sets a value in a data structure using a specified key.
723
+ * @param {K} key - The key parameter is of type K, which represents the type of the key being passed
724
+ * to the function.
725
+ * @param {V} value - The value parameter represents the value that you want to associate with the
726
+ * specified key in the data structure.
727
+ * @returns The method is returning a boolean value.
594
728
  */
595
729
  put(key, value) {
596
730
  return this.set(key, value);
597
731
  }
598
732
  /**
599
- * Time Complexity: O(n), where n is the number of entries in the LinkedHashMap.
733
+ * Time Complexity: O(n)
600
734
  * Space Complexity: O(1)
735
+ * where n is the number of entries in the LinkedHashMap.
601
736
  *
602
737
  * The above function is an iterator that yields key-value pairs from a linked list.
603
738
  */
@@ -19,10 +19,28 @@ import { IterableElementBase } from '../base';
19
19
  * 8. Graph Algorithms: Such as Dijkstra's shortest path algorithm and Prim's minimum spanning tree algorithm, which use heaps to improve performance.
20
20
  */
21
21
  export declare class Heap<E = any> extends IterableElementBase<E> {
22
+ /**
23
+ * The constructor initializes a heap data structure with optional elements and options.
24
+ * @param elements - The `elements` parameter is an iterable object that contains the initial
25
+ * elements to be added to the heap. It is an optional parameter and if not provided, the heap will
26
+ * be initialized as empty.
27
+ * @param [options] - The `options` parameter is an optional object that can contain additional
28
+ * configuration options for the heap. In this case, it is used to specify a custom comparator
29
+ * function for comparing elements in the heap. The comparator function is used to determine the
30
+ * order of elements in the heap.
31
+ */
22
32
  constructor(elements?: Iterable<E>, options?: HeapOptions<E>);
23
33
  protected _comparator: (a: E, b: E) => number;
34
+ /**
35
+ * The function returns the value of the _comparator property.
36
+ * @returns The `_comparator` property is being returned.
37
+ */
24
38
  get comparator(): (a: E, b: E) => number;
25
39
  protected _elements: E[];
40
+ /**
41
+ * The function returns an array of elements.
42
+ * @returns The elements array is being returned.
43
+ */
26
44
  get elements(): E[];
27
45
  /**
28
46
  * Get the size (number of elements) of the heap.
@@ -43,11 +61,12 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
43
61
  comparator: Comparator<E>;
44
62
  }): Heap<E>;
45
63
  /**
46
- * Time Complexity: O(log n), where n is the number of elements in the heap.
64
+ * Time Complexity: O(log n)
47
65
  * Space Complexity: O(1)
66
+ * where n is the number of elements in the heap.
48
67
  */
49
68
  /**
50
- * Time Complexity: O(log n), where n is the number of elements in the heap.
69
+ * Time Complexity: O(log n)
51
70
  * Space Complexity: O(1)
52
71
  *
53
72
  * Insert an element into the heap and maintain the heap properties.
@@ -55,11 +74,12 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
55
74
  */
56
75
  add(element: E): boolean;
57
76
  /**
58
- * Time Complexity: O(log n), where n is the number of elements in the heap.
77
+ * Time Complexity: O(log n)
59
78
  * Space Complexity: O(1)
79
+ * where n is the number of elements in the heap.
60
80
  */
61
81
  /**
62
- * Time Complexity: O(log n), where n is the number of elements in the heap.
82
+ * Time Complexity: O(log n)
63
83
  * Space Complexity: O(1)
64
84
  *
65
85
  * Remove and return the top element (smallest or largest element) from the heap.
@@ -67,6 +87,9 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
67
87
  */
68
88
  poll(): E | undefined;
69
89
  /**
90
+ * Time Complexity: O(1)
91
+ * Space Complexity: O(1)
92
+ *
70
93
  * Peek at the top element of the heap without removing it.
71
94
  * @returns The top element or undefined if the heap is empty.
72
95
  */
@@ -227,6 +250,9 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
227
250
  * original Heap.
228
251
  */
229
252
  map<T>(callback: ElementCallback<E, T>, comparator: Comparator<T>, thisArg?: any): Heap<T>;
253
+ /**
254
+ * The function `_getIterator` returns an iterable iterator for the elements in the class.
255
+ */
230
256
  protected _getIterator(): IterableIterator<E>;
231
257
  /**
232
258
  * Time Complexity: O(n)
@@ -258,17 +284,51 @@ export declare class FibonacciHeapNode<E> {
258
284
  child?: FibonacciHeapNode<E>;
259
285
  parent?: FibonacciHeapNode<E>;
260
286
  marked: boolean;
287
+ /**
288
+ * The constructor function initializes an object with an element and a degree, and sets the marked
289
+ * property to false.
290
+ * @param {E} element - The "element" parameter represents the value or data that will be stored in
291
+ * the node of a data structure. It can be any type of data, such as a number, string, object, or
292
+ * even another data structure.
293
+ * @param [degree=0] - The degree parameter represents the degree of the element in a data structure
294
+ * called a Fibonacci heap. The degree of a node is the number of children it has. By default, the
295
+ * degree is set to 0 when a new node is created.
296
+ */
261
297
  constructor(element: E, degree?: number);
262
298
  }
263
299
  export declare class FibonacciHeap<E> {
300
+ /**
301
+ * The constructor function initializes a FibonacciHeap object with an optional comparator function.
302
+ * @param [comparator] - The `comparator` parameter is an optional argument that represents a
303
+ * function used to compare elements in the FibonacciHeap. If a comparator function is provided, it
304
+ * will be used to determine the order of elements in the heap. If no comparator function is
305
+ * provided, a default comparator function will be used.
306
+ */
264
307
  constructor(comparator?: Comparator<E>);
265
308
  protected _root?: FibonacciHeapNode<E>;
309
+ /**
310
+ * The function returns the root node of a Fibonacci heap.
311
+ * @returns The method is returning either a FibonacciHeapNode object or undefined.
312
+ */
266
313
  get root(): FibonacciHeapNode<E> | undefined;
267
314
  protected _size: number;
315
+ /**
316
+ * The function returns the size of an object.
317
+ * @returns The size of the object, which is a number.
318
+ */
268
319
  get size(): number;
269
320
  protected _min?: FibonacciHeapNode<E>;
321
+ /**
322
+ * The function returns the minimum node in a Fibonacci heap.
323
+ * @returns The method is returning the minimum node of the Fibonacci heap, which is of type
324
+ * `FibonacciHeapNode<E>`. If there is no minimum node, it will return `undefined`.
325
+ */
270
326
  get min(): FibonacciHeapNode<E> | undefined;
271
327
  protected _comparator: Comparator<E>;
328
+ /**
329
+ * The function returns the comparator used for comparing elements.
330
+ * @returns The `_comparator` property of the object.
331
+ */
272
332
  get comparator(): Comparator<E>;
273
333
  /**
274
334
  * Get the size (number of elements) of the heap.
@@ -425,11 +485,11 @@ export declare class FibonacciHeap<E> {
425
485
  */
426
486
  protected _link(y: FibonacciHeapNode<E>, x: FibonacciHeapNode<E>): void;
427
487
  /**
428
- * Time Complexity: O(n log n), where n is the number of elements in the heap.
488
+ * Time Complexity: O(n log n)
429
489
  * Space Complexity: O(n)
430
490
  */
431
491
  /**
432
- * Time Complexity: O(n log n), where n is the number of elements in the heap.
492
+ * Time Complexity: O(n log n)
433
493
  * Space Complexity: O(n)
434
494
  *
435
495
  * Remove and return the top element (smallest or largest element) from the heap.