data-structure-typed 1.48.8 → 1.48.9
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 +58 -55
- package/README_zh-CN.md +58 -56
- package/benchmark/report.html +1 -46
- package/benchmark/report.json +23 -458
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +0 -4
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +36 -34
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +0 -110
- package/dist/cjs/data-structures/queue/deque.js +1 -172
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +0 -4
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +36 -34
- package/dist/mjs/data-structures/queue/deque.d.ts +0 -110
- package/dist/mjs/data-structures/queue/deque.js +0 -170
- package/dist/umd/data-structure-typed.js +32 -195
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/binary-tree/binary-tree.ts +43 -33
- package/src/data-structures/queue/deque.ts +1 -191
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +15 -8
- package/test/unit/data-structures/binary-tree/bst.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +5 -5
- package/test/unit/data-structures/queue/deque.test.ts +265 -367
- package/test/unit/data-structures/queue/queue.test.ts +158 -158
package/benchmark/report.json
CHANGED
|
@@ -1,490 +1,55 @@
|
|
|
1
1
|
{
|
|
2
|
-
"avl-tree": {
|
|
3
|
-
"benchmarks": [
|
|
4
|
-
{
|
|
5
|
-
"test name": "10,000 add randomly",
|
|
6
|
-
"time taken (ms)": "51.22",
|
|
7
|
-
"executions per sec": "19.52",
|
|
8
|
-
"sample deviation": "0.00"
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"test name": "10,000 add & delete randomly",
|
|
12
|
-
"time taken (ms)": "110.40",
|
|
13
|
-
"executions per sec": "9.06",
|
|
14
|
-
"sample deviation": "0.00"
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"test name": "10,000 addMany",
|
|
18
|
-
"time taken (ms)": "58.39",
|
|
19
|
-
"executions per sec": "17.13",
|
|
20
|
-
"sample deviation": "6.35e-4"
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
"test name": "10,000 get",
|
|
24
|
-
"time taken (ms)": "50.59",
|
|
25
|
-
"executions per sec": "19.77",
|
|
26
|
-
"sample deviation": "3.87e-4"
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
"testName": "avl-tree"
|
|
30
|
-
},
|
|
31
2
|
"binary-tree": {
|
|
32
3
|
"benchmarks": [
|
|
33
4
|
{
|
|
34
5
|
"test name": "1,000 add randomly",
|
|
35
|
-
"time taken (ms)": "
|
|
36
|
-
"executions per sec": "
|
|
37
|
-
"sample deviation": "
|
|
6
|
+
"time taken (ms)": "17.61",
|
|
7
|
+
"executions per sec": "56.79",
|
|
8
|
+
"sample deviation": "4.75e-4"
|
|
38
9
|
},
|
|
39
10
|
{
|
|
40
11
|
"test name": "1,000 add & delete randomly",
|
|
41
|
-
"time taken (ms)": "21
|
|
42
|
-
"executions per sec": "
|
|
43
|
-
"sample deviation": "
|
|
12
|
+
"time taken (ms)": "23.21",
|
|
13
|
+
"executions per sec": "43.08",
|
|
14
|
+
"sample deviation": "0.00"
|
|
44
15
|
},
|
|
45
16
|
{
|
|
46
17
|
"test name": "1,000 addMany",
|
|
47
|
-
"time taken (ms)": "
|
|
48
|
-
"executions per sec": "
|
|
49
|
-
"sample deviation": "
|
|
18
|
+
"time taken (ms)": "17.89",
|
|
19
|
+
"executions per sec": "55.90",
|
|
20
|
+
"sample deviation": "0.00"
|
|
50
21
|
},
|
|
51
22
|
{
|
|
52
23
|
"test name": "1,000 get",
|
|
53
|
-
"time taken (ms)": "
|
|
54
|
-
"executions per sec": "
|
|
55
|
-
"sample deviation": "
|
|
24
|
+
"time taken (ms)": "17.71",
|
|
25
|
+
"executions per sec": "56.47",
|
|
26
|
+
"sample deviation": "0.00"
|
|
56
27
|
},
|
|
57
28
|
{
|
|
58
29
|
"test name": "1,000 has",
|
|
59
|
-
"time taken (ms)": "
|
|
60
|
-
"executions per sec": "
|
|
61
|
-
"sample deviation": "
|
|
30
|
+
"time taken (ms)": "17.15",
|
|
31
|
+
"executions per sec": "58.30",
|
|
32
|
+
"sample deviation": "2.88e-4"
|
|
62
33
|
},
|
|
63
34
|
{
|
|
64
35
|
"test name": "1,000 dfs",
|
|
65
|
-
"time taken (ms)": "161.
|
|
66
|
-
"executions per sec": "6.
|
|
67
|
-
"sample deviation": "
|
|
36
|
+
"time taken (ms)": "161.44",
|
|
37
|
+
"executions per sec": "6.19",
|
|
38
|
+
"sample deviation": "0.00"
|
|
68
39
|
},
|
|
69
40
|
{
|
|
70
41
|
"test name": "1,000 bfs",
|
|
71
|
-
"time taken (ms)": "
|
|
72
|
-
"executions per sec": "17.
|
|
73
|
-
"sample deviation": "
|
|
42
|
+
"time taken (ms)": "57.53",
|
|
43
|
+
"executions per sec": "17.38",
|
|
44
|
+
"sample deviation": "0.00"
|
|
74
45
|
},
|
|
75
46
|
{
|
|
76
47
|
"test name": "1,000 morris",
|
|
77
|
-
"time taken (ms)": "
|
|
78
|
-
"executions per sec": "3.
|
|
48
|
+
"time taken (ms)": "258.22",
|
|
49
|
+
"executions per sec": "3.87",
|
|
79
50
|
"sample deviation": "0.00"
|
|
80
51
|
}
|
|
81
52
|
],
|
|
82
53
|
"testName": "binary-tree"
|
|
83
|
-
},
|
|
84
|
-
"bst": {
|
|
85
|
-
"benchmarks": [
|
|
86
|
-
{
|
|
87
|
-
"test name": "10,000 add randomly",
|
|
88
|
-
"time taken (ms)": "51.51",
|
|
89
|
-
"executions per sec": "19.41",
|
|
90
|
-
"sample deviation": "8.70e-4"
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
"test name": "10,000 add & delete randomly",
|
|
94
|
-
"time taken (ms)": "114.09",
|
|
95
|
-
"executions per sec": "8.76",
|
|
96
|
-
"sample deviation": "9.66e-4"
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
"test name": "10,000 addMany",
|
|
100
|
-
"time taken (ms)": "47.86",
|
|
101
|
-
"executions per sec": "20.90",
|
|
102
|
-
"sample deviation": "2.77e-4"
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
"test name": "10,000 get",
|
|
106
|
-
"time taken (ms)": "51.93",
|
|
107
|
-
"executions per sec": "19.26",
|
|
108
|
-
"sample deviation": "6.56e-4"
|
|
109
|
-
}
|
|
110
|
-
],
|
|
111
|
-
"testName": "bst"
|
|
112
|
-
},
|
|
113
|
-
"rb-tree": {
|
|
114
|
-
"benchmarks": [
|
|
115
|
-
{
|
|
116
|
-
"test name": "100,000 add",
|
|
117
|
-
"time taken (ms)": "86.63",
|
|
118
|
-
"executions per sec": "11.54",
|
|
119
|
-
"sample deviation": "0.00"
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
"test name": "100,000 add & delete randomly",
|
|
123
|
-
"time taken (ms)": "218.88",
|
|
124
|
-
"executions per sec": "4.57",
|
|
125
|
-
"sample deviation": "0.01"
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
"test name": "100,000 getNode",
|
|
129
|
-
"time taken (ms)": "261.16",
|
|
130
|
-
"executions per sec": "3.83",
|
|
131
|
-
"sample deviation": "0.00"
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
"test name": "100,000 add & iterator",
|
|
135
|
-
"time taken (ms)": "117.64",
|
|
136
|
-
"executions per sec": "8.50",
|
|
137
|
-
"sample deviation": "0.00"
|
|
138
|
-
}
|
|
139
|
-
],
|
|
140
|
-
"testName": "rb-tree"
|
|
141
|
-
},
|
|
142
|
-
"comparison": {
|
|
143
|
-
"benchmarks": [
|
|
144
|
-
{
|
|
145
|
-
"test name": "SRC PQ 10,000 add",
|
|
146
|
-
"time taken (ms)": "0.14",
|
|
147
|
-
"executions per sec": "6949.20",
|
|
148
|
-
"sample deviation": "1.53e-6"
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
"test name": "CJS PQ 10,000 add",
|
|
152
|
-
"time taken (ms)": "0.14",
|
|
153
|
-
"executions per sec": "6943.68",
|
|
154
|
-
"sample deviation": "1.74e-6"
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
"test name": "MJS PQ 10,000 add",
|
|
158
|
-
"time taken (ms)": "0.57",
|
|
159
|
-
"executions per sec": "1758.40",
|
|
160
|
-
"sample deviation": "6.26e-6"
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
"test name": "SRC PQ 10,000 add & pop",
|
|
164
|
-
"time taken (ms)": "3.40",
|
|
165
|
-
"executions per sec": "293.94",
|
|
166
|
-
"sample deviation": "3.50e-5"
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
"test name": "CJS PQ 10,000 add & pop",
|
|
170
|
-
"time taken (ms)": "3.42",
|
|
171
|
-
"executions per sec": "292.69",
|
|
172
|
-
"sample deviation": "5.34e-5"
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
"test name": "MJS PQ 10,000 add & pop",
|
|
176
|
-
"time taken (ms)": "3.30",
|
|
177
|
-
"executions per sec": "303.01",
|
|
178
|
-
"sample deviation": "3.97e-5"
|
|
179
|
-
}
|
|
180
|
-
],
|
|
181
|
-
"testName": "comparison"
|
|
182
|
-
},
|
|
183
|
-
"directed-graph": {
|
|
184
|
-
"benchmarks": [
|
|
185
|
-
{
|
|
186
|
-
"test name": "1,000 addVertex",
|
|
187
|
-
"time taken (ms)": "0.10",
|
|
188
|
-
"executions per sec": "9930.74",
|
|
189
|
-
"sample deviation": "1.11e-6"
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
"test name": "1,000 addEdge",
|
|
193
|
-
"time taken (ms)": "6.13",
|
|
194
|
-
"executions per sec": "163.19",
|
|
195
|
-
"sample deviation": "1.84e-4"
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
"test name": "1,000 getVertex",
|
|
199
|
-
"time taken (ms)": "0.05",
|
|
200
|
-
"executions per sec": "2.15e+4",
|
|
201
|
-
"sample deviation": "5.00e-7"
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
"test name": "1,000 getEdge",
|
|
205
|
-
"time taken (ms)": "23.57",
|
|
206
|
-
"executions per sec": "42.43",
|
|
207
|
-
"sample deviation": "0.00"
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
"test name": "tarjan",
|
|
211
|
-
"time taken (ms)": "252.05",
|
|
212
|
-
"executions per sec": "3.97",
|
|
213
|
-
"sample deviation": "0.03"
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
"test name": "tarjan all",
|
|
217
|
-
"time taken (ms)": "221.15",
|
|
218
|
-
"executions per sec": "4.52",
|
|
219
|
-
"sample deviation": "0.00"
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
"test name": "topologicalSort",
|
|
223
|
-
"time taken (ms)": "181.07",
|
|
224
|
-
"executions per sec": "5.52",
|
|
225
|
-
"sample deviation": "0.00"
|
|
226
|
-
}
|
|
227
|
-
],
|
|
228
|
-
"testName": "directed-graph"
|
|
229
|
-
},
|
|
230
|
-
"hash-map": {
|
|
231
|
-
"benchmarks": [
|
|
232
|
-
{
|
|
233
|
-
"test name": "1,000,000 set",
|
|
234
|
-
"time taken (ms)": "122.90",
|
|
235
|
-
"executions per sec": "8.14",
|
|
236
|
-
"sample deviation": "0.04"
|
|
237
|
-
},
|
|
238
|
-
{
|
|
239
|
-
"test name": "Native Map 1,000,000 set",
|
|
240
|
-
"time taken (ms)": "215.97",
|
|
241
|
-
"executions per sec": "4.63",
|
|
242
|
-
"sample deviation": "0.02"
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
"test name": "Native Set 1,000,000 add",
|
|
246
|
-
"time taken (ms)": "179.11",
|
|
247
|
-
"executions per sec": "5.58",
|
|
248
|
-
"sample deviation": "0.02"
|
|
249
|
-
},
|
|
250
|
-
{
|
|
251
|
-
"test name": "1,000,000 set & get",
|
|
252
|
-
"time taken (ms)": "123.10",
|
|
253
|
-
"executions per sec": "8.12",
|
|
254
|
-
"sample deviation": "0.04"
|
|
255
|
-
},
|
|
256
|
-
{
|
|
257
|
-
"test name": "Native Map 1,000,000 set & get",
|
|
258
|
-
"time taken (ms)": "271.80",
|
|
259
|
-
"executions per sec": "3.68",
|
|
260
|
-
"sample deviation": "0.02"
|
|
261
|
-
},
|
|
262
|
-
{
|
|
263
|
-
"test name": "Native Set 1,000,000 add & has",
|
|
264
|
-
"time taken (ms)": "176.65",
|
|
265
|
-
"executions per sec": "5.66",
|
|
266
|
-
"sample deviation": "0.02"
|
|
267
|
-
},
|
|
268
|
-
{
|
|
269
|
-
"test name": "1,000,000 ObjKey set & get",
|
|
270
|
-
"time taken (ms)": "341.97",
|
|
271
|
-
"executions per sec": "2.92",
|
|
272
|
-
"sample deviation": "0.07"
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
"test name": "Native Map 1,000,000 ObjKey set & get",
|
|
276
|
-
"time taken (ms)": "316.86",
|
|
277
|
-
"executions per sec": "3.16",
|
|
278
|
-
"sample deviation": "0.04"
|
|
279
|
-
},
|
|
280
|
-
{
|
|
281
|
-
"test name": "Native Set 1,000,000 ObjKey add & has",
|
|
282
|
-
"time taken (ms)": "285.14",
|
|
283
|
-
"executions per sec": "3.51",
|
|
284
|
-
"sample deviation": "0.06"
|
|
285
|
-
}
|
|
286
|
-
],
|
|
287
|
-
"testName": "hash-map"
|
|
288
|
-
},
|
|
289
|
-
"heap": {
|
|
290
|
-
"benchmarks": [
|
|
291
|
-
{
|
|
292
|
-
"test name": "100,000 add & pop",
|
|
293
|
-
"time taken (ms)": "80.37",
|
|
294
|
-
"executions per sec": "12.44",
|
|
295
|
-
"sample deviation": "0.00"
|
|
296
|
-
},
|
|
297
|
-
{
|
|
298
|
-
"test name": "100,000 add & dfs",
|
|
299
|
-
"time taken (ms)": "36.20",
|
|
300
|
-
"executions per sec": "27.63",
|
|
301
|
-
"sample deviation": "0.00"
|
|
302
|
-
},
|
|
303
|
-
{
|
|
304
|
-
"test name": "10,000 fib add & pop",
|
|
305
|
-
"time taken (ms)": "362.24",
|
|
306
|
-
"executions per sec": "2.76",
|
|
307
|
-
"sample deviation": "0.00"
|
|
308
|
-
}
|
|
309
|
-
],
|
|
310
|
-
"testName": "heap"
|
|
311
|
-
},
|
|
312
|
-
"doubly-linked-list": {
|
|
313
|
-
"benchmarks": [
|
|
314
|
-
{
|
|
315
|
-
"test name": "1,000,000 push",
|
|
316
|
-
"time taken (ms)": "216.09",
|
|
317
|
-
"executions per sec": "4.63",
|
|
318
|
-
"sample deviation": "0.06"
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
"test name": "1,000,000 unshift",
|
|
322
|
-
"time taken (ms)": "220.68",
|
|
323
|
-
"executions per sec": "4.53",
|
|
324
|
-
"sample deviation": "0.02"
|
|
325
|
-
},
|
|
326
|
-
{
|
|
327
|
-
"test name": "1,000,000 unshift & shift",
|
|
328
|
-
"time taken (ms)": "172.93",
|
|
329
|
-
"executions per sec": "5.78",
|
|
330
|
-
"sample deviation": "0.04"
|
|
331
|
-
},
|
|
332
|
-
{
|
|
333
|
-
"test name": "1,000,000 insertBefore",
|
|
334
|
-
"time taken (ms)": "332.25",
|
|
335
|
-
"executions per sec": "3.01",
|
|
336
|
-
"sample deviation": "0.08"
|
|
337
|
-
}
|
|
338
|
-
],
|
|
339
|
-
"testName": "doubly-linked-list"
|
|
340
|
-
},
|
|
341
|
-
"singly-linked-list": {
|
|
342
|
-
"benchmarks": [
|
|
343
|
-
{
|
|
344
|
-
"test name": "1,000,000 push & shift",
|
|
345
|
-
"time taken (ms)": "222.99",
|
|
346
|
-
"executions per sec": "4.48",
|
|
347
|
-
"sample deviation": "0.10"
|
|
348
|
-
},
|
|
349
|
-
{
|
|
350
|
-
"test name": "10,000 push & pop",
|
|
351
|
-
"time taken (ms)": "214.82",
|
|
352
|
-
"executions per sec": "4.66",
|
|
353
|
-
"sample deviation": "0.01"
|
|
354
|
-
},
|
|
355
|
-
{
|
|
356
|
-
"test name": "10,000 insertBefore",
|
|
357
|
-
"time taken (ms)": "251.24",
|
|
358
|
-
"executions per sec": "3.98",
|
|
359
|
-
"sample deviation": "0.01"
|
|
360
|
-
}
|
|
361
|
-
],
|
|
362
|
-
"testName": "singly-linked-list"
|
|
363
|
-
},
|
|
364
|
-
"max-priority-queue": {
|
|
365
|
-
"benchmarks": [
|
|
366
|
-
{
|
|
367
|
-
"test name": "10,000 refill & poll",
|
|
368
|
-
"time taken (ms)": "8.91",
|
|
369
|
-
"executions per sec": "112.19",
|
|
370
|
-
"sample deviation": "1.57e-4"
|
|
371
|
-
}
|
|
372
|
-
],
|
|
373
|
-
"testName": "max-priority-queue"
|
|
374
|
-
},
|
|
375
|
-
"priority-queue": {
|
|
376
|
-
"benchmarks": [
|
|
377
|
-
{
|
|
378
|
-
"test name": "100,000 add & pop",
|
|
379
|
-
"time taken (ms)": "101.70",
|
|
380
|
-
"executions per sec": "9.83",
|
|
381
|
-
"sample deviation": "0.00"
|
|
382
|
-
}
|
|
383
|
-
],
|
|
384
|
-
"testName": "priority-queue"
|
|
385
|
-
},
|
|
386
|
-
"deque": {
|
|
387
|
-
"benchmarks": [
|
|
388
|
-
{
|
|
389
|
-
"test name": "1,000,000 push",
|
|
390
|
-
"time taken (ms)": "13.80",
|
|
391
|
-
"executions per sec": "72.47",
|
|
392
|
-
"sample deviation": "1.56e-4"
|
|
393
|
-
},
|
|
394
|
-
{
|
|
395
|
-
"test name": "1,000,000 push & pop",
|
|
396
|
-
"time taken (ms)": "22.72",
|
|
397
|
-
"executions per sec": "44.02",
|
|
398
|
-
"sample deviation": "2.02e-4"
|
|
399
|
-
},
|
|
400
|
-
{
|
|
401
|
-
"test name": "100,000 push & shift",
|
|
402
|
-
"time taken (ms)": "2.35",
|
|
403
|
-
"executions per sec": "425.67",
|
|
404
|
-
"sample deviation": "5.80e-5"
|
|
405
|
-
},
|
|
406
|
-
{
|
|
407
|
-
"test name": "Native Array 100,000 push & shift",
|
|
408
|
-
"time taken (ms)": "2511.14",
|
|
409
|
-
"executions per sec": "0.40",
|
|
410
|
-
"sample deviation": "0.36"
|
|
411
|
-
},
|
|
412
|
-
{
|
|
413
|
-
"test name": "100,000 unshift & shift",
|
|
414
|
-
"time taken (ms)": "2.23",
|
|
415
|
-
"executions per sec": "447.89",
|
|
416
|
-
"sample deviation": "3.30e-4"
|
|
417
|
-
},
|
|
418
|
-
{
|
|
419
|
-
"test name": "Native Array 100,000 unshift & shift",
|
|
420
|
-
"time taken (ms)": "4140.23",
|
|
421
|
-
"executions per sec": "0.24",
|
|
422
|
-
"sample deviation": "0.33"
|
|
423
|
-
}
|
|
424
|
-
],
|
|
425
|
-
"testName": "deque"
|
|
426
|
-
},
|
|
427
|
-
"queue": {
|
|
428
|
-
"benchmarks": [
|
|
429
|
-
{
|
|
430
|
-
"test name": "1,000,000 push",
|
|
431
|
-
"time taken (ms)": "43.65",
|
|
432
|
-
"executions per sec": "22.91",
|
|
433
|
-
"sample deviation": "0.01"
|
|
434
|
-
},
|
|
435
|
-
{
|
|
436
|
-
"test name": "100,000 push & shift",
|
|
437
|
-
"time taken (ms)": "4.99",
|
|
438
|
-
"executions per sec": "200.28",
|
|
439
|
-
"sample deviation": "9.54e-5"
|
|
440
|
-
},
|
|
441
|
-
{
|
|
442
|
-
"test name": "Native Array 100,000 push & shift",
|
|
443
|
-
"time taken (ms)": "2335.63",
|
|
444
|
-
"executions per sec": "0.43",
|
|
445
|
-
"sample deviation": "0.33"
|
|
446
|
-
},
|
|
447
|
-
{
|
|
448
|
-
"test name": "Native Array 100,000 push & pop",
|
|
449
|
-
"time taken (ms)": "4.39",
|
|
450
|
-
"executions per sec": "227.81",
|
|
451
|
-
"sample deviation": "0.00"
|
|
452
|
-
}
|
|
453
|
-
],
|
|
454
|
-
"testName": "queue"
|
|
455
|
-
},
|
|
456
|
-
"stack": {
|
|
457
|
-
"benchmarks": [
|
|
458
|
-
{
|
|
459
|
-
"test name": "1,000,000 push",
|
|
460
|
-
"time taken (ms)": "45.38",
|
|
461
|
-
"executions per sec": "22.04",
|
|
462
|
-
"sample deviation": "0.01"
|
|
463
|
-
},
|
|
464
|
-
{
|
|
465
|
-
"test name": "1,000,000 push & pop",
|
|
466
|
-
"time taken (ms)": "49.52",
|
|
467
|
-
"executions per sec": "20.19",
|
|
468
|
-
"sample deviation": "0.01"
|
|
469
|
-
}
|
|
470
|
-
],
|
|
471
|
-
"testName": "stack"
|
|
472
|
-
},
|
|
473
|
-
"trie": {
|
|
474
|
-
"benchmarks": [
|
|
475
|
-
{
|
|
476
|
-
"test name": "100,000 push",
|
|
477
|
-
"time taken (ms)": "42.99",
|
|
478
|
-
"executions per sec": "23.26",
|
|
479
|
-
"sample deviation": "0.00"
|
|
480
|
-
},
|
|
481
|
-
{
|
|
482
|
-
"test name": "100,000 getWords",
|
|
483
|
-
"time taken (ms)": "89.78",
|
|
484
|
-
"executions per sec": "11.14",
|
|
485
|
-
"sample deviation": "0.00"
|
|
486
|
-
}
|
|
487
|
-
],
|
|
488
|
-
"testName": "trie"
|
|
489
54
|
}
|
|
490
55
|
}
|
|
@@ -37,10 +37,6 @@ export declare class BinaryTreeNode<K = any, V = any, N extends BinaryTreeNode<K
|
|
|
37
37
|
* 3. Depth and Height: Depth is the number of edges from the root to a node; height is the maximum depth in the tree.
|
|
38
38
|
* 4. Subtrees: Each child of a node forms the root of a subtree.
|
|
39
39
|
* 5. Leaf Nodes: Nodes without children are leaves.
|
|
40
|
-
* 6. Internal Nodes: Nodes with at least one child are internal.
|
|
41
|
-
* 7. Balanced Trees: The heights of the left and right subtrees of any node differ by no more than one.
|
|
42
|
-
* 8. Full Trees: Every node has either 0 or 2 children.
|
|
43
|
-
* 9. Complete Trees: All levels are fully filled except possibly the last, filled from left to right.
|
|
44
40
|
*/
|
|
45
41
|
export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V, N> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, N, TREE> = BinaryTree<K, V, N, BinaryTreeNested<K, V, N>>> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, N, TREE> {
|
|
46
42
|
iterationType: IterationType;
|
|
@@ -65,10 +65,6 @@ exports.BinaryTreeNode = BinaryTreeNode;
|
|
|
65
65
|
* 3. Depth and Height: Depth is the number of edges from the root to a node; height is the maximum depth in the tree.
|
|
66
66
|
* 4. Subtrees: Each child of a node forms the root of a subtree.
|
|
67
67
|
* 5. Leaf Nodes: Nodes without children are leaves.
|
|
68
|
-
* 6. Internal Nodes: Nodes with at least one child are internal.
|
|
69
|
-
* 7. Balanced Trees: The heights of the left and right subtrees of any node differ by no more than one.
|
|
70
|
-
* 8. Full Trees: Every node has either 0 or 2 children.
|
|
71
|
-
* 9. Complete Trees: All levels are fully filled except possibly the last, filled from left to right.
|
|
72
68
|
*/
|
|
73
69
|
class BinaryTree extends base_1.IterableEntryBase {
|
|
74
70
|
/**
|
|
@@ -196,44 +192,50 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
196
192
|
* @returns The function `add` returns either a node (`N`), `null`, or `undefined`.
|
|
197
193
|
*/
|
|
198
194
|
add(keyOrNodeOrEntry, value) {
|
|
199
|
-
let inserted;
|
|
200
195
|
const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
|
|
201
196
|
if (newNode === undefined)
|
|
202
197
|
return;
|
|
203
|
-
//
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
198
|
+
// If the tree is empty, directly set the new node as the root node
|
|
199
|
+
if (!this.root) {
|
|
200
|
+
this._root = newNode;
|
|
201
|
+
this._size = 1;
|
|
202
|
+
return newNode;
|
|
203
|
+
}
|
|
204
|
+
const queue = new queue_1.Queue([this.root]);
|
|
205
|
+
let potentialParent; // Record the parent node of the potential insertion location
|
|
206
|
+
while (queue.size > 0) {
|
|
207
|
+
const cur = queue.shift();
|
|
208
|
+
if (!cur)
|
|
209
|
+
continue;
|
|
210
|
+
// Check for duplicate keys when newNode is not null
|
|
211
|
+
if (newNode !== null && cur.key === newNode.key) {
|
|
212
|
+
this._replaceNode(cur, newNode);
|
|
213
|
+
return newNode; // If duplicate keys are found, no insertion is performed
|
|
214
|
+
}
|
|
215
|
+
// Record the first possible insertion location found
|
|
216
|
+
if (potentialParent === undefined && (cur.left === undefined || cur.right === undefined)) {
|
|
217
|
+
potentialParent = cur;
|
|
218
|
+
}
|
|
219
|
+
// Continue traversing the left and right subtrees
|
|
220
|
+
if (cur.left !== null) {
|
|
221
|
+
cur.left && queue.push(cur.left);
|
|
222
|
+
}
|
|
223
|
+
if (cur.right !== null) {
|
|
224
|
+
cur.right && queue.push(cur.right);
|
|
221
225
|
}
|
|
222
|
-
};
|
|
223
|
-
if (this.root) {
|
|
224
|
-
inserted = _bfs(this.root, newNode);
|
|
225
226
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (
|
|
229
|
-
|
|
227
|
+
// At the end of the traversal, if the insertion position is found, insert
|
|
228
|
+
if (potentialParent) {
|
|
229
|
+
if (potentialParent.left === undefined) {
|
|
230
|
+
potentialParent.left = newNode;
|
|
230
231
|
}
|
|
231
|
-
else {
|
|
232
|
-
|
|
232
|
+
else if (potentialParent.right === undefined) {
|
|
233
|
+
potentialParent.right = newNode;
|
|
233
234
|
}
|
|
234
|
-
|
|
235
|
+
this._size++;
|
|
236
|
+
return newNode;
|
|
235
237
|
}
|
|
236
|
-
return
|
|
238
|
+
return undefined; // If the insertion position cannot be found, return undefined
|
|
237
239
|
}
|
|
238
240
|
/**
|
|
239
241
|
* Time Complexity: O(k log n) - O(k * n)
|