stack-typed 1.48.0 → 1.48.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 (54) hide show
  1. package/dist/data-structures/base/index.d.ts +1 -0
  2. package/dist/data-structures/base/index.js +17 -0
  3. package/dist/data-structures/base/iterable-base.d.ts +232 -0
  4. package/dist/data-structures/base/iterable-base.js +312 -0
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +45 -40
  6. package/dist/data-structures/binary-tree/binary-tree.js +91 -88
  7. package/dist/data-structures/binary-tree/tree-multimap.d.ts +12 -0
  8. package/dist/data-structures/binary-tree/tree-multimap.js +16 -0
  9. package/dist/data-structures/graph/abstract-graph.d.ts +44 -6
  10. package/dist/data-structures/graph/abstract-graph.js +50 -27
  11. package/dist/data-structures/hash/hash-map.d.ts +160 -44
  12. package/dist/data-structures/hash/hash-map.js +314 -82
  13. package/dist/data-structures/heap/heap.d.ts +50 -7
  14. package/dist/data-structures/heap/heap.js +60 -30
  15. package/dist/data-structures/index.d.ts +1 -0
  16. package/dist/data-structures/index.js +1 -0
  17. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +38 -51
  18. package/dist/data-structures/linked-list/doubly-linked-list.js +46 -73
  19. package/dist/data-structures/linked-list/singly-linked-list.d.ts +32 -51
  20. package/dist/data-structures/linked-list/singly-linked-list.js +40 -73
  21. package/dist/data-structures/queue/deque.d.ts +29 -51
  22. package/dist/data-structures/queue/deque.js +36 -71
  23. package/dist/data-structures/queue/queue.d.ts +49 -48
  24. package/dist/data-structures/queue/queue.js +69 -82
  25. package/dist/data-structures/stack/stack.d.ts +43 -10
  26. package/dist/data-structures/stack/stack.js +50 -31
  27. package/dist/data-structures/trie/trie.d.ts +41 -6
  28. package/dist/data-structures/trie/trie.js +53 -32
  29. package/dist/types/data-structures/base/base.d.ts +5 -0
  30. package/dist/types/data-structures/base/base.js +2 -0
  31. package/dist/types/data-structures/base/index.d.ts +1 -0
  32. package/dist/types/data-structures/base/index.js +17 -0
  33. package/dist/types/data-structures/hash/hash-map.d.ts +4 -0
  34. package/dist/types/data-structures/index.d.ts +1 -0
  35. package/dist/types/data-structures/index.js +1 -0
  36. package/package.json +2 -2
  37. package/src/data-structures/base/index.ts +1 -0
  38. package/src/data-structures/base/iterable-base.ts +329 -0
  39. package/src/data-structures/binary-tree/binary-tree.ts +98 -93
  40. package/src/data-structures/binary-tree/tree-multimap.ts +18 -0
  41. package/src/data-structures/graph/abstract-graph.ts +55 -28
  42. package/src/data-structures/hash/hash-map.ts +334 -83
  43. package/src/data-structures/heap/heap.ts +63 -36
  44. package/src/data-structures/index.ts +1 -0
  45. package/src/data-structures/linked-list/doubly-linked-list.ts +50 -79
  46. package/src/data-structures/linked-list/singly-linked-list.ts +45 -80
  47. package/src/data-structures/queue/deque.ts +40 -82
  48. package/src/data-structures/queue/queue.ts +72 -87
  49. package/src/data-structures/stack/stack.ts +53 -34
  50. package/src/data-structures/trie/trie.ts +58 -35
  51. package/src/types/data-structures/base/base.ts +6 -0
  52. package/src/types/data-structures/base/index.ts +1 -0
  53. package/src/types/data-structures/hash/hash-map.ts +2 -0
  54. package/src/types/data-structures/index.ts +1 -0
@@ -5,8 +5,119 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { HashMapLinkedNode, HashMapOptions } from '../../types';
9
- export declare class HashMap<K = any, V = any> {
8
+ import { HashMapLinkedNode, HashMapOptions, HashMapStoreItem, PairCallback } from '../../types';
9
+ import { IterablePairBase } from "../base";
10
+ export declare class HashMap<K = any, V = any> extends IterablePairBase<K, V> {
11
+ protected _store: {
12
+ [key: string]: HashMapStoreItem<K, V>;
13
+ };
14
+ protected _objMap: Map<object, V>;
15
+ /**
16
+ * The constructor function initializes a new instance of a class with optional elements and options.
17
+ * @param elements - The `elements` parameter is an iterable containing key-value pairs `[K, V]`. It
18
+ * is optional and defaults to an empty array `[]`. This parameter is used to initialize the map with
19
+ * key-value pairs.
20
+ * @param [options] - The `options` parameter is an optional object that can contain additional
21
+ * configuration options for the constructor. In this case, it has one property:
22
+ */
23
+ constructor(elements?: Iterable<[K, V]>, options?: {
24
+ hashFn: (key: K) => string;
25
+ });
26
+ protected _size: number;
27
+ get size(): number;
28
+ isEmpty(): boolean;
29
+ clear(): void;
30
+ /**
31
+ * The `set` function adds a key-value pair to a map-like data structure, incrementing the size if
32
+ * the key is not already present.
33
+ * @param {K} key - The key parameter is the key used to identify the value in the data structure. It
34
+ * can be of any type, but if it is an object, it will be stored in a Map, otherwise it will be
35
+ * stored in a regular JavaScript object.
36
+ * @param {V} value - The value parameter represents the value that you want to associate with the
37
+ * key in the data structure.
38
+ */
39
+ set(key: K, value: V): void;
40
+ /**
41
+ * The function "setMany" sets multiple key-value pairs in a map.
42
+ * @param elements - The `elements` parameter is an iterable containing key-value pairs. Each
43
+ * key-value pair is represented as an array with two elements: the key and the value.
44
+ */
45
+ setMany(elements: Iterable<[K, V]>): void;
46
+ /**
47
+ * The `get` function retrieves a value from a map based on a given key, either from an object map or
48
+ * a string map.
49
+ * @param {K} key - The `key` parameter is the key used to retrieve a value from the map. It can be
50
+ * of any type, but it should be compatible with the key type used when the map was created.
51
+ * @returns The method `get(key: K)` returns a value of type `V` if the key exists in the `_objMap`
52
+ * or `_store`, otherwise it returns `undefined`.
53
+ */
54
+ get(key: K): V | undefined;
55
+ /**
56
+ * The `has` function checks if a given key exists in the `_objMap` or `_store` based on whether it
57
+ * is an object key or not.
58
+ * @param {K} key - The parameter "key" is of type K, which means it can be any type.
59
+ * @returns The `has` method is returning a boolean value.
60
+ */
61
+ has(key: K): boolean;
62
+ /**
63
+ * The `delete` function removes an element from a map-like data structure based on the provided key.
64
+ * @param {K} key - The `key` parameter is the key of the element that you want to delete from the
65
+ * data structure.
66
+ * @returns The `delete` method returns a boolean value. It returns `true` if the key was
67
+ * successfully deleted from the map, and `false` if the key was not found in the map.
68
+ */
69
+ delete(key: K): boolean;
70
+ /**
71
+ * Time Complexity: O(n)
72
+ * Space Complexity: O(n)
73
+ */
74
+ /**
75
+ * Time Complexity: O(n)
76
+ * Space Complexity: O(n)
77
+ *
78
+ * The `map` function in TypeScript creates a new HashMap by applying a callback function to each
79
+ * key-value pair in the original HashMap.
80
+ * @param callbackfn - The callback function that will be called for each key-value pair in the
81
+ * HashMap. It takes four parameters:
82
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
83
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
84
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
85
+ * @returns The `map` method is returning a new `HashMap` object with the transformed values based on
86
+ * the provided callback function.
87
+ */
88
+ map<U>(callbackfn: PairCallback<K, V, U>, thisArg?: any): HashMap<K, U>;
89
+ /**
90
+ * Time Complexity: O(n)
91
+ * Space Complexity: O(n)
92
+ */
93
+ /**
94
+ * Time Complexity: O(n)
95
+ * Space Complexity: O(n)
96
+ *
97
+ * The `filter` function creates a new HashMap containing key-value pairs from the original HashMap
98
+ * that satisfy a given predicate function.
99
+ * @param predicate - The predicate parameter is a function that takes four arguments: value, key,
100
+ * index, and map. It is used to determine whether an element should be included in the filtered map
101
+ * or not. The function should return a boolean value - true if the element should be included, and
102
+ * false otherwise.
103
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
104
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
105
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
106
+ * @returns The `filter` method is returning a new `HashMap` object that contains the key-value pairs
107
+ * from the original `HashMap` that pass the provided `predicate` function.
108
+ */
109
+ filter(predicate: PairCallback<K, V, boolean>, thisArg?: any): HashMap<K, V>;
110
+ print(): void;
111
+ /**
112
+ * The function returns an iterator that yields key-value pairs from both an object store and an
113
+ * object map.
114
+ */
115
+ protected _getIterator(): IterableIterator<[K, V]>;
116
+ protected _hashFn: (key: K) => string;
117
+ protected _isObjKey(key: any): key is (object | ((...args: any[]) => any));
118
+ protected _getNoObjKey(key: K): string;
119
+ }
120
+ export declare class LinkedHashMap<K = any, V = any> extends IterablePairBase<K, V> {
10
121
  protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>>;
11
122
  protected _objMap: WeakMap<object, HashMapLinkedNode<K, V | undefined>>;
12
123
  protected _head: HashMapLinkedNode<K, V | undefined>;
@@ -57,6 +168,8 @@ export declare class HashMap<K = any, V = any> {
57
168
  * @returns the size of the data structure after the key-value pair has been set.
58
169
  */
59
170
  set(key: K, value?: V): number;
171
+ has(key: K): boolean;
172
+ setMany(entries: Iterable<[K, V]>): void;
60
173
  /**
61
174
  * Time Complexity: O(1)
62
175
  * Space Complexity: O(1)
@@ -120,54 +233,57 @@ export declare class HashMap<K = any, V = any> {
120
233
  * The `clear` function clears all the elements in a data structure and resets its properties.
121
234
  */
122
235
  clear(): void;
236
+ clone(): LinkedHashMap<K, V>;
123
237
  /**
124
- * Time Complexity: O(n), where n is the number of elements in the HashMap.
125
- * Space Complexity: O(1)
238
+ * Time Complexity: O(n)
239
+ * Space Complexity: O(n)
240
+ */
241
+ /**
242
+ * Time Complexity: O(n)
243
+ * Space Complexity: O(n)
126
244
  *
127
- * The `forEach` function iterates over each element in a HashMap and executes a callback function on
128
- * each element.
129
- * @param callback - The callback parameter is a function that will be called for each element in the
130
- * HashMap. It takes three arguments:
131
- */
132
- forEach(callback: (element: [K, V], index: number, hashMap: HashMap<K, V>) => void): void;
133
- /**
134
- * The `filter` function takes a predicate function and returns a new HashMap containing only the
135
- * key-value pairs that satisfy the predicate.
136
- * @param predicate - The `predicate` parameter is a function that takes two arguments: `element` and
137
- * `map`.
138
- * @returns a new HashMap object that contains the key-value pairs from the original HashMap that
139
- * satisfy the given predicate function.
140
- */
141
- filter(predicate: (element: [K, V], index: number, map: HashMap<K, V>) => boolean): HashMap<K, V>;
142
- /**
143
- * The `map` function takes a callback function and returns a new HashMap with the values transformed
144
- * by the callback.
145
- * @param callback - The `callback` parameter is a function that takes two arguments: `element` and
146
- * `map`.
147
- * @returns a new HashMap object with the values mapped according to the provided callback function.
148
- */
149
- map<NV>(callback: (element: [K, V], index: number, map: HashMap<K, V>) => NV): HashMap<K, NV>;
150
- /**
151
- * The `reduce` function iterates over the elements of a HashMap and applies a callback function to
152
- * each element, accumulating a single value.
153
- * @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
155
- * result.
156
- * @param {A} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
157
- * is the value that will be passed as the first argument to the `callback` function when reducing
158
- * the elements of the map.
159
- * @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.
161
- */
162
- reduce<A>(callback: (accumulator: A, element: [K, V], index: number, map: HashMap<K, V>) => A, initialValue: A): A;
163
- /**
164
- * Time Complexity: O(n), where n is the number of elements in the HashMap.
245
+ * The `filter` function creates a new `LinkedHashMap` containing key-value pairs from the original
246
+ * map that satisfy a given predicate function.
247
+ * @param predicate - The `predicate` parameter is a callback function that takes four arguments:
248
+ * `value`, `key`, `index`, and `this`. It should return a boolean value indicating whether the
249
+ * current element should be included in the filtered map or not.
250
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
251
+ * specify the value of `this` within the `predicate` function. It is used when you want to bind a
252
+ * specific object as the context for the `predicate` function. If `thisArg` is not provided, `this
253
+ * @returns a new `LinkedHashMap` object that contains the key-value pairs from the original
254
+ * `LinkedHashMap` object that satisfy the given predicate function.
255
+ */
256
+ filter(predicate: PairCallback<K, V, boolean>, thisArg?: any): LinkedHashMap<K, V>;
257
+ /**
258
+ * Time Complexity: O(n)
259
+ * Space Complexity: O(n)
260
+ */
261
+ /**
262
+ * Time Complexity: O(n)
263
+ * Space Complexity: O(n)
264
+ *
265
+ * The `map` function in TypeScript creates a new `LinkedHashMap` by applying a callback function to
266
+ * each key-value pair in the original map.
267
+ * @param callback - The callback parameter is a function that will be called for each key-value pair
268
+ * in the map. It takes four arguments: the value of the current key-value pair, the key of the
269
+ * current key-value pair, the index of the current key-value pair, and the map itself. The callback
270
+ * function should
271
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
272
+ * specify the value of `this` within the callback function. If provided, the callback function will
273
+ * be called with `thisArg` as its `this` value. If not provided, `this` will refer to the current
274
+ * map
275
+ * @returns a new `LinkedHashMap` object with the values mapped according to the provided callback
276
+ * function.
277
+ */
278
+ map<NV>(callback: PairCallback<K, V, NV>, thisArg?: any): LinkedHashMap<K, NV>;
279
+ print(): void;
280
+ /**
281
+ * Time Complexity: O(n), where n is the number of elements in the LinkedHashMap.
165
282
  * Space Complexity: O(1)
166
283
  *
167
284
  * The above function is an iterator that yields key-value pairs from a linked list.
168
285
  */
169
- [Symbol.iterator](): Generator<[K, V], void, unknown>;
170
- print(): void;
286
+ protected _getIterator(): Generator<[K, V], void, unknown>;
171
287
  /**
172
288
  * Time Complexity: O(1)
173
289
  * Space Complexity: O(1)