min-heap-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.
- package/dist/data-structures/base/index.d.ts +1 -0
- package/dist/data-structures/base/index.js +17 -0
- package/dist/data-structures/base/iterable-base.d.ts +232 -0
- package/dist/data-structures/base/iterable-base.js +312 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +45 -40
- package/dist/data-structures/binary-tree/binary-tree.js +91 -88
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +12 -0
- package/dist/data-structures/binary-tree/tree-multimap.js +16 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +44 -6
- package/dist/data-structures/graph/abstract-graph.js +50 -27
- package/dist/data-structures/hash/hash-map.d.ts +160 -44
- package/dist/data-structures/hash/hash-map.js +314 -82
- package/dist/data-structures/heap/heap.d.ts +50 -7
- package/dist/data-structures/heap/heap.js +60 -30
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +38 -51
- package/dist/data-structures/linked-list/doubly-linked-list.js +46 -73
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +32 -51
- package/dist/data-structures/linked-list/singly-linked-list.js +40 -73
- package/dist/data-structures/queue/deque.d.ts +29 -51
- package/dist/data-structures/queue/deque.js +36 -71
- package/dist/data-structures/queue/queue.d.ts +49 -48
- package/dist/data-structures/queue/queue.js +69 -82
- package/dist/data-structures/stack/stack.d.ts +43 -10
- package/dist/data-structures/stack/stack.js +50 -31
- package/dist/data-structures/trie/trie.d.ts +41 -6
- package/dist/data-structures/trie/trie.js +53 -32
- package/dist/types/data-structures/base/base.d.ts +5 -0
- package/dist/types/data-structures/base/base.js +2 -0
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/index.js +17 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +4 -0
- package/dist/types/data-structures/index.d.ts +1 -0
- package/dist/types/data-structures/index.js +1 -0
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-base.ts +329 -0
- package/src/data-structures/binary-tree/binary-tree.ts +98 -93
- package/src/data-structures/binary-tree/tree-multimap.ts +18 -0
- package/src/data-structures/graph/abstract-graph.ts +55 -28
- package/src/data-structures/hash/hash-map.ts +334 -83
- package/src/data-structures/heap/heap.ts +63 -36
- package/src/data-structures/index.ts +1 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +50 -79
- package/src/data-structures/linked-list/singly-linked-list.ts +45 -80
- package/src/data-structures/queue/deque.ts +40 -82
- package/src/data-structures/queue/queue.ts +72 -87
- package/src/data-structures/stack/stack.ts +53 -34
- package/src/data-structures/trie/trie.ts +58 -35
- package/src/types/data-structures/base/base.ts +6 -0
- package/src/types/data-structures/base/index.ts +1 -0
- package/src/types/data-structures/hash/hash-map.ts +2 -0
- 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
|
-
|
|
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)
|
|
125
|
-
* Space Complexity: O(
|
|
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 `
|
|
128
|
-
*
|
|
129
|
-
* @param
|
|
130
|
-
*
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
*
|
|
135
|
-
* key-value pairs
|
|
136
|
-
*
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* @param
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
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)
|