priority-queue-typed 1.47.9 → 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.
- package/dist/data-structures/binary-tree/avl-tree.d.ts +6 -0
- package/dist/data-structures/binary-tree/avl-tree.js +8 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +52 -0
- package/dist/data-structures/binary-tree/binary-tree.js +106 -28
- package/dist/data-structures/binary-tree/bst.d.ts +13 -0
- package/dist/data-structures/binary-tree/bst.js +41 -21
- package/dist/data-structures/binary-tree/rb-tree.d.ts +16 -0
- package/dist/data-structures/binary-tree/rb-tree.js +54 -31
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +28 -0
- package/dist/data-structures/binary-tree/tree-multimap.js +60 -21
- package/dist/data-structures/hash/hash-map.d.ts +173 -16
- package/dist/data-structures/hash/hash-map.js +373 -37
- package/dist/types/data-structures/hash/hash-map.d.ts +4 -0
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +9 -0
- package/src/data-structures/binary-tree/binary-tree.ts +109 -24
- package/src/data-structures/binary-tree/bst.ts +38 -19
- package/src/data-structures/binary-tree/rb-tree.ts +55 -31
- package/src/data-structures/binary-tree/tree-multimap.ts +60 -17
- package/src/data-structures/hash/hash-map.ts +400 -40
- package/src/types/data-structures/hash/hash-map.ts +2 -0
|
@@ -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
|
|
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
|
|
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
|
-
*
|
|
287
|
+
* LinkedHashMap. It takes three arguments:
|
|
131
288
|
*/
|
|
132
|
-
forEach(callback: (element: [K, V], index: number, hashMap:
|
|
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
|
|
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
|
|
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:
|
|
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
|
|
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
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
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:
|
|
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
|
|
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.
|