data-structure-typed 1.46.4 → 1.46.6

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +65 -79
  3. package/benchmark/report.html +46 -1
  4. package/benchmark/report.json +428 -5
  5. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +2 -1
  6. package/dist/cjs/data-structures/binary-tree/binary-tree.js +29 -46
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/rb-tree.js +10 -5
  9. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  10. package/dist/cjs/data-structures/hash/hash-map.d.ts +2 -2
  11. package/dist/cjs/data-structures/hash/hash-map.js +1 -2
  12. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  13. package/dist/cjs/types/{helpers.js → common.js} +1 -1
  14. package/dist/cjs/types/common.js.map +1 -0
  15. package/dist/cjs/types/data-structures/hash/hash-map.d.ts +1 -1
  16. package/dist/cjs/types/index.d.ts +1 -1
  17. package/dist/cjs/types/index.js +1 -1
  18. package/dist/cjs/types/index.js.map +1 -1
  19. package/dist/cjs/utils/utils.d.ts +1 -1
  20. package/dist/cjs/utils/utils.js.map +1 -1
  21. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +2 -1
  22. package/dist/mjs/data-structures/binary-tree/binary-tree.js +29 -46
  23. package/dist/mjs/data-structures/binary-tree/rb-tree.js +10 -5
  24. package/dist/mjs/data-structures/hash/hash-map.d.ts +2 -2
  25. package/dist/mjs/data-structures/hash/hash-map.js +1 -2
  26. package/dist/mjs/types/data-structures/hash/hash-map.d.ts +1 -1
  27. package/dist/mjs/types/index.d.ts +1 -1
  28. package/dist/mjs/types/index.js +1 -1
  29. package/dist/mjs/utils/utils.d.ts +1 -1
  30. package/dist/umd/data-structure-typed.js +33 -51
  31. package/dist/umd/data-structure-typed.min.js +10 -5
  32. package/dist/umd/data-structure-typed.min.js.map +1 -1
  33. package/package.json +1 -1
  34. package/src/data-structures/binary-tree/binary-tree.ts +33 -46
  35. package/src/data-structures/binary-tree/rb-tree.ts +9 -4
  36. package/src/data-structures/hash/hash-map.ts +4 -5
  37. package/src/types/data-structures/hash/hash-map.ts +1 -1
  38. package/src/types/index.ts +1 -1
  39. package/src/utils/utils.ts +1 -1
  40. package/test/integration/index.html +32 -23
  41. package/test/performance/data-structures/{comparison.test.ts → comparison/comparison.test.ts} +34 -28
  42. package/test/performance/data-structures/hash/hash-map.test.ts +3 -3
  43. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +17 -0
  44. package/tsup.config.js +1 -1
  45. package/dist/cjs/types/helpers.js.map +0 -1
  46. /package/dist/cjs/types/{helpers.d.ts → common.d.ts} +0 -0
  47. /package/dist/mjs/types/{helpers.d.ts → common.d.ts} +0 -0
  48. /package/dist/mjs/types/{helpers.js → common.js} +0 -0
  49. /package/src/types/{helpers.ts → common.ts} +0 -0
@@ -1,19 +1,442 @@
1
1
  {
2
+ "avl-tree": {
3
+ "benchmarks": [
4
+ {
5
+ "test name": "10,000 add randomly",
6
+ "time taken (ms)": "31.32",
7
+ "executions per sec": "31.93",
8
+ "sample deviation": "3.67e-4"
9
+ },
10
+ {
11
+ "test name": "10,000 add & delete randomly",
12
+ "time taken (ms)": "70.90",
13
+ "executions per sec": "14.10",
14
+ "sample deviation": "0.00"
15
+ },
16
+ {
17
+ "test name": "10,000 addMany",
18
+ "time taken (ms)": "40.58",
19
+ "executions per sec": "24.64",
20
+ "sample deviation": "4.87e-4"
21
+ },
22
+ {
23
+ "test name": "10,000 get",
24
+ "time taken (ms)": "27.31",
25
+ "executions per sec": "36.62",
26
+ "sample deviation": "2.00e-4"
27
+ }
28
+ ],
29
+ "testName": "avl-tree"
30
+ },
31
+ "binary-tree": {
32
+ "benchmarks": [
33
+ {
34
+ "test name": "1,000 add randomly",
35
+ "time taken (ms)": "12.35",
36
+ "executions per sec": "80.99",
37
+ "sample deviation": "7.17e-5"
38
+ },
39
+ {
40
+ "test name": "1,000 add & delete randomly",
41
+ "time taken (ms)": "15.98",
42
+ "executions per sec": "62.58",
43
+ "sample deviation": "7.98e-4"
44
+ },
45
+ {
46
+ "test name": "1,000 addMany",
47
+ "time taken (ms)": "10.96",
48
+ "executions per sec": "91.27",
49
+ "sample deviation": "0.00"
50
+ },
51
+ {
52
+ "test name": "1,000 get",
53
+ "time taken (ms)": "18.61",
54
+ "executions per sec": "53.73",
55
+ "sample deviation": "0.00"
56
+ },
57
+ {
58
+ "test name": "1,000 dfs",
59
+ "time taken (ms)": "164.20",
60
+ "executions per sec": "6.09",
61
+ "sample deviation": "0.04"
62
+ },
63
+ {
64
+ "test name": "1,000 bfs",
65
+ "time taken (ms)": "58.84",
66
+ "executions per sec": "17.00",
67
+ "sample deviation": "0.01"
68
+ },
69
+ {
70
+ "test name": "1,000 morris",
71
+ "time taken (ms)": "256.66",
72
+ "executions per sec": "3.90",
73
+ "sample deviation": "7.70e-4"
74
+ }
75
+ ],
76
+ "testName": "binary-tree"
77
+ },
78
+ "bst": {
79
+ "benchmarks": [
80
+ {
81
+ "test name": "10,000 add randomly",
82
+ "time taken (ms)": "31.59",
83
+ "executions per sec": "31.66",
84
+ "sample deviation": "2.74e-4"
85
+ },
86
+ {
87
+ "test name": "10,000 add & delete randomly",
88
+ "time taken (ms)": "74.56",
89
+ "executions per sec": "13.41",
90
+ "sample deviation": "8.32e-4"
91
+ },
92
+ {
93
+ "test name": "10,000 addMany",
94
+ "time taken (ms)": "29.16",
95
+ "executions per sec": "34.30",
96
+ "sample deviation": "0.00"
97
+ },
98
+ {
99
+ "test name": "10,000 get",
100
+ "time taken (ms)": "29.24",
101
+ "executions per sec": "34.21",
102
+ "sample deviation": "0.00"
103
+ }
104
+ ],
105
+ "testName": "bst"
106
+ },
107
+ "rb-tree": {
108
+ "benchmarks": [
109
+ {
110
+ "test name": "100,000 add",
111
+ "time taken (ms)": "85.85",
112
+ "executions per sec": "11.65",
113
+ "sample deviation": "0.00"
114
+ },
115
+ {
116
+ "test name": "100,000 add & delete randomly",
117
+ "time taken (ms)": "211.54",
118
+ "executions per sec": "4.73",
119
+ "sample deviation": "0.00"
120
+ },
121
+ {
122
+ "test name": "100,000 getNode",
123
+ "time taken (ms)": "37.92",
124
+ "executions per sec": "26.37",
125
+ "sample deviation": "1.65e-4"
126
+ }
127
+ ],
128
+ "testName": "rb-tree"
129
+ },
130
+ "comparison": {
131
+ "benchmarks": [
132
+ {
133
+ "test name": "SRC PQ 10,000 add",
134
+ "time taken (ms)": "0.57",
135
+ "executions per sec": "1748.73",
136
+ "sample deviation": "4.96e-6"
137
+ },
138
+ {
139
+ "test name": "CJS PQ 10,000 add",
140
+ "time taken (ms)": "0.57",
141
+ "executions per sec": "1746.69",
142
+ "sample deviation": "4.91e-6"
143
+ },
144
+ {
145
+ "test name": "MJS PQ 10,000 add",
146
+ "time taken (ms)": "0.57",
147
+ "executions per sec": "1749.68",
148
+ "sample deviation": "4.43e-6"
149
+ },
150
+ {
151
+ "test name": "SRC PQ 10,000 add & pop",
152
+ "time taken (ms)": "3.47",
153
+ "executions per sec": "288.14",
154
+ "sample deviation": "6.38e-4"
155
+ },
156
+ {
157
+ "test name": "CJS PQ 10,000 add & pop",
158
+ "time taken (ms)": "3.39",
159
+ "executions per sec": "295.36",
160
+ "sample deviation": "3.90e-5"
161
+ },
162
+ {
163
+ "test name": "MJS PQ 10,000 add & pop",
164
+ "time taken (ms)": "3.37",
165
+ "executions per sec": "297.17",
166
+ "sample deviation": "3.03e-5"
167
+ }
168
+ ],
169
+ "testName": "comparison"
170
+ },
171
+ "directed-graph": {
172
+ "benchmarks": [
173
+ {
174
+ "test name": "1,000 addVertex",
175
+ "time taken (ms)": "0.10",
176
+ "executions per sec": "9534.93",
177
+ "sample deviation": "8.72e-7"
178
+ },
179
+ {
180
+ "test name": "1,000 addEdge",
181
+ "time taken (ms)": "6.30",
182
+ "executions per sec": "158.67",
183
+ "sample deviation": "0.00"
184
+ },
185
+ {
186
+ "test name": "1,000 getVertex",
187
+ "time taken (ms)": "0.05",
188
+ "executions per sec": "2.16e+4",
189
+ "sample deviation": "3.03e-7"
190
+ },
191
+ {
192
+ "test name": "1,000 getEdge",
193
+ "time taken (ms)": "22.31",
194
+ "executions per sec": "44.82",
195
+ "sample deviation": "0.00"
196
+ },
197
+ {
198
+ "test name": "tarjan",
199
+ "time taken (ms)": "210.90",
200
+ "executions per sec": "4.74",
201
+ "sample deviation": "0.01"
202
+ },
203
+ {
204
+ "test name": "tarjan all",
205
+ "time taken (ms)": "214.72",
206
+ "executions per sec": "4.66",
207
+ "sample deviation": "0.01"
208
+ },
209
+ {
210
+ "test name": "topologicalSort",
211
+ "time taken (ms)": "172.52",
212
+ "executions per sec": "5.80",
213
+ "sample deviation": "0.00"
214
+ }
215
+ ],
216
+ "testName": "directed-graph"
217
+ },
2
218
  "hash-map": {
3
219
  "benchmarks": [
4
220
  {
5
221
  "test name": "1,000,000 set",
6
- "time taken (ms)": "217.67",
7
- "executions per sec": "4.59",
222
+ "time taken (ms)": "275.88",
223
+ "executions per sec": "3.62",
224
+ "sample deviation": "0.12"
225
+ },
226
+ {
227
+ "test name": "1,000,000 Map set",
228
+ "time taken (ms)": "211.66",
229
+ "executions per sec": "4.72",
230
+ "sample deviation": "0.01"
231
+ },
232
+ {
233
+ "test name": "1,000,000 Set add",
234
+ "time taken (ms)": "177.72",
235
+ "executions per sec": "5.63",
236
+ "sample deviation": "0.02"
237
+ },
238
+ {
239
+ "test name": "1,000,000 set & get",
240
+ "time taken (ms)": "317.60",
241
+ "executions per sec": "3.15",
8
242
  "sample deviation": "0.02"
9
243
  },
10
244
  {
11
- "test name": "1,000,000 CPT set",
12
- "time taken (ms)": "176.11",
13
- "executions per sec": "5.68",
245
+ "test name": "1,000,000 Map set & get",
246
+ "time taken (ms)": "274.99",
247
+ "executions per sec": "3.64",
14
248
  "sample deviation": "0.03"
249
+ },
250
+ {
251
+ "test name": "1,000,000 Set add & has",
252
+ "time taken (ms)": "172.23",
253
+ "executions per sec": "5.81",
254
+ "sample deviation": "0.02"
255
+ },
256
+ {
257
+ "test name": "1,000,000 ObjKey set & get",
258
+ "time taken (ms)": "929.40",
259
+ "executions per sec": "1.08",
260
+ "sample deviation": "0.07"
261
+ },
262
+ {
263
+ "test name": "1,000,000 Map ObjKey set & get",
264
+ "time taken (ms)": "310.02",
265
+ "executions per sec": "3.23",
266
+ "sample deviation": "0.05"
267
+ },
268
+ {
269
+ "test name": "1,000,000 Set ObjKey add & has",
270
+ "time taken (ms)": "283.28",
271
+ "executions per sec": "3.53",
272
+ "sample deviation": "0.04"
15
273
  }
16
274
  ],
17
275
  "testName": "hash-map"
276
+ },
277
+ "heap": {
278
+ "benchmarks": [
279
+ {
280
+ "test name": "10,000 add & pop",
281
+ "time taken (ms)": "5.80",
282
+ "executions per sec": "172.35",
283
+ "sample deviation": "8.78e-5"
284
+ },
285
+ {
286
+ "test name": "10,000 fib add & pop",
287
+ "time taken (ms)": "357.92",
288
+ "executions per sec": "2.79",
289
+ "sample deviation": "0.00"
290
+ }
291
+ ],
292
+ "testName": "heap"
293
+ },
294
+ "doubly-linked-list": {
295
+ "benchmarks": [
296
+ {
297
+ "test name": "1,000,000 push",
298
+ "time taken (ms)": "221.57",
299
+ "executions per sec": "4.51",
300
+ "sample deviation": "0.03"
301
+ },
302
+ {
303
+ "test name": "1,000,000 unshift",
304
+ "time taken (ms)": "229.02",
305
+ "executions per sec": "4.37",
306
+ "sample deviation": "0.07"
307
+ },
308
+ {
309
+ "test name": "1,000,000 unshift & shift",
310
+ "time taken (ms)": "169.21",
311
+ "executions per sec": "5.91",
312
+ "sample deviation": "0.02"
313
+ },
314
+ {
315
+ "test name": "1,000,000 insertBefore",
316
+ "time taken (ms)": "314.48",
317
+ "executions per sec": "3.18",
318
+ "sample deviation": "0.07"
319
+ }
320
+ ],
321
+ "testName": "doubly-linked-list"
322
+ },
323
+ "singly-linked-list": {
324
+ "benchmarks": [
325
+ {
326
+ "test name": "10,000 push & pop",
327
+ "time taken (ms)": "212.98",
328
+ "executions per sec": "4.70",
329
+ "sample deviation": "0.01"
330
+ },
331
+ {
332
+ "test name": "10,000 insertBefore",
333
+ "time taken (ms)": "250.68",
334
+ "executions per sec": "3.99",
335
+ "sample deviation": "0.01"
336
+ }
337
+ ],
338
+ "testName": "singly-linked-list"
339
+ },
340
+ "max-priority-queue": {
341
+ "benchmarks": [
342
+ {
343
+ "test name": "10,000 refill & poll",
344
+ "time taken (ms)": "8.91",
345
+ "executions per sec": "112.29",
346
+ "sample deviation": "2.26e-4"
347
+ }
348
+ ],
349
+ "testName": "max-priority-queue"
350
+ },
351
+ "priority-queue": {
352
+ "benchmarks": [
353
+ {
354
+ "test name": "100,000 add & pop",
355
+ "time taken (ms)": "103.59",
356
+ "executions per sec": "9.65",
357
+ "sample deviation": "0.00"
358
+ }
359
+ ],
360
+ "testName": "priority-queue"
361
+ },
362
+ "deque": {
363
+ "benchmarks": [
364
+ {
365
+ "test name": "1,000,000 push",
366
+ "time taken (ms)": "14.55",
367
+ "executions per sec": "68.72",
368
+ "sample deviation": "6.91e-4"
369
+ },
370
+ {
371
+ "test name": "1,000,000 push & pop",
372
+ "time taken (ms)": "23.40",
373
+ "executions per sec": "42.73",
374
+ "sample deviation": "5.94e-4"
375
+ },
376
+ {
377
+ "test name": "1,000,000 push & shift",
378
+ "time taken (ms)": "24.41",
379
+ "executions per sec": "40.97",
380
+ "sample deviation": "1.45e-4"
381
+ },
382
+ {
383
+ "test name": "1,000,000 unshift & shift",
384
+ "time taken (ms)": "22.56",
385
+ "executions per sec": "44.32",
386
+ "sample deviation": "1.30e-4"
387
+ }
388
+ ],
389
+ "testName": "deque"
390
+ },
391
+ "queue": {
392
+ "benchmarks": [
393
+ {
394
+ "test name": "1,000,000 push",
395
+ "time taken (ms)": "39.90",
396
+ "executions per sec": "25.07",
397
+ "sample deviation": "0.01"
398
+ },
399
+ {
400
+ "test name": "1,000,000 push & shift",
401
+ "time taken (ms)": "81.79",
402
+ "executions per sec": "12.23",
403
+ "sample deviation": "0.00"
404
+ }
405
+ ],
406
+ "testName": "queue"
407
+ },
408
+ "stack": {
409
+ "benchmarks": [
410
+ {
411
+ "test name": "1,000,000 push",
412
+ "time taken (ms)": "37.60",
413
+ "executions per sec": "26.60",
414
+ "sample deviation": "0.00"
415
+ },
416
+ {
417
+ "test name": "1,000,000 push & pop",
418
+ "time taken (ms)": "47.01",
419
+ "executions per sec": "21.27",
420
+ "sample deviation": "0.00"
421
+ }
422
+ ],
423
+ "testName": "stack"
424
+ },
425
+ "trie": {
426
+ "benchmarks": [
427
+ {
428
+ "test name": "100,000 push",
429
+ "time taken (ms)": "45.97",
430
+ "executions per sec": "21.76",
431
+ "sample deviation": "0.00"
432
+ },
433
+ {
434
+ "test name": "100,000 getWords",
435
+ "time taken (ms)": "66.20",
436
+ "executions per sec": "15.11",
437
+ "sample deviation": "0.00"
438
+ }
439
+ ],
440
+ "testName": "trie"
18
441
  }
19
442
  }
@@ -441,11 +441,12 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
441
441
  [Symbol.iterator](node?: N | null | undefined): Generator<BTNKey, void, undefined>;
442
442
  /**
443
443
  * The `print` function is used to display a binary tree structure in a visually appealing way.
444
- * @param {N | null | undefined} root - The `root` parameter is of type `BTNKey | N | null |
444
+ * @param {N | null | undefined} beginRoot - The `root` parameter is of type `BTNKey | N | null |
445
445
  * undefined`. It represents the root node of a binary tree. The root node can have one of the
446
446
  * following types:
447
447
  */
448
448
  print(beginRoot?: BTNKey | N | null | undefined): void;
449
+ protected _displayAux(node: N | null | undefined): [string[], number, number, number];
449
450
  protected _defaultOneParamCallback: (node: N) => number;
450
451
  /**
451
452
  * Swap the data of two nodes in the binary tree.
@@ -1447,7 +1447,7 @@ class BinaryTree {
1447
1447
  }
1448
1448
  /**
1449
1449
  * The `print` function is used to display a binary tree structure in a visually appealing way.
1450
- * @param {N | null | undefined} root - The `root` parameter is of type `BTNKey | N | null |
1450
+ * @param {N | null | undefined} beginRoot - The `root` parameter is of type `BTNKey | N | null |
1451
1451
  * undefined`. It represents the root node of a binary tree. The root node can have one of the
1452
1452
  * following types:
1453
1453
  */
@@ -1456,57 +1456,40 @@ class BinaryTree {
1456
1456
  if (!beginRoot)
1457
1457
  return;
1458
1458
  const display = (root) => {
1459
- const [lines, , ,] = _displayAux(root);
1459
+ const [lines, , ,] = this._displayAux(root);
1460
1460
  for (const line of lines) {
1461
1461
  console.log(line);
1462
1462
  }
1463
1463
  };
1464
- const _displayAux = (node) => {
1465
- if (!this.isRealNode(node)) {
1466
- return [[], 0, 0, 0];
1467
- }
1468
- if (this.isRealNode(node) && !this.isRealNode(node.right) && !this.isRealNode(node.left)) {
1469
- const line = `${node.key}`;
1470
- const width = line.length;
1471
- const height = 1;
1472
- const middle = Math.floor(width / 2);
1473
- return [[line], width, height, middle];
1474
- }
1475
- if (this.isRealNode(node) && !this.isRealNode(node.right)) {
1476
- const [lines, n, p, x] = _displayAux(node.left);
1477
- const s = `${node.key}`;
1478
- const u = s.length;
1479
- const first_line = ' '.repeat(x + 1) + '_'.repeat(n - x - 1) + s;
1480
- const second_line = ' '.repeat(x) + '/' + ' '.repeat(n - x - 1 + u);
1481
- const shifted_lines = lines.map(line => line + ' '.repeat(u));
1482
- return [[first_line, second_line, ...shifted_lines], n + u, p + 2, n + Math.floor(u / 2)];
1483
- }
1484
- if (this.isRealNode(node) && !this.isRealNode(node.left)) {
1485
- const [lines, n, p, u] = _displayAux(node.right);
1486
- const s = `${node.key}`;
1487
- const x = s.length;
1488
- const first_line = s + '_'.repeat(x) + ' '.repeat(n - x);
1489
- const second_line = ' '.repeat(u + x) + '\\' + ' '.repeat(n - x - 1);
1490
- const shifted_lines = lines.map(line => ' '.repeat(u) + line);
1491
- return [[first_line, second_line, ...shifted_lines], n + x, p + 2, Math.floor(u / 2)];
1492
- }
1493
- const [left, n, p, x] = _displayAux(node.left);
1494
- const [right, m, q, y] = _displayAux(node.right);
1495
- const s = `${node.key}`;
1496
- const u = s.length;
1497
- const first_line = ' '.repeat(x + 1) + '_'.repeat(n - x - 1) + s + '_'.repeat(y) + ' '.repeat(m - y);
1498
- const second_line = ' '.repeat(x) + '/' + ' '.repeat(n - x - 1 + u + y) + '\\' + ' '.repeat(m - y - 1);
1499
- if (p < q) {
1500
- left.push(...new Array(q - p).fill(' '.repeat(n)));
1501
- }
1502
- else if (q < p) {
1503
- right.push(...new Array(p - q).fill(' '.repeat(m)));
1504
- }
1505
- const zipped_lines = left.map((a, i) => a + ' '.repeat(u) + right[i]);
1506
- return [[first_line, second_line, ...zipped_lines], n + m + u, Math.max(p, q) + 2, n + Math.floor(u / 2)];
1507
- };
1508
1464
  display(beginRoot);
1509
1465
  }
1466
+ _displayAux(node) {
1467
+ if (!node) {
1468
+ return [['─'], 1, 0, 0];
1469
+ }
1470
+ const line = node.key.toString();
1471
+ const width = line.length;
1472
+ if (!node.left && !node.right) {
1473
+ return [[line], width, 1, Math.floor(width / 2)];
1474
+ }
1475
+ const [leftLines, leftWidth, leftHeight, leftMiddle] = node.left ? this._displayAux(node.left) : [[''], 0, 0, 0];
1476
+ const [rightLines, rightWidth, rightHeight, rightMiddle] = node.right ? this._displayAux(node.right) : [[''], 0, 0, 0];
1477
+ const firstLine = ' '.repeat(Math.max(0, leftMiddle + 1))
1478
+ + '_'.repeat(Math.max(0, leftWidth - leftMiddle - 1))
1479
+ + line
1480
+ + '_'.repeat(Math.max(0, rightMiddle))
1481
+ + ' '.repeat(Math.max(0, rightWidth - rightMiddle));
1482
+ const secondLine = (leftHeight > 0 ? ' '.repeat(leftMiddle) + '/' + ' '.repeat(leftWidth - leftMiddle - 1) : ' '.repeat(leftWidth))
1483
+ + ' '.repeat(width)
1484
+ + (rightHeight > 0 ? ' '.repeat(rightMiddle) + '\\' + ' '.repeat(rightWidth - rightMiddle - 1) : ' '.repeat(rightWidth));
1485
+ const mergedLines = [firstLine, secondLine];
1486
+ for (let i = 0; i < Math.max(leftHeight, rightHeight); i++) {
1487
+ const leftLine = i < leftHeight ? leftLines[i] : ' '.repeat(leftWidth);
1488
+ const rightLine = i < rightHeight ? rightLines[i] : ' '.repeat(rightWidth);
1489
+ mergedLines.push(leftLine + ' '.repeat(width) + rightLine);
1490
+ }
1491
+ return [mergedLines, leftWidth + width + rightWidth, Math.max(leftHeight, rightHeight) + 2, leftWidth + Math.floor(width / 2)];
1492
+ }
1510
1493
  /**
1511
1494
  * Swap the data of two nodes in the binary tree.
1512
1495
  * @param {N} srcNode - The source node to swap.