deque-typed 1.48.0 → 1.48.1

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.
@@ -460,6 +460,44 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
460
460
  * by the return type of the `callback` function.
461
461
  */
462
462
  morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<N>): ReturnType<C>[];
463
+ /**
464
+ * Time complexity: O(n)
465
+ * Space complexity: O(n)
466
+ */
467
+ /**
468
+ * Time complexity: O(n)
469
+ * Space complexity: O(n)
470
+ *
471
+ * The function "keys" returns an array of keys from a given object.
472
+ * @returns an array of BTNKey objects.
473
+ */
474
+ keys(): BTNKey[];
475
+ /**
476
+ * Time complexity: O(n)
477
+ * Space complexity: O(n)
478
+ */
479
+ /**
480
+ * Time complexity: O(n)
481
+ * Space complexity: O(n)
482
+ *
483
+ * The function "values" returns an array of values from a map-like object.
484
+ * @returns The `values()` method is returning an array of values (`V`) from the entries in the
485
+ * object.
486
+ */
487
+ values(): (V | undefined)[];
488
+ /**
489
+ * Time complexity: O(n)
490
+ * Space complexity: O(n)
491
+ */
492
+ /**
493
+ * Time complexity: O(n)
494
+ * Space complexity: O(n)
495
+ *
496
+ * The `clone` function creates a new tree object and copies all the nodes from the original tree to
497
+ * the new tree.
498
+ * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
499
+ */
500
+ clone(): TREE;
463
501
  /**
464
502
  * Time complexity: O(n)
465
503
  * Space complexity: O(1)
@@ -1404,6 +1404,60 @@ class BinaryTree {
1404
1404
  }
1405
1405
  return ans;
1406
1406
  }
1407
+ /**
1408
+ * Time complexity: O(n)
1409
+ * Space complexity: O(n)
1410
+ */
1411
+ /**
1412
+ * Time complexity: O(n)
1413
+ * Space complexity: O(n)
1414
+ *
1415
+ * The function "keys" returns an array of keys from a given object.
1416
+ * @returns an array of BTNKey objects.
1417
+ */
1418
+ keys() {
1419
+ const keys = [];
1420
+ for (const entry of this) {
1421
+ keys.push(entry[0]);
1422
+ }
1423
+ return keys;
1424
+ }
1425
+ /**
1426
+ * Time complexity: O(n)
1427
+ * Space complexity: O(n)
1428
+ */
1429
+ /**
1430
+ * Time complexity: O(n)
1431
+ * Space complexity: O(n)
1432
+ *
1433
+ * The function "values" returns an array of values from a map-like object.
1434
+ * @returns The `values()` method is returning an array of values (`V`) from the entries in the
1435
+ * object.
1436
+ */
1437
+ values() {
1438
+ const values = [];
1439
+ for (const entry of this) {
1440
+ values.push(entry[1]);
1441
+ }
1442
+ return values;
1443
+ }
1444
+ /**
1445
+ * Time complexity: O(n)
1446
+ * Space complexity: O(n)
1447
+ */
1448
+ /**
1449
+ * Time complexity: O(n)
1450
+ * Space complexity: O(n)
1451
+ *
1452
+ * The `clone` function creates a new tree object and copies all the nodes from the original tree to
1453
+ * the new tree.
1454
+ * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
1455
+ */
1456
+ clone() {
1457
+ const cloned = this.createTree();
1458
+ this.bfs(node => cloned.add([node.key, node.value]));
1459
+ return cloned;
1460
+ }
1407
1461
  /**
1408
1462
  * Time complexity: O(n)
1409
1463
  * Space complexity: O(1)
@@ -137,6 +137,18 @@ export declare class TreeMultimap<V = any, N extends TreeMultimapNode<V, N> = Tr
137
137
  * The clear() function clears the contents of a data structure and sets the count to zero.
138
138
  */
139
139
  clear(): void;
140
+ /**
141
+ * Time complexity: O(n)
142
+ * Space complexity: O(n)
143
+ */
144
+ /**
145
+ * Time complexity: O(n)
146
+ * Space complexity: O(n)
147
+ *
148
+ * The `clone` function creates a deep copy of a tree object.
149
+ * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
150
+ */
151
+ clone(): TREE;
140
152
  /**
141
153
  * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
142
154
  * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
@@ -280,6 +280,22 @@ class TreeMultimap extends avl_tree_1.AVLTree {
280
280
  super.clear();
281
281
  this._count = 0;
282
282
  }
283
+ /**
284
+ * Time complexity: O(n)
285
+ * Space complexity: O(n)
286
+ */
287
+ /**
288
+ * Time complexity: O(n)
289
+ * Space complexity: O(n)
290
+ *
291
+ * The `clone` function creates a deep copy of a tree object.
292
+ * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
293
+ */
294
+ clone() {
295
+ const cloned = this.createTree();
296
+ this.bfs(node => cloned.add([node.key, node.value], node.count));
297
+ return cloned;
298
+ }
283
299
  /**
284
300
  * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
285
301
  * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
@@ -5,8 +5,160 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { HashMapLinkedNode, HashMapOptions } from '../../types';
8
+ import { HashMapLinkedNode, HashMapOptions, HashMapStoreItem } from '../../types';
9
9
  export declare class HashMap<K = any, V = any> {
10
+ protected _store: {
11
+ [key: string]: HashMapStoreItem<K, V>;
12
+ };
13
+ protected _objMap: Map<object, V>;
14
+ /**
15
+ * The constructor function initializes a new instance of a class with optional elements and options.
16
+ * @param elements - The `elements` parameter is an iterable containing key-value pairs `[K, V]`. It
17
+ * is optional and defaults to an empty array `[]`. This parameter is used to initialize the map with
18
+ * key-value pairs.
19
+ * @param [options] - The `options` parameter is an optional object that can contain additional
20
+ * configuration options for the constructor. In this case, it has one property:
21
+ */
22
+ constructor(elements?: Iterable<[K, V]>, options?: {
23
+ hashFn: (key: K) => string;
24
+ });
25
+ protected _size: number;
26
+ get size(): number;
27
+ isEmpty(): boolean;
28
+ clear(): void;
29
+ /**
30
+ * The `set` function adds a key-value pair to a map-like data structure, incrementing the size if
31
+ * the key is not already present.
32
+ * @param {K} key - The key parameter is the key used to identify the value in the data structure. It
33
+ * can be of any type, but if it is an object, it will be stored in a Map, otherwise it will be
34
+ * stored in a regular JavaScript object.
35
+ * @param {V} value - The value parameter represents the value that you want to associate with the
36
+ * key in the data structure.
37
+ */
38
+ set(key: K, value: V): void;
39
+ /**
40
+ * The function "setMany" sets multiple key-value pairs in a map.
41
+ * @param elements - The `elements` parameter is an iterable containing key-value pairs. Each
42
+ * key-value pair is represented as an array with two elements: the key and the value.
43
+ */
44
+ setMany(elements: Iterable<[K, V]>): void;
45
+ /**
46
+ * The `get` function retrieves a value from a map based on a given key, either from an object map or
47
+ * a string map.
48
+ * @param {K} key - The `key` parameter is the key used to retrieve a value from the map. It can be
49
+ * of any type, but it should be compatible with the key type used when the map was created.
50
+ * @returns The method `get(key: K)` returns a value of type `V` if the key exists in the `_objMap`
51
+ * or `_store`, otherwise it returns `undefined`.
52
+ */
53
+ get(key: K): V | undefined;
54
+ /**
55
+ * The `has` function checks if a given key exists in the `_objMap` or `_store` based on whether it
56
+ * is an object key or not.
57
+ * @param {K} key - The parameter "key" is of type K, which means it can be any type.
58
+ * @returns The `has` method is returning a boolean value.
59
+ */
60
+ has(key: K): boolean;
61
+ /**
62
+ * The `delete` function removes an element from a map-like data structure based on the provided key.
63
+ * @param {K} key - The `key` parameter is the key of the element that you want to delete from the
64
+ * data structure.
65
+ * @returns The `delete` method returns a boolean value. It returns `true` if the key was
66
+ * successfully deleted from the map, and `false` if the key was not found in the map.
67
+ */
68
+ delete(key: K): boolean;
69
+ /**
70
+ * The function returns an iterator that yields key-value pairs from both an object store and an
71
+ * object map.
72
+ */
73
+ [Symbol.iterator](): IterableIterator<[K, V]>;
74
+ /**
75
+ * The function returns an iterator that yields key-value pairs from the object.
76
+ */
77
+ entries(): IterableIterator<[K, V]>;
78
+ /**
79
+ * The function `keys()` returns an iterator that yields all the keys of the object.
80
+ */
81
+ keys(): IterableIterator<K>;
82
+ values(): IterableIterator<V>;
83
+ /**
84
+ * The `every` function checks if every element in a HashMap satisfies a given predicate function.
85
+ * @param predicate - The predicate parameter is a function that takes four arguments: value, key,
86
+ * index, and map. It is used to test each element in the map against a condition. If the predicate
87
+ * function returns false for any element, the every() method will return false. If the predicate
88
+ * function returns true for all
89
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
90
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
91
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
92
+ * @returns The method is returning a boolean value. It returns true if the predicate function
93
+ * returns true for every element in the map, and false otherwise.
94
+ */
95
+ every(predicate: (value: V, key: K, index: number, map: HashMap<K, V>) => boolean, thisArg?: any): boolean;
96
+ /**
97
+ * The "some" function checks if at least one element in a HashMap satisfies a given predicate.
98
+ * @param predicate - The `predicate` parameter is a function that takes four arguments: `value`,
99
+ * `key`, `index`, and `map`. It is used to determine whether a specific condition is met for a given
100
+ * key-value pair in the `HashMap`.
101
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
102
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
103
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
104
+ * @returns a boolean value. It returns true if the predicate function returns true for any element
105
+ * in the map, and false otherwise.
106
+ */
107
+ some(predicate: (value: V, key: K, index: number, map: HashMap<K, V>) => boolean, thisArg?: any): boolean;
108
+ /**
109
+ * The `forEach` function iterates over the elements of a HashMap and applies a callback function to
110
+ * each element.
111
+ * @param callbackfn - A function that will be called for each key-value pair in the HashMap. It
112
+ * takes four parameters:
113
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
114
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
115
+ * be passed as the `this` value inside the `callbackfn` function. If `thisArg
116
+ */
117
+ forEach(callbackfn: (value: V, key: K, index: number, map: HashMap<K, V>) => void, thisArg?: any): void;
118
+ /**
119
+ * The `map` function in TypeScript creates a new HashMap by applying a callback function to each
120
+ * key-value pair in the original HashMap.
121
+ * @param callbackfn - The callback function that will be called for each key-value pair in the
122
+ * HashMap. It takes four parameters:
123
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
124
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
125
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
126
+ * @returns The `map` method is returning a new `HashMap` object with the transformed values based on
127
+ * the provided callback function.
128
+ */
129
+ map<U>(callbackfn: (value: V, key: K, index: number, map: HashMap<K, V>) => U, thisArg?: any): HashMap<K, U>;
130
+ /**
131
+ * The `filter` function creates a new HashMap containing key-value pairs from the original HashMap
132
+ * that satisfy a given predicate function.
133
+ * @param predicate - The predicate parameter is a function that takes four arguments: value, key,
134
+ * index, and map. It is used to determine whether an element should be included in the filtered map
135
+ * or not. The function should return a boolean value - true if the element should be included, and
136
+ * false otherwise.
137
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
138
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
139
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
140
+ * @returns The `filter` method is returning a new `HashMap` object that contains the key-value pairs
141
+ * from the original `HashMap` that pass the provided `predicate` function.
142
+ */
143
+ filter(predicate: (value: V, key: K, index: number, map: HashMap<K, V>) => boolean, thisArg?: any): HashMap<K, V>;
144
+ /**
145
+ * The `reduce` function iterates over the elements of a HashMap and applies a callback function to
146
+ * each element, accumulating a single value.
147
+ * @param callbackfn - The callback function that will be called for each element in the HashMap. It
148
+ * takes five parameters:
149
+ * @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
150
+ * is the value that will be used as the first argument of the callback function when reducing the
151
+ * elements of the map.
152
+ * @returns The `reduce` method is returning the final value of the accumulator after iterating over
153
+ * all the elements in the `HashMap`.
154
+ */
155
+ reduce<U>(callbackfn: (accumulator: U, currentValue: V, currentKey: K, index: number, map: HashMap<K, V>) => U, initialValue: U): U;
156
+ print(): void;
157
+ protected _hashFn: (key: K) => string;
158
+ protected _isObjKey(key: any): key is (object | ((...args: any[]) => any));
159
+ protected _getNoObjKey(key: K): string;
160
+ }
161
+ export declare class LinkedHashMap<K = any, V = any> {
10
162
  protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>>;
11
163
  protected _objMap: WeakMap<object, HashMapLinkedNode<K, V | undefined>>;
12
164
  protected _head: HashMapLinkedNode<K, V | undefined>;
@@ -57,6 +209,10 @@ export declare class HashMap<K = any, V = any> {
57
209
  * @returns the size of the data structure after the key-value pair has been set.
58
210
  */
59
211
  set(key: K, value?: V): number;
212
+ has(key: K): boolean;
213
+ setMany(entries: Iterable<[K, V]>): void;
214
+ keys(): K[];
215
+ values(): V[];
60
216
  /**
61
217
  * Time Complexity: O(1)
62
218
  * Space Complexity: O(1)
@@ -120,48 +276,49 @@ export declare class HashMap<K = any, V = any> {
120
276
  * The `clear` function clears all the elements in a data structure and resets its properties.
121
277
  */
122
278
  clear(): void;
279
+ clone(): LinkedHashMap<K, V>;
123
280
  /**
124
- * Time Complexity: O(n), where n is the number of elements in the HashMap.
281
+ * Time Complexity: O(n), where n is the number of elements in the LinkedHashMap.
125
282
  * Space Complexity: O(1)
126
283
  *
127
- * The `forEach` function iterates over each element in a HashMap and executes a callback function on
284
+ * The `forEach` function iterates over each element in a LinkedHashMap and executes a callback function on
128
285
  * each element.
129
286
  * @param callback - The callback parameter is a function that will be called for each element in the
130
- * HashMap. It takes three arguments:
287
+ * LinkedHashMap. It takes three arguments:
131
288
  */
132
- forEach(callback: (element: [K, V], index: number, hashMap: HashMap<K, V>) => void): void;
289
+ forEach(callback: (element: [K, V], index: number, hashMap: LinkedHashMap<K, V>) => void): void;
133
290
  /**
134
- * The `filter` function takes a predicate function and returns a new HashMap containing only the
291
+ * The `filter` function takes a predicate function and returns a new LinkedHashMap containing only the
135
292
  * key-value pairs that satisfy the predicate.
136
293
  * @param predicate - The `predicate` parameter is a function that takes two arguments: `element` and
137
294
  * `map`.
138
- * @returns a new HashMap object that contains the key-value pairs from the original HashMap that
295
+ * @returns a new LinkedHashMap object that contains the key-value pairs from the original LinkedHashMap that
139
296
  * satisfy the given predicate function.
140
297
  */
141
- filter(predicate: (element: [K, V], index: number, map: HashMap<K, V>) => boolean): HashMap<K, V>;
298
+ filter(predicate: (element: [K, V], index: number, map: LinkedHashMap<K, V>) => boolean): LinkedHashMap<K, V>;
142
299
  /**
143
- * The `map` function takes a callback function and returns a new HashMap with the values transformed
300
+ * The `map` function takes a callback function and returns a new LinkedHashMap with the values transformed
144
301
  * by the callback.
145
302
  * @param callback - The `callback` parameter is a function that takes two arguments: `element` and
146
303
  * `map`.
147
- * @returns a new HashMap object with the values mapped according to the provided callback function.
304
+ * @returns a new LinkedHashMap object with the values mapped according to the provided callback function.
148
305
  */
149
- map<NV>(callback: (element: [K, V], index: number, map: HashMap<K, V>) => NV): HashMap<K, NV>;
306
+ map<NV>(callback: (element: [K, V], index: number, map: LinkedHashMap<K, V>) => NV): LinkedHashMap<K, NV>;
150
307
  /**
151
- * The `reduce` function iterates over the elements of a HashMap and applies a callback function to
308
+ * The `reduce` function iterates over the elements of a LinkedHashMap and applies a callback function to
152
309
  * each element, accumulating a single value.
153
310
  * @param callback - The callback parameter is a function that takes three arguments: accumulator,
154
- * element, and map. It is called for each element in the HashMap and is used to accumulate a single
311
+ * element, and map. It is called for each element in the LinkedHashMap and is used to accumulate a single
155
312
  * result.
156
313
  * @param {A} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
157
314
  * is the value that will be passed as the first argument to the `callback` function when reducing
158
315
  * the elements of the map.
159
316
  * @returns The `reduce` function is returning the final value of the accumulator after iterating
160
- * over all the elements in the HashMap and applying the callback function to each element.
317
+ * over all the elements in the LinkedHashMap and applying the callback function to each element.
161
318
  */
162
- reduce<A>(callback: (accumulator: A, element: [K, V], index: number, map: HashMap<K, V>) => A, initialValue: A): A;
319
+ reduce<A>(callback: (accumulator: A, element: [K, V], index: number, map: LinkedHashMap<K, V>) => A, initialValue: A): A;
163
320
  /**
164
- * Time Complexity: O(n), where n is the number of elements in the HashMap.
321
+ * Time Complexity: O(n), where n is the number of elements in the LinkedHashMap.
165
322
  * Space Complexity: O(1)
166
323
  *
167
324
  * The above function is an iterator that yields key-value pairs from a linked list.