data-structure-typed 1.46.2 → 1.46.4
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/CHANGELOG.md +1 -1
- package/README.md +16 -16
- package/benchmark/report.html +1 -46
- package/benchmark/report.json +8 -389
- package/dist/cjs/data-structures/hash/hash-map.d.ts +31 -116
- package/dist/cjs/data-structures/hash/hash-map.js +127 -254
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/index.d.ts +0 -4
- package/dist/cjs/data-structures/hash/index.js +0 -4
- package/dist/cjs/data-structures/hash/index.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +6 -74
- package/dist/cjs/data-structures/queue/deque.js +20 -142
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/types/data-structures/hash/hash-map.d.ts +5 -0
- package/dist/cjs/types/data-structures/hash/index.d.ts +0 -4
- package/dist/cjs/types/data-structures/hash/index.js +0 -4
- package/dist/cjs/types/data-structures/hash/index.js.map +1 -1
- package/dist/cjs/utils/utils.d.ts +1 -1
- package/dist/cjs/utils/utils.js +3 -3
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/hash/hash-map.d.ts +31 -116
- package/dist/mjs/data-structures/hash/hash-map.js +129 -257
- package/dist/mjs/data-structures/hash/index.d.ts +0 -4
- package/dist/mjs/data-structures/hash/index.js +0 -4
- package/dist/mjs/data-structures/queue/deque.d.ts +6 -74
- package/dist/mjs/data-structures/queue/deque.js +16 -140
- package/dist/mjs/types/data-structures/hash/hash-map.d.ts +5 -0
- package/dist/mjs/types/data-structures/hash/index.d.ts +0 -4
- package/dist/mjs/types/data-structures/hash/index.js +0 -4
- package/dist/mjs/utils/utils.d.ts +1 -1
- package/dist/mjs/utils/utils.js +1 -1
- package/dist/umd/data-structure-typed.js +169 -531
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +4 -3
- package/src/data-structures/hash/hash-map.ts +154 -275
- package/src/data-structures/hash/index.ts +0 -4
- package/src/data-structures/queue/deque.ts +22 -161
- package/src/types/data-structures/hash/hash-map.ts +6 -0
- package/src/types/data-structures/hash/index.ts +0 -4
- package/src/utils/utils.ts +1 -1
- package/test/performance/data-structures/hash/hash-map.test.ts +86 -11
- package/test/performance/reportor.ts +6 -3
- package/test/unit/data-structures/hash/hash-map.test.ts +36 -5
- package/test/unit/data-structures/queue/deque.test.ts +28 -0
- package/dist/cjs/data-structures/hash/coordinate-map.d.ts +0 -44
- package/dist/cjs/data-structures/hash/coordinate-map.js +0 -63
- package/dist/cjs/data-structures/hash/coordinate-map.js.map +0 -1
- package/dist/cjs/data-structures/hash/coordinate-set.d.ts +0 -36
- package/dist/cjs/data-structures/hash/coordinate-set.js +0 -53
- package/dist/cjs/data-structures/hash/coordinate-set.js.map +0 -1
- package/dist/cjs/data-structures/hash/tree-map.d.ts +0 -2
- package/dist/cjs/data-structures/hash/tree-map.js +0 -7
- package/dist/cjs/data-structures/hash/tree-map.js.map +0 -1
- package/dist/cjs/data-structures/hash/tree-set.d.ts +0 -2
- package/dist/cjs/data-structures/hash/tree-set.js +0 -7
- package/dist/cjs/data-structures/hash/tree-set.js.map +0 -1
- package/dist/cjs/types/data-structures/hash/coordinate-map.d.ts +0 -1
- package/dist/cjs/types/data-structures/hash/coordinate-map.js +0 -3
- package/dist/cjs/types/data-structures/hash/coordinate-map.js.map +0 -1
- package/dist/cjs/types/data-structures/hash/coordinate-set.d.ts +0 -1
- package/dist/cjs/types/data-structures/hash/coordinate-set.js +0 -3
- package/dist/cjs/types/data-structures/hash/coordinate-set.js.map +0 -1
- package/dist/cjs/types/data-structures/hash/tree-map.d.ts +0 -1
- package/dist/cjs/types/data-structures/hash/tree-map.js +0 -3
- package/dist/cjs/types/data-structures/hash/tree-map.js.map +0 -1
- package/dist/cjs/types/data-structures/hash/tree-set.d.ts +0 -1
- package/dist/cjs/types/data-structures/hash/tree-set.js +0 -3
- package/dist/cjs/types/data-structures/hash/tree-set.js.map +0 -1
- package/dist/mjs/data-structures/hash/coordinate-map.d.ts +0 -44
- package/dist/mjs/data-structures/hash/coordinate-map.js +0 -58
- package/dist/mjs/data-structures/hash/coordinate-set.d.ts +0 -36
- package/dist/mjs/data-structures/hash/coordinate-set.js +0 -48
- package/dist/mjs/data-structures/hash/tree-map.d.ts +0 -2
- package/dist/mjs/data-structures/hash/tree-map.js +0 -2
- package/dist/mjs/data-structures/hash/tree-set.d.ts +0 -2
- package/dist/mjs/data-structures/hash/tree-set.js +0 -2
- package/dist/mjs/types/data-structures/hash/coordinate-map.d.ts +0 -1
- package/dist/mjs/types/data-structures/hash/coordinate-map.js +0 -1
- package/dist/mjs/types/data-structures/hash/coordinate-set.d.ts +0 -1
- package/dist/mjs/types/data-structures/hash/coordinate-set.js +0 -1
- package/dist/mjs/types/data-structures/hash/tree-map.d.ts +0 -1
- package/dist/mjs/types/data-structures/hash/tree-map.js +0 -1
- package/dist/mjs/types/data-structures/hash/tree-set.d.ts +0 -1
- package/dist/mjs/types/data-structures/hash/tree-set.js +0 -1
- package/src/data-structures/hash/coordinate-map.ts +0 -63
- package/src/data-structures/hash/coordinate-set.ts +0 -52
- package/src/data-structures/hash/tree-map.ts +0 -2
- package/src/data-structures/hash/tree-set.ts +0 -2
- package/src/types/data-structures/hash/coordinate-map.ts +0 -1
- package/src/types/data-structures/hash/coordinate-set.ts +0 -1
- package/src/types/data-structures/hash/tree-map.ts +0 -1
- package/src/types/data-structures/hash/tree-set.ts +0 -1
- package/test/performance/data-structures/hash/coordinate-map.test.ts +0 -0
- package/test/performance/data-structures/hash/coordinate-set.test.ts +0 -0
- package/test/unit/data-structures/hash/coordinate-map.test.ts +0 -74
- package/test/unit/data-structures/hash/coordinate-set.test.ts +0 -66
|
@@ -5,99 +5,23 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import { HashMapLinkedNode,
|
|
9
|
-
/**
|
|
10
|
-
* Because the implementation of HashMap relies on JavaScript's built-in objects and arrays,
|
|
11
|
-
* these underlying structures have already dealt with dynamic expansion and hash collisions.
|
|
12
|
-
* Therefore, there is no need for additional logic to handle these issues.
|
|
13
|
-
*/
|
|
14
|
-
export declare class HashMapIterator<K, V> {
|
|
15
|
-
readonly hashMap: HashMap<K, V>;
|
|
16
|
-
readonly iterateDirection: IterateDirection;
|
|
17
|
-
protected _node: HashMapLinkedNode<K, V>;
|
|
18
|
-
protected readonly _sentinel: HashMapLinkedNode<K, V>;
|
|
19
|
-
/**
|
|
20
|
-
* This is a constructor function for a linked list iterator in a HashMap data structure.
|
|
21
|
-
* @param node - The `node` parameter is a reference to a `HashMapLinkedNode` object. This object
|
|
22
|
-
* represents a node in a linked list used in a hash map data structure. It contains a key-value pair
|
|
23
|
-
* and references to the previous and next nodes in the linked list.
|
|
24
|
-
* @param sentinel - The `sentinel` parameter is a reference to a special node in a linked list. It
|
|
25
|
-
* is used to mark the beginning or end of the list and is typically used in data structures like
|
|
26
|
-
* hash maps or linked lists to simplify operations and boundary checks.
|
|
27
|
-
* @param hashMap - A HashMap object that stores key-value pairs.
|
|
28
|
-
* @param {IterateDirection} iterateDirection - The `iterateDirection` parameter is an optional
|
|
29
|
-
* parameter that specifies the direction in which the iterator should iterate over the elements of
|
|
30
|
-
* the HashMap. It can take one of the following values:
|
|
31
|
-
* @returns The constructor does not return anything. It is used to initialize the properties and
|
|
32
|
-
* methods of the object being created.
|
|
33
|
-
*/
|
|
34
|
-
constructor(node: HashMapLinkedNode<K, V>, sentinel: HashMapLinkedNode<K, V>, hashMap: HashMap<K, V>, iterateDirection?: IterateDirection);
|
|
35
|
-
/**
|
|
36
|
-
* The above function returns a Proxy object that allows access to the key and value of a node in a
|
|
37
|
-
* data structure.
|
|
38
|
-
* @returns The code is returning a Proxy object.
|
|
39
|
-
*/
|
|
40
|
-
get current(): [K, V];
|
|
41
|
-
/**
|
|
42
|
-
* The function checks if a node is accessible.
|
|
43
|
-
* @returns a boolean value indicating whether the `_node` is not equal to the `_sentinel`.
|
|
44
|
-
*/
|
|
45
|
-
isAccessible(): boolean;
|
|
46
|
-
prev(): this;
|
|
47
|
-
next(): this;
|
|
48
|
-
clone(): HashMapIterator<K, V>;
|
|
49
|
-
}
|
|
8
|
+
import { HashMapLinkedNode, HashMapOptions } from '../../types';
|
|
50
9
|
export declare class HashMap<K = any, V = any> {
|
|
51
|
-
|
|
52
|
-
protected
|
|
53
|
-
protected
|
|
54
|
-
protected
|
|
55
|
-
protected
|
|
56
|
-
protected
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* `
|
|
62
|
-
*/
|
|
63
|
-
constructor(
|
|
10
|
+
protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>>;
|
|
11
|
+
protected _objMap: WeakMap<WeakKey, HashMapLinkedNode<K, V | undefined>>;
|
|
12
|
+
protected _head: HashMapLinkedNode<K, V | undefined>;
|
|
13
|
+
protected _tail: HashMapLinkedNode<K, V | undefined>;
|
|
14
|
+
protected readonly _sentinel: HashMapLinkedNode<K, V | undefined>;
|
|
15
|
+
protected _hashFn: (key: K) => string;
|
|
16
|
+
protected _objHashFn: (key: K) => WeakKey;
|
|
17
|
+
/**
|
|
18
|
+
* The constructor initializes a HashMapLinkedNode with an optional iterable of key-value pairs.
|
|
19
|
+
* @param options - The `options` parameter is an object that contains the `elements` property. The
|
|
20
|
+
* `elements` property is an iterable that contains key-value pairs represented as arrays `[K, V]`.
|
|
21
|
+
*/
|
|
22
|
+
constructor(options?: HashMapOptions<K, V>);
|
|
64
23
|
protected _size: number;
|
|
65
24
|
get size(): number;
|
|
66
|
-
/**
|
|
67
|
-
* Time Complexity: O(1)
|
|
68
|
-
* Space Complexity: O(1)
|
|
69
|
-
*
|
|
70
|
-
* The function returns a new iterator object for a HashMap.
|
|
71
|
-
* @returns A new instance of the HashMapIterator class is being returned.
|
|
72
|
-
*/
|
|
73
|
-
get begin(): HashMapIterator<K, V>;
|
|
74
|
-
/**
|
|
75
|
-
* Time Complexity: O(1)
|
|
76
|
-
* Space Complexity: O(1)
|
|
77
|
-
*
|
|
78
|
-
* The function returns a new HashMapIterator object with the _sentinel value as both the start and
|
|
79
|
-
* end values.
|
|
80
|
-
* @returns A new instance of the HashMapIterator class is being returned.
|
|
81
|
-
*/
|
|
82
|
-
get end(): HashMapIterator<K, V>;
|
|
83
|
-
/**
|
|
84
|
-
* Time Complexity: O(1)
|
|
85
|
-
* Space Complexity: O(1)
|
|
86
|
-
*
|
|
87
|
-
* The reverseBegin function returns a new HashMapIterator object that iterates over the elements of
|
|
88
|
-
* a HashMap in reverse order.
|
|
89
|
-
* @returns A new instance of the HashMapIterator class is being returned.
|
|
90
|
-
*/
|
|
91
|
-
get reverseBegin(): HashMapIterator<K, V>;
|
|
92
|
-
/**
|
|
93
|
-
* Time Complexity: O(1)
|
|
94
|
-
* Space Complexity: O(1)
|
|
95
|
-
*
|
|
96
|
-
* The reverseEnd function returns a new HashMapIterator object that iterates over the elements of a
|
|
97
|
-
* HashMap in reverse order.
|
|
98
|
-
* @returns A new instance of the HashMapIterator class is being returned.
|
|
99
|
-
*/
|
|
100
|
-
get reverseEnd(): HashMapIterator<K, V>;
|
|
101
25
|
/**
|
|
102
26
|
* Time Complexity: O(1)
|
|
103
27
|
* Space Complexity: O(1)
|
|
@@ -116,6 +40,15 @@ export declare class HashMap<K = any, V = any> {
|
|
|
116
40
|
* data structure.
|
|
117
41
|
*/
|
|
118
42
|
get last(): [K, V] | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* The `begin()` function in TypeScript iterates over a linked list and yields key-value pairs.
|
|
45
|
+
*/
|
|
46
|
+
begin(): Generator<(K | V | undefined)[], void, unknown>;
|
|
47
|
+
/**
|
|
48
|
+
* The function `reverseBegin()` iterates over a linked list in reverse order, yielding each node's
|
|
49
|
+
* key and value.
|
|
50
|
+
*/
|
|
51
|
+
reverseBegin(): Generator<(K | V | undefined)[], void, unknown>;
|
|
119
52
|
/**
|
|
120
53
|
* Time Complexity: O(1)
|
|
121
54
|
* Space Complexity: O(1)
|
|
@@ -126,10 +59,9 @@ export declare class HashMap<K = any, V = any> {
|
|
|
126
59
|
* type, but typically it is a string or symbol.
|
|
127
60
|
* @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the
|
|
128
61
|
* value associated with the key being set in the data structure.
|
|
129
|
-
* @param {boolean} isObjectKey - A boolean flag indicating whether the key is an object key or not.
|
|
130
62
|
* @returns the size of the data structure after the key-value pair has been set.
|
|
131
63
|
*/
|
|
132
|
-
set(key: K, value?: V
|
|
64
|
+
set(key: K, value?: V): number;
|
|
133
65
|
/**
|
|
134
66
|
* Time Complexity: O(1)
|
|
135
67
|
* Space Complexity: O(1)
|
|
@@ -138,15 +70,12 @@ export declare class HashMap<K = any, V = any> {
|
|
|
138
70
|
* key directly or by using an index stored in the key object.
|
|
139
71
|
* @param {K} key - The `key` parameter is the key used to retrieve a value from the map. It can be
|
|
140
72
|
* of any type, but typically it is a string or symbol.
|
|
141
|
-
* @param {boolean} isObjectKey - The `isObjectKey` parameter is a boolean flag that indicates
|
|
142
|
-
* whether the `key` parameter is an object key or not. If `isObjectKey` is `true`, it means that
|
|
143
|
-
* `key` is an object key. If `isObjectKey` is `false`, it means that `key`
|
|
144
73
|
* @returns The value associated with the given key is being returned. If the key is an object key,
|
|
145
74
|
* the value is retrieved from the `_nodes` array using the index stored in the `OBJ_KEY_INDEX`
|
|
146
|
-
* property of the key. If the key is a string key, the value is retrieved from the `
|
|
75
|
+
* property of the key. If the key is a string key, the value is retrieved from the `_noObjMap` object
|
|
147
76
|
* using the key itself. If the key is not found, `undefined` is
|
|
148
77
|
*/
|
|
149
|
-
get(key: K
|
|
78
|
+
get(key: K): V | undefined;
|
|
150
79
|
/**
|
|
151
80
|
* Time Complexity: O(n), where n is the index.
|
|
152
81
|
* Space Complexity: O(1)
|
|
@@ -159,20 +88,6 @@ export declare class HashMap<K = any, V = any> {
|
|
|
159
88
|
* where `K` is the key and `V` is the value.
|
|
160
89
|
*/
|
|
161
90
|
getAt(index: number): [K, V];
|
|
162
|
-
/**
|
|
163
|
-
* Time Complexity: O(1)
|
|
164
|
-
* Space Complexity: O(1)
|
|
165
|
-
*
|
|
166
|
-
* The function `getIterator` returns a new instance of `HashMapIterator` based on the provided key
|
|
167
|
-
* and whether it is an object key or not.
|
|
168
|
-
* @param {K} key - The `key` parameter is the key used to retrieve the iterator from the HashMap. It
|
|
169
|
-
* can be of any type, depending on how the HashMap is implemented.
|
|
170
|
-
* @param {boolean} [isObjectKey] - The `isObjectKey` parameter is an optional boolean parameter that
|
|
171
|
-
* indicates whether the `key` parameter is an object key. If `isObjectKey` is `true`, it means that
|
|
172
|
-
* the `key` parameter is an object and needs to be handled differently. If `isObjectKey` is `false`
|
|
173
|
-
* @returns a new instance of the `HashMapIterator` class.
|
|
174
|
-
*/
|
|
175
|
-
getIterator(key: K, isObjectKey?: boolean): HashMapIterator<K, V>;
|
|
176
91
|
/**
|
|
177
92
|
* Time Complexity: O(1)
|
|
178
93
|
* Space Complexity: O(1)
|
|
@@ -180,13 +95,10 @@ export declare class HashMap<K = any, V = any> {
|
|
|
180
95
|
* The `delete` function removes a key-value pair from a map-like data structure.
|
|
181
96
|
* @param {K} key - The `key` parameter is the key that you want to delete from the data structure.
|
|
182
97
|
* It can be of any type, but typically it is a string or an object.
|
|
183
|
-
* @param {boolean} isObjectKey - The `isObjectKey` parameter is a boolean flag that indicates
|
|
184
|
-
* whether the `key` parameter is an object key or not. If `isObjectKey` is `true`, it means that the
|
|
185
|
-
* `key` parameter is an object key. If `isObjectKey` is `false`, it means that the
|
|
186
98
|
* @returns a boolean value. It returns `true` if the deletion was successful, and `false` if the key
|
|
187
99
|
* was not found.
|
|
188
100
|
*/
|
|
189
|
-
delete(key: K
|
|
101
|
+
delete(key: K): boolean;
|
|
190
102
|
/**
|
|
191
103
|
* Time Complexity: O(n), where n is the index.
|
|
192
104
|
* Space Complexity: O(1)
|
|
@@ -223,6 +135,9 @@ export declare class HashMap<K = any, V = any> {
|
|
|
223
135
|
* HashMap. It takes three arguments:
|
|
224
136
|
*/
|
|
225
137
|
forEach(callback: (element: [K, V], index: number, hashMap: HashMap<K, V>) => void): void;
|
|
138
|
+
filter(predicate: (element: [K, V], map: HashMap<K, V>) => boolean): HashMap<K, V>;
|
|
139
|
+
map<NV>(callback: (element: [K, V], map: HashMap<K, V>) => NV): HashMap<K, NV>;
|
|
140
|
+
reduce<A>(callback: (accumulator: A, element: [K, V], map: HashMap<K, V>) => A, initialValue: A): A;
|
|
226
141
|
/**
|
|
227
142
|
* Time Complexity: O(n), where n is the number of elements in the HashMap.
|
|
228
143
|
* Space Complexity: O(1)
|
|
@@ -240,5 +155,5 @@ export declare class HashMap<K = any, V = any> {
|
|
|
240
155
|
* represents a node in a linked list. It contains a key-value pair and references to the previous
|
|
241
156
|
* and next nodes in the list.
|
|
242
157
|
*/
|
|
243
|
-
protected _deleteNode(node: HashMapLinkedNode<K, V>): void;
|
|
158
|
+
protected _deleteNode(node: HashMapLinkedNode<K, V | undefined>): void;
|
|
244
159
|
}
|