data-structure-typed 1.45.3 → 1.46.0
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 +91 -40
- package/benchmark/report.html +17 -17
- package/benchmark/report.json +160 -142
- package/dist/cjs/data-structures/hash/hash-map.d.ts +6 -5
- package/dist/cjs/data-structures/hash/hash-map.js +9 -6
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +59 -47
- package/dist/cjs/data-structures/heap/heap.js +133 -123
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +131 -164
- package/dist/cjs/data-structures/queue/deque.js +543 -211
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/types/data-structures/hash/hash-map.d.ts +0 -9
- package/dist/cjs/types/helpers.d.ts +11 -0
- package/dist/cjs/utils/utils.d.ts +1 -0
- package/dist/cjs/utils/utils.js +3 -1
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/hash/hash-map.d.ts +6 -5
- package/dist/mjs/data-structures/hash/hash-map.js +9 -6
- package/dist/mjs/data-structures/heap/heap.d.ts +59 -47
- package/dist/mjs/data-structures/heap/heap.js +133 -123
- package/dist/mjs/data-structures/queue/deque.d.ts +131 -164
- package/dist/mjs/data-structures/queue/deque.js +544 -201
- package/dist/mjs/types/data-structures/hash/hash-map.d.ts +0 -9
- package/dist/mjs/types/helpers.d.ts +11 -0
- package/dist/mjs/utils/utils.d.ts +1 -0
- package/dist/mjs/utils/utils.js +1 -0
- package/dist/umd/data-structure-typed.js +684 -328
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/hash/hash-map.ts +11 -7
- package/src/data-structures/heap/heap.ts +132 -128
- package/src/data-structures/queue/deque.ts +605 -226
- package/src/types/data-structures/hash/hash-map.ts +0 -11
- package/src/types/helpers.ts +15 -0
- package/src/utils/utils.ts +2 -0
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +21 -0
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +7 -7
- package/test/performance/data-structures/queue/deque.test.ts +24 -13
- package/test/unit/data-structures/hash/hash-map.test.ts +4 -4
- package/test/unit/data-structures/heap/heap.test.ts +2 -1
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +3 -3
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +3 -3
- package/test/unit/data-structures/queue/deque.test.ts +252 -240
- /package/test/performance/data-structures/{comparation.test.ts → comparison.test.ts} +0 -0
package/benchmark/report.json
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"comparison": {
|
|
3
3
|
"benchmarks": [
|
|
4
4
|
{
|
|
5
5
|
"test name": "SRC 10,000 add",
|
|
6
|
-
"time taken (ms)": "0.
|
|
7
|
-
"executions per sec": "
|
|
8
|
-
"sample deviation": "
|
|
6
|
+
"time taken (ms)": "0.57",
|
|
7
|
+
"executions per sec": "1745.23",
|
|
8
|
+
"sample deviation": "4.83e-6"
|
|
9
9
|
},
|
|
10
10
|
{
|
|
11
11
|
"test name": "CJS 10,000 add",
|
|
12
|
-
"time taken (ms)": "0.
|
|
13
|
-
"executions per sec": "
|
|
14
|
-
"sample deviation": "
|
|
12
|
+
"time taken (ms)": "0.57",
|
|
13
|
+
"executions per sec": "1752.47",
|
|
14
|
+
"sample deviation": "4.64e-6"
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
"test name": "MJS 10,000 add",
|
|
18
18
|
"time taken (ms)": "0.59",
|
|
19
|
-
"executions per sec": "
|
|
20
|
-
"sample deviation": "
|
|
19
|
+
"executions per sec": "1687.89",
|
|
20
|
+
"sample deviation": "1.40e-4"
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
23
|
"test name": "SRC PQ 10,000 add & pop",
|
|
24
|
-
"time taken (ms)": "
|
|
25
|
-
"executions per sec": "
|
|
26
|
-
"sample deviation": "
|
|
24
|
+
"time taken (ms)": "3.41",
|
|
25
|
+
"executions per sec": "293.00",
|
|
26
|
+
"sample deviation": "2.65e-5"
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
29
|
"test name": "CJS PQ 10,000 add & pop",
|
|
30
|
-
"time taken (ms)": "4.
|
|
31
|
-
"executions per sec": "
|
|
32
|
-
"sample deviation": "
|
|
30
|
+
"time taken (ms)": "4.92",
|
|
31
|
+
"executions per sec": "203.31",
|
|
32
|
+
"sample deviation": "3.60e-5"
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
35
|
"test name": "MJS PQ 10,000 add & pop",
|
|
36
|
-
"time taken (ms)": "4.
|
|
37
|
-
"executions per sec": "
|
|
38
|
-
"sample deviation": "4.
|
|
36
|
+
"time taken (ms)": "4.88",
|
|
37
|
+
"executions per sec": "204.72",
|
|
38
|
+
"sample deviation": "4.35e-5"
|
|
39
39
|
}
|
|
40
40
|
],
|
|
41
|
-
"testName": "
|
|
41
|
+
"testName": "comparison"
|
|
42
42
|
},
|
|
43
43
|
"avl-tree": {
|
|
44
44
|
"benchmarks": [
|
|
45
45
|
{
|
|
46
46
|
"test name": "10,000 add randomly",
|
|
47
|
-
"time taken (ms)": "
|
|
48
|
-
"executions per sec": "
|
|
49
|
-
"sample deviation": "
|
|
47
|
+
"time taken (ms)": "31.02",
|
|
48
|
+
"executions per sec": "32.24",
|
|
49
|
+
"sample deviation": "2.83e-4"
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
"test name": "10,000 add & delete randomly",
|
|
53
|
-
"time taken (ms)": "
|
|
54
|
-
"executions per sec": "
|
|
53
|
+
"time taken (ms)": "71.45",
|
|
54
|
+
"executions per sec": "14.00",
|
|
55
55
|
"sample deviation": "0.00"
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
58
|
"test name": "10,000 addMany",
|
|
59
|
-
"time taken (ms)": "
|
|
60
|
-
"executions per sec": "
|
|
61
|
-
"sample deviation": "
|
|
59
|
+
"time taken (ms)": "40.21",
|
|
60
|
+
"executions per sec": "24.87",
|
|
61
|
+
"sample deviation": "4.47e-4"
|
|
62
62
|
},
|
|
63
63
|
{
|
|
64
64
|
"test name": "10,000 get",
|
|
65
|
-
"time taken (ms)": "
|
|
66
|
-
"executions per sec": "
|
|
67
|
-
"sample deviation": "
|
|
65
|
+
"time taken (ms)": "28.34",
|
|
66
|
+
"executions per sec": "35.29",
|
|
67
|
+
"sample deviation": "5.15e-4"
|
|
68
68
|
}
|
|
69
69
|
],
|
|
70
70
|
"testName": "avl-tree"
|
|
@@ -73,45 +73,45 @@
|
|
|
73
73
|
"benchmarks": [
|
|
74
74
|
{
|
|
75
75
|
"test name": "1,000 add randomly",
|
|
76
|
-
"time taken (ms)": "13.
|
|
77
|
-
"executions per sec": "
|
|
78
|
-
"sample deviation": "
|
|
76
|
+
"time taken (ms)": "13.04",
|
|
77
|
+
"executions per sec": "76.71",
|
|
78
|
+
"sample deviation": "1.56e-4"
|
|
79
79
|
},
|
|
80
80
|
{
|
|
81
81
|
"test name": "1,000 add & delete randomly",
|
|
82
|
-
"time taken (ms)": "
|
|
83
|
-
"executions per sec": "
|
|
84
|
-
"sample deviation": "
|
|
82
|
+
"time taken (ms)": "15.79",
|
|
83
|
+
"executions per sec": "63.33",
|
|
84
|
+
"sample deviation": "1.40e-4"
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
87
|
"test name": "1,000 addMany",
|
|
88
|
-
"time taken (ms)": "
|
|
89
|
-
"executions per sec": "
|
|
90
|
-
"sample deviation": "
|
|
88
|
+
"time taken (ms)": "10.25",
|
|
89
|
+
"executions per sec": "97.60",
|
|
90
|
+
"sample deviation": "1.08e-4"
|
|
91
91
|
},
|
|
92
92
|
{
|
|
93
93
|
"test name": "1,000 get",
|
|
94
|
-
"time taken (ms)": "
|
|
95
|
-
"executions per sec": "
|
|
96
|
-
"sample deviation": "
|
|
94
|
+
"time taken (ms)": "18.31",
|
|
95
|
+
"executions per sec": "54.60",
|
|
96
|
+
"sample deviation": "1.50e-4"
|
|
97
97
|
},
|
|
98
98
|
{
|
|
99
99
|
"test name": "1,000 dfs",
|
|
100
|
-
"time taken (ms)": "
|
|
101
|
-
"executions per sec": "6.
|
|
102
|
-
"sample deviation": "
|
|
100
|
+
"time taken (ms)": "155.22",
|
|
101
|
+
"executions per sec": "6.44",
|
|
102
|
+
"sample deviation": "8.11e-4"
|
|
103
103
|
},
|
|
104
104
|
{
|
|
105
105
|
"test name": "1,000 bfs",
|
|
106
|
-
"time taken (ms)": "56.
|
|
107
|
-
"executions per sec": "17.
|
|
108
|
-
"sample deviation": "
|
|
106
|
+
"time taken (ms)": "56.66",
|
|
107
|
+
"executions per sec": "17.65",
|
|
108
|
+
"sample deviation": "6.70e-4"
|
|
109
109
|
},
|
|
110
110
|
{
|
|
111
111
|
"test name": "1,000 morris",
|
|
112
|
-
"time taken (ms)": "
|
|
113
|
-
"executions per sec": "
|
|
114
|
-
"sample deviation": "
|
|
112
|
+
"time taken (ms)": "254.79",
|
|
113
|
+
"executions per sec": "3.92",
|
|
114
|
+
"sample deviation": "5.27e-4"
|
|
115
115
|
}
|
|
116
116
|
],
|
|
117
117
|
"testName": "binary-tree"
|
|
@@ -120,27 +120,27 @@
|
|
|
120
120
|
"benchmarks": [
|
|
121
121
|
{
|
|
122
122
|
"test name": "10,000 add randomly",
|
|
123
|
-
"time taken (ms)": "28.
|
|
124
|
-
"executions per sec": "35.
|
|
125
|
-
"sample deviation": "
|
|
123
|
+
"time taken (ms)": "28.23",
|
|
124
|
+
"executions per sec": "35.42",
|
|
125
|
+
"sample deviation": "3.20e-4"
|
|
126
126
|
},
|
|
127
127
|
{
|
|
128
128
|
"test name": "10,000 add & delete randomly",
|
|
129
|
-
"time taken (ms)": "
|
|
130
|
-
"executions per sec": "14.
|
|
131
|
-
"sample deviation": "
|
|
129
|
+
"time taken (ms)": "68.35",
|
|
130
|
+
"executions per sec": "14.63",
|
|
131
|
+
"sample deviation": "8.46e-4"
|
|
132
132
|
},
|
|
133
133
|
{
|
|
134
134
|
"test name": "10,000 addMany",
|
|
135
|
-
"time taken (ms)": "
|
|
136
|
-
"executions per sec": "34.
|
|
135
|
+
"time taken (ms)": "28.94",
|
|
136
|
+
"executions per sec": "34.56",
|
|
137
137
|
"sample deviation": "0.00"
|
|
138
138
|
},
|
|
139
139
|
{
|
|
140
140
|
"test name": "10,000 get",
|
|
141
|
-
"time taken (ms)": "
|
|
142
|
-
"executions per sec": "
|
|
143
|
-
"sample deviation": "
|
|
141
|
+
"time taken (ms)": "28.97",
|
|
142
|
+
"executions per sec": "34.51",
|
|
143
|
+
"sample deviation": "4.57e-4"
|
|
144
144
|
}
|
|
145
145
|
],
|
|
146
146
|
"testName": "bst"
|
|
@@ -149,21 +149,21 @@
|
|
|
149
149
|
"benchmarks": [
|
|
150
150
|
{
|
|
151
151
|
"test name": "100,000 add",
|
|
152
|
-
"time taken (ms)": "
|
|
153
|
-
"executions per sec": "
|
|
154
|
-
"sample deviation": "0.
|
|
152
|
+
"time taken (ms)": "89.12",
|
|
153
|
+
"executions per sec": "11.22",
|
|
154
|
+
"sample deviation": "0.00"
|
|
155
155
|
},
|
|
156
156
|
{
|
|
157
157
|
"test name": "100,000 add & delete randomly",
|
|
158
|
-
"time taken (ms)": "
|
|
159
|
-
"executions per sec": "4.
|
|
160
|
-
"sample deviation": "0.
|
|
158
|
+
"time taken (ms)": "219.00",
|
|
159
|
+
"executions per sec": "4.57",
|
|
160
|
+
"sample deviation": "0.00"
|
|
161
161
|
},
|
|
162
162
|
{
|
|
163
163
|
"test name": "100,000 getNode",
|
|
164
|
-
"time taken (ms)": "
|
|
165
|
-
"executions per sec": "
|
|
166
|
-
"sample deviation": "
|
|
164
|
+
"time taken (ms)": "105.74",
|
|
165
|
+
"executions per sec": "9.46",
|
|
166
|
+
"sample deviation": "6.09e-4"
|
|
167
167
|
}
|
|
168
168
|
],
|
|
169
169
|
"testName": "rb-tree"
|
|
@@ -172,44 +172,44 @@
|
|
|
172
172
|
"benchmarks": [
|
|
173
173
|
{
|
|
174
174
|
"test name": "1,000 addVertex",
|
|
175
|
-
"time taken (ms)": "0.
|
|
176
|
-
"executions per sec": "
|
|
177
|
-
"sample deviation": "
|
|
175
|
+
"time taken (ms)": "0.10",
|
|
176
|
+
"executions per sec": "9902.14",
|
|
177
|
+
"sample deviation": "9.12e-7"
|
|
178
178
|
},
|
|
179
179
|
{
|
|
180
180
|
"test name": "1,000 addEdge",
|
|
181
|
-
"time taken (ms)": "6.
|
|
182
|
-
"executions per sec": "
|
|
183
|
-
"sample deviation": "1.
|
|
181
|
+
"time taken (ms)": "6.11",
|
|
182
|
+
"executions per sec": "163.67",
|
|
183
|
+
"sample deviation": "1.29e-4"
|
|
184
184
|
},
|
|
185
185
|
{
|
|
186
186
|
"test name": "1,000 getVertex",
|
|
187
187
|
"time taken (ms)": "0.05",
|
|
188
|
-
"executions per sec": "2.
|
|
189
|
-
"sample deviation": "
|
|
188
|
+
"executions per sec": "2.16e+4",
|
|
189
|
+
"sample deviation": "3.51e-7"
|
|
190
190
|
},
|
|
191
191
|
{
|
|
192
192
|
"test name": "1,000 getEdge",
|
|
193
|
-
"time taken (ms)": "
|
|
194
|
-
"executions per sec": "
|
|
195
|
-
"sample deviation": "0.
|
|
193
|
+
"time taken (ms)": "23.63",
|
|
194
|
+
"executions per sec": "42.33",
|
|
195
|
+
"sample deviation": "0.00"
|
|
196
196
|
},
|
|
197
197
|
{
|
|
198
198
|
"test name": "tarjan",
|
|
199
|
-
"time taken (ms)": "
|
|
200
|
-
"executions per sec": "4.
|
|
201
|
-
"sample deviation": "0.
|
|
199
|
+
"time taken (ms)": "222.85",
|
|
200
|
+
"executions per sec": "4.49",
|
|
201
|
+
"sample deviation": "0.01"
|
|
202
202
|
},
|
|
203
203
|
{
|
|
204
204
|
"test name": "tarjan all",
|
|
205
|
-
"time taken (ms)": "
|
|
206
|
-
"executions per sec": "4.
|
|
205
|
+
"time taken (ms)": "223.79",
|
|
206
|
+
"executions per sec": "4.47",
|
|
207
207
|
"sample deviation": "0.00"
|
|
208
208
|
},
|
|
209
209
|
{
|
|
210
210
|
"test name": "topologicalSort",
|
|
211
|
-
"time taken (ms)": "
|
|
212
|
-
"executions per sec": "5.
|
|
211
|
+
"time taken (ms)": "181.77",
|
|
212
|
+
"executions per sec": "5.50",
|
|
213
213
|
"sample deviation": "0.00"
|
|
214
214
|
}
|
|
215
215
|
],
|
|
@@ -220,14 +220,14 @@
|
|
|
220
220
|
{
|
|
221
221
|
"test name": "10,000 set",
|
|
222
222
|
"time taken (ms)": "1.00",
|
|
223
|
-
"executions per sec": "1001.
|
|
224
|
-
"sample deviation": "
|
|
223
|
+
"executions per sec": "1001.93",
|
|
224
|
+
"sample deviation": "2.06e-5"
|
|
225
225
|
},
|
|
226
226
|
{
|
|
227
227
|
"test name": "10,000 set & get",
|
|
228
|
-
"time taken (ms)": "1.
|
|
229
|
-
"executions per sec": "
|
|
230
|
-
"sample deviation": "
|
|
228
|
+
"time taken (ms)": "1.51",
|
|
229
|
+
"executions per sec": "661.53",
|
|
230
|
+
"sample deviation": "2.65e-5"
|
|
231
231
|
}
|
|
232
232
|
],
|
|
233
233
|
"testName": "hash-map"
|
|
@@ -236,38 +236,44 @@
|
|
|
236
236
|
"benchmarks": [
|
|
237
237
|
{
|
|
238
238
|
"test name": "10,000 add & pop",
|
|
239
|
-
"time taken (ms)": "
|
|
240
|
-
"executions per sec": "
|
|
241
|
-
"sample deviation": "5.
|
|
239
|
+
"time taken (ms)": "5.82",
|
|
240
|
+
"executions per sec": "171.79",
|
|
241
|
+
"sample deviation": "5.13e-5"
|
|
242
242
|
},
|
|
243
243
|
{
|
|
244
244
|
"test name": "10,000 fib add & pop",
|
|
245
|
-
"time taken (ms)": "
|
|
246
|
-
"executions per sec": "2.
|
|
247
|
-
"sample deviation": "0.
|
|
245
|
+
"time taken (ms)": "359.24",
|
|
246
|
+
"executions per sec": "2.78",
|
|
247
|
+
"sample deviation": "0.00"
|
|
248
248
|
}
|
|
249
249
|
],
|
|
250
250
|
"testName": "heap"
|
|
251
251
|
},
|
|
252
252
|
"doubly-linked-list": {
|
|
253
253
|
"benchmarks": [
|
|
254
|
+
{
|
|
255
|
+
"test name": "1,000,000 push",
|
|
256
|
+
"time taken (ms)": "214.50",
|
|
257
|
+
"executions per sec": "4.66",
|
|
258
|
+
"sample deviation": "0.05"
|
|
259
|
+
},
|
|
254
260
|
{
|
|
255
261
|
"test name": "1,000,000 unshift",
|
|
256
|
-
"time taken (ms)": "
|
|
257
|
-
"executions per sec": "4.
|
|
258
|
-
"sample deviation": "0.
|
|
262
|
+
"time taken (ms)": "205.89",
|
|
263
|
+
"executions per sec": "4.86",
|
|
264
|
+
"sample deviation": "0.05"
|
|
259
265
|
},
|
|
260
266
|
{
|
|
261
267
|
"test name": "1,000,000 unshift & shift",
|
|
262
|
-
"time taken (ms)": "
|
|
263
|
-
"executions per sec": "5.
|
|
264
|
-
"sample deviation": "0.
|
|
268
|
+
"time taken (ms)": "168.93",
|
|
269
|
+
"executions per sec": "5.92",
|
|
270
|
+
"sample deviation": "0.04"
|
|
265
271
|
},
|
|
266
272
|
{
|
|
267
273
|
"test name": "1,000,000 insertBefore",
|
|
268
|
-
"time taken (ms)": "
|
|
269
|
-
"executions per sec": "
|
|
270
|
-
"sample deviation": "0.
|
|
274
|
+
"time taken (ms)": "291.32",
|
|
275
|
+
"executions per sec": "3.43",
|
|
276
|
+
"sample deviation": "0.05"
|
|
271
277
|
}
|
|
272
278
|
],
|
|
273
279
|
"testName": "doubly-linked-list"
|
|
@@ -276,15 +282,15 @@
|
|
|
276
282
|
"benchmarks": [
|
|
277
283
|
{
|
|
278
284
|
"test name": "10,000 push & pop",
|
|
279
|
-
"time taken (ms)": "
|
|
280
|
-
"executions per sec": "4.
|
|
281
|
-
"sample deviation": "0.
|
|
285
|
+
"time taken (ms)": "215.82",
|
|
286
|
+
"executions per sec": "4.63",
|
|
287
|
+
"sample deviation": "0.02"
|
|
282
288
|
},
|
|
283
289
|
{
|
|
284
290
|
"test name": "10,000 insertBefore",
|
|
285
|
-
"time taken (ms)": "248.
|
|
286
|
-
"executions per sec": "4.
|
|
287
|
-
"sample deviation": "0.
|
|
291
|
+
"time taken (ms)": "248.56",
|
|
292
|
+
"executions per sec": "4.02",
|
|
293
|
+
"sample deviation": "0.01"
|
|
288
294
|
}
|
|
289
295
|
],
|
|
290
296
|
"testName": "singly-linked-list"
|
|
@@ -293,9 +299,9 @@
|
|
|
293
299
|
"benchmarks": [
|
|
294
300
|
{
|
|
295
301
|
"test name": "10,000 refill & poll",
|
|
296
|
-
"time taken (ms)": "
|
|
297
|
-
"executions per sec": "
|
|
298
|
-
"sample deviation": "1.
|
|
302
|
+
"time taken (ms)": "8.85",
|
|
303
|
+
"executions per sec": "113.01",
|
|
304
|
+
"sample deviation": "1.90e-4"
|
|
299
305
|
}
|
|
300
306
|
],
|
|
301
307
|
"testName": "max-priority-queue"
|
|
@@ -303,10 +309,10 @@
|
|
|
303
309
|
"priority-queue": {
|
|
304
310
|
"benchmarks": [
|
|
305
311
|
{
|
|
306
|
-
"test name": "
|
|
307
|
-
"time taken (ms)": "
|
|
308
|
-
"executions per sec": "
|
|
309
|
-
"sample deviation": "
|
|
312
|
+
"test name": "100,000 add & pop",
|
|
313
|
+
"time taken (ms)": "104.23",
|
|
314
|
+
"executions per sec": "9.59",
|
|
315
|
+
"sample deviation": "0.00"
|
|
310
316
|
}
|
|
311
317
|
],
|
|
312
318
|
"testName": "priority-queue"
|
|
@@ -315,15 +321,27 @@
|
|
|
315
321
|
"benchmarks": [
|
|
316
322
|
{
|
|
317
323
|
"test name": "1,000,000 push",
|
|
318
|
-
"time taken (ms)": "
|
|
319
|
-
"executions per sec": "
|
|
320
|
-
"sample deviation": "
|
|
324
|
+
"time taken (ms)": "14.25",
|
|
325
|
+
"executions per sec": "70.18",
|
|
326
|
+
"sample deviation": "1.63e-4"
|
|
321
327
|
},
|
|
322
328
|
{
|
|
323
|
-
"test name": "1,000,000
|
|
324
|
-
"time taken (ms)": "
|
|
325
|
-
"executions per sec": "
|
|
326
|
-
"sample deviation": "
|
|
329
|
+
"test name": "1,000,000 push & pop",
|
|
330
|
+
"time taken (ms)": "23.15",
|
|
331
|
+
"executions per sec": "43.21",
|
|
332
|
+
"sample deviation": "2.07e-4"
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
"test name": "1,000,000 push & shift",
|
|
336
|
+
"time taken (ms)": "24.16",
|
|
337
|
+
"executions per sec": "41.40",
|
|
338
|
+
"sample deviation": "1.78e-4"
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
"test name": "1,000,000 unshift & shift",
|
|
342
|
+
"time taken (ms)": "22.28",
|
|
343
|
+
"executions per sec": "44.88",
|
|
344
|
+
"sample deviation": "1.56e-4"
|
|
327
345
|
}
|
|
328
346
|
],
|
|
329
347
|
"testName": "deque"
|
|
@@ -332,14 +350,14 @@
|
|
|
332
350
|
"benchmarks": [
|
|
333
351
|
{
|
|
334
352
|
"test name": "1,000,000 push",
|
|
335
|
-
"time taken (ms)": "
|
|
336
|
-
"executions per sec": "21.
|
|
353
|
+
"time taken (ms)": "45.72",
|
|
354
|
+
"executions per sec": "21.87",
|
|
337
355
|
"sample deviation": "0.01"
|
|
338
356
|
},
|
|
339
357
|
{
|
|
340
358
|
"test name": "1,000,000 push & shift",
|
|
341
|
-
"time taken (ms)": "
|
|
342
|
-
"executions per sec": "12.
|
|
359
|
+
"time taken (ms)": "81.75",
|
|
360
|
+
"executions per sec": "12.23",
|
|
343
361
|
"sample deviation": "0.00"
|
|
344
362
|
}
|
|
345
363
|
],
|
|
@@ -349,14 +367,14 @@
|
|
|
349
367
|
"benchmarks": [
|
|
350
368
|
{
|
|
351
369
|
"test name": "1,000,000 push",
|
|
352
|
-
"time taken (ms)": "
|
|
353
|
-
"executions per sec": "22.
|
|
370
|
+
"time taken (ms)": "44.30",
|
|
371
|
+
"executions per sec": "22.57",
|
|
354
372
|
"sample deviation": "0.01"
|
|
355
373
|
},
|
|
356
374
|
{
|
|
357
375
|
"test name": "1,000,000 push & pop",
|
|
358
|
-
"time taken (ms)": "
|
|
359
|
-
"executions per sec": "
|
|
376
|
+
"time taken (ms)": "49.69",
|
|
377
|
+
"executions per sec": "20.12",
|
|
360
378
|
"sample deviation": "0.01"
|
|
361
379
|
}
|
|
362
380
|
],
|
|
@@ -366,14 +384,14 @@
|
|
|
366
384
|
"benchmarks": [
|
|
367
385
|
{
|
|
368
386
|
"test name": "100,000 push",
|
|
369
|
-
"time taken (ms)": "
|
|
370
|
-
"executions per sec": "
|
|
371
|
-
"sample deviation": "
|
|
387
|
+
"time taken (ms)": "43.10",
|
|
388
|
+
"executions per sec": "23.20",
|
|
389
|
+
"sample deviation": "6.46e-4"
|
|
372
390
|
},
|
|
373
391
|
{
|
|
374
392
|
"test name": "100,000 getWords",
|
|
375
|
-
"time taken (ms)": "
|
|
376
|
-
"executions per sec": "
|
|
393
|
+
"time taken (ms)": "85.45",
|
|
394
|
+
"executions per sec": "11.70",
|
|
377
395
|
"sample deviation": "0.00"
|
|
378
396
|
}
|
|
379
397
|
],
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import { HashMapLinkedNode,
|
|
8
|
+
import { HashMapLinkedNode, IterableWithSizeOrLength, IterateDirection } from '../../types';
|
|
9
9
|
/**
|
|
10
10
|
* Because the implementation of HashMap relies on JavaScript's built-in objects and arrays,
|
|
11
11
|
* these underlying structures have already dealt with dynamic expansion and hash collisions.
|
|
@@ -45,6 +45,7 @@ export declare class HashMapIterator<K, V> {
|
|
|
45
45
|
isAccessible(): boolean;
|
|
46
46
|
prev(): this;
|
|
47
47
|
next(): this;
|
|
48
|
+
clone(): HashMapIterator<K, V>;
|
|
48
49
|
}
|
|
49
50
|
export declare class HashMap<K = any, V = any> {
|
|
50
51
|
readonly OBJ_KEY_INDEX: symbol;
|
|
@@ -55,11 +56,11 @@ export declare class HashMap<K = any, V = any> {
|
|
|
55
56
|
protected readonly _sentinel: HashMapLinkedNode<K, V>;
|
|
56
57
|
/**
|
|
57
58
|
* The constructor initializes a HashMap object with an optional initial set of key-value pairs.
|
|
58
|
-
* @param
|
|
59
|
+
* @param {Iterable<[K, V]>} elements - The `hashMap` parameter is an optional parameter of type `HashMapOptions<[K,
|
|
59
60
|
* V]>`. It is an array of key-value pairs, where each pair is represented as an array `[K, V]`. The
|
|
60
61
|
* `K` represents the type of the key and `V` represents the
|
|
61
62
|
*/
|
|
62
|
-
constructor(
|
|
63
|
+
constructor(elements?: IterableWithSizeOrLength<[K, V]>);
|
|
63
64
|
protected _size: number;
|
|
64
65
|
get size(): number;
|
|
65
66
|
/**
|
|
@@ -105,7 +106,7 @@ export declare class HashMap<K = any, V = any> {
|
|
|
105
106
|
* @returns The front element of the data structure, represented as a tuple with a key (K) and a
|
|
106
107
|
* value (V).
|
|
107
108
|
*/
|
|
108
|
-
get
|
|
109
|
+
get first(): [K, V] | undefined;
|
|
109
110
|
/**
|
|
110
111
|
* Time Complexity: O(1)
|
|
111
112
|
* Space Complexity: O(1)
|
|
@@ -114,7 +115,7 @@ export declare class HashMap<K = any, V = any> {
|
|
|
114
115
|
* @returns The method is returning an array containing the key-value pair of the tail element in the
|
|
115
116
|
* data structure.
|
|
116
117
|
*/
|
|
117
|
-
get
|
|
118
|
+
get last(): [K, V] | undefined;
|
|
118
119
|
/**
|
|
119
120
|
* Time Complexity: O(1)
|
|
120
121
|
* Space Complexity: O(1)
|
|
@@ -109,16 +109,19 @@ class HashMapIterator {
|
|
|
109
109
|
next() {
|
|
110
110
|
return this;
|
|
111
111
|
}
|
|
112
|
+
clone() {
|
|
113
|
+
return new HashMapIterator(this._node, this._sentinel, this.hashMap, this.iterateDirection);
|
|
114
|
+
}
|
|
112
115
|
}
|
|
113
116
|
exports.HashMapIterator = HashMapIterator;
|
|
114
117
|
class HashMap {
|
|
115
118
|
/**
|
|
116
119
|
* The constructor initializes a HashMap object with an optional initial set of key-value pairs.
|
|
117
|
-
* @param
|
|
120
|
+
* @param {Iterable<[K, V]>} elements - The `hashMap` parameter is an optional parameter of type `HashMapOptions<[K,
|
|
118
121
|
* V]>`. It is an array of key-value pairs, where each pair is represented as an array `[K, V]`. The
|
|
119
122
|
* `K` represents the type of the key and `V` represents the
|
|
120
123
|
*/
|
|
121
|
-
constructor(
|
|
124
|
+
constructor(elements = []) {
|
|
122
125
|
this.OBJ_KEY_INDEX = Symbol('OBJ_KEY_INDEX');
|
|
123
126
|
this._nodes = [];
|
|
124
127
|
this._orgMap = {};
|
|
@@ -126,9 +129,9 @@ class HashMap {
|
|
|
126
129
|
Object.setPrototypeOf(this._orgMap, null);
|
|
127
130
|
this._sentinel = {};
|
|
128
131
|
this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
|
|
129
|
-
|
|
132
|
+
for (const el of elements) {
|
|
130
133
|
this.set(el[0], el[1]);
|
|
131
|
-
}
|
|
134
|
+
}
|
|
132
135
|
}
|
|
133
136
|
get size() {
|
|
134
137
|
return this._size;
|
|
@@ -184,7 +187,7 @@ class HashMap {
|
|
|
184
187
|
* @returns The front element of the data structure, represented as a tuple with a key (K) and a
|
|
185
188
|
* value (V).
|
|
186
189
|
*/
|
|
187
|
-
get
|
|
190
|
+
get first() {
|
|
188
191
|
if (this._size === 0)
|
|
189
192
|
return;
|
|
190
193
|
return [this._head.key, this._head.value];
|
|
@@ -197,7 +200,7 @@ class HashMap {
|
|
|
197
200
|
* @returns The method is returning an array containing the key-value pair of the tail element in the
|
|
198
201
|
* data structure.
|
|
199
202
|
*/
|
|
200
|
-
get
|
|
203
|
+
get last() {
|
|
201
204
|
if (this._size === 0)
|
|
202
205
|
return;
|
|
203
206
|
return [this._tail.key, this._tail.value];
|