data-structure-typed 1.46.7 → 1.46.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 +140 -110
- package/benchmark/report.html +1 -46
- package/benchmark/report.json +11 -422
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +4 -2
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +10 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +19 -13
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +121 -55
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +10 -9
- package/dist/cjs/data-structures/binary-tree/bst.js +16 -14
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +7 -5
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +32 -23
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +5 -3
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +11 -2
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/cjs/types/common.d.ts +5 -4
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +3 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -6
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +2 -1
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +2 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +2 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +4 -2
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +11 -0
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +19 -13
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +122 -55
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +10 -9
- package/dist/mjs/data-structures/binary-tree/bst.js +17 -14
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +7 -5
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +34 -24
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +5 -3
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +12 -2
- package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/mjs/types/common.d.ts +5 -4
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -1
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +3 -1
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +0 -6
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +2 -1
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +2 -1
- package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +2 -1
- package/dist/umd/data-structure-typed.js +198 -103
- package/dist/umd/data-structure-typed.min.js +4 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +7 -6
- package/src/data-structures/binary-tree/avl-tree.ts +17 -5
- package/src/data-structures/binary-tree/binary-tree.ts +143 -62
- package/src/data-structures/binary-tree/bst.ts +23 -19
- package/src/data-structures/binary-tree/rb-tree.ts +38 -27
- package/src/data-structures/binary-tree/tree-multimap.ts +19 -6
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/common.ts +2 -5
- package/src/types/data-structures/binary-tree/avl-tree.ts +5 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +5 -7
- package/src/types/data-structures/binary-tree/bst.ts +3 -1
- package/src/types/data-structures/binary-tree/rb-tree.ts +3 -1
- package/src/types/data-structures/binary-tree/tree-multimap.ts +3 -1
- package/test/integration/index.html +30 -28
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +7 -0
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +57 -1
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +62 -7
- package/test/unit/data-structures/binary-tree/bst.test.ts +56 -1
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +98 -42
- package/tsconfig-base.json +2 -1
package/benchmark/report.json
CHANGED
|
@@ -1,442 +1,31 @@
|
|
|
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
2
|
"rb-tree": {
|
|
108
3
|
"benchmarks": [
|
|
109
4
|
{
|
|
110
5
|
"test name": "100,000 add",
|
|
111
|
-
"time taken (ms)": "
|
|
112
|
-
"executions per sec": "
|
|
6
|
+
"time taken (ms)": "77.77",
|
|
7
|
+
"executions per sec": "12.86",
|
|
113
8
|
"sample deviation": "0.00"
|
|
114
9
|
},
|
|
115
10
|
{
|
|
116
11
|
"test name": "100,000 add & delete randomly",
|
|
117
|
-
"time taken (ms)": "
|
|
118
|
-
"executions per sec": "4.
|
|
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
|
-
},
|
|
218
|
-
"hash-map": {
|
|
219
|
-
"benchmarks": [
|
|
220
|
-
{
|
|
221
|
-
"test name": "1,000,000 set",
|
|
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",
|
|
242
|
-
"sample deviation": "0.02"
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
"test name": "1,000,000 Map set & get",
|
|
246
|
-
"time taken (ms)": "274.99",
|
|
247
|
-
"executions per sec": "3.64",
|
|
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"
|
|
273
|
-
}
|
|
274
|
-
],
|
|
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",
|
|
12
|
+
"time taken (ms)": "210.72",
|
|
13
|
+
"executions per sec": "4.75",
|
|
329
14
|
"sample deviation": "0.01"
|
|
330
15
|
},
|
|
331
16
|
{
|
|
332
|
-
"test name": "
|
|
333
|
-
"time taken (ms)": "
|
|
334
|
-
"executions per sec": "
|
|
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",
|
|
17
|
+
"test name": "100,000 getNode",
|
|
18
|
+
"time taken (ms)": "68.17",
|
|
19
|
+
"executions per sec": "14.67",
|
|
357
20
|
"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
21
|
},
|
|
382
22
|
{
|
|
383
|
-
"test name": "
|
|
384
|
-
"time taken (ms)": "
|
|
385
|
-
"executions per sec": "
|
|
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",
|
|
23
|
+
"test name": "100,000 add && iterator",
|
|
24
|
+
"time taken (ms)": "113.76",
|
|
25
|
+
"executions per sec": "8.79",
|
|
397
26
|
"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
27
|
}
|
|
439
28
|
],
|
|
440
|
-
"testName": "
|
|
29
|
+
"testName": "rb-tree"
|
|
441
30
|
}
|
|
442
31
|
}
|
|
@@ -6,14 +6,15 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import { BST, BSTNode } from './bst';
|
|
9
|
-
import type { AVLTreeNodeNested, AVLTreeOptions, BiTreeDeleteResult, BTNKey } from '../../types';
|
|
9
|
+
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BiTreeDeleteResult, BTNKey } from '../../types';
|
|
10
10
|
import { BTNCallback } from '../../types';
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
12
12
|
export declare class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNested<V>> extends BSTNode<V, N> {
|
|
13
13
|
height: number;
|
|
14
14
|
constructor(key: BTNKey, value?: V);
|
|
15
15
|
}
|
|
16
|
-
export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTreeNodeNested<V>>> extends BST<V, N> implements IBinaryTree<V, N> {
|
|
16
|
+
export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTreeNodeNested<V>>, TREE extends AVLTree<V, N, TREE> = AVLTree<V, N, AVLTreeNested<V, N>>> extends BST<V, N, TREE> implements IBinaryTree<V, N, TREE> {
|
|
17
|
+
options: AVLTreeOptions;
|
|
17
18
|
/**
|
|
18
19
|
* This is a constructor function for an AVL tree data structure in TypeScript.
|
|
19
20
|
* @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
|
|
@@ -31,6 +32,7 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
31
32
|
* @returns a new AVLTreeNode object with the specified key and value.
|
|
32
33
|
*/
|
|
33
34
|
createNode(key: BTNKey, value?: V): N;
|
|
35
|
+
createTree(options?: AVLTreeOptions): TREE;
|
|
34
36
|
/**
|
|
35
37
|
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
36
38
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -9,6 +9,7 @@ exports.AVLTree = exports.AVLTreeNode = void 0;
|
|
|
9
9
|
* @license MIT License
|
|
10
10
|
*/
|
|
11
11
|
const bst_1 = require("./bst");
|
|
12
|
+
const types_1 = require("../../types");
|
|
12
13
|
class AVLTreeNode extends bst_1.BSTNode {
|
|
13
14
|
constructor(key, value) {
|
|
14
15
|
super(key, value);
|
|
@@ -25,6 +26,12 @@ class AVLTree extends bst_1.BST {
|
|
|
25
26
|
*/
|
|
26
27
|
constructor(options) {
|
|
27
28
|
super(options);
|
|
29
|
+
if (options) {
|
|
30
|
+
this.options = Object.assign({ iterationType: types_1.IterationType.ITERATIVE, comparator: (a, b) => a - b }, options);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
this.options = { iterationType: types_1.IterationType.ITERATIVE, comparator: (a, b) => a - b };
|
|
34
|
+
}
|
|
28
35
|
}
|
|
29
36
|
/**
|
|
30
37
|
* The function creates a new AVL tree node with the specified key and value.
|
|
@@ -38,6 +45,9 @@ class AVLTree extends bst_1.BST {
|
|
|
38
45
|
createNode(key, value) {
|
|
39
46
|
return new AVLTreeNode(key, value);
|
|
40
47
|
}
|
|
48
|
+
createTree(options) {
|
|
49
|
+
return new AVLTree(Object.assign(Object.assign({}, this.options), options));
|
|
50
|
+
}
|
|
41
51
|
/**
|
|
42
52
|
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
43
53
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avl-tree.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/avl-tree.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,+BAAqC;
|
|
1
|
+
{"version":3,"file":"avl-tree.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/avl-tree.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,+BAAqC;AAErC,uCAAyD;AAG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IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;SACzB;aAAM;YACL,IAAI,SAAS,EAAE;gBACb,IAAI,SAAS,CAAC,IAAI,KAAK,CAAC,EAAE;oBACxB,SAAS,CAAC,IAAI,GAAG,CAAC,CAAC;iBACpB;qBAAM;oBACL,SAAS,CAAC,KAAK,GAAG,CAAC,CAAC;iBACrB;aACF;SACF;QAED,IAAI,CAAC;YAAE,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC;YAAE,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC;QAC7B,IAAI,CAAC;YAAE,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;QAClB,IAAI,CAAC;YAAE,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;QAEnB,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;QACtB,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;QAC3B,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;CACF;AAraD,0BAqaC"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNKey } from '../../types';
|
|
9
|
-
import { BiTreeDeleteResult, DFSOrderPattern, FamilyPosition, IterationType } from '../../types';
|
|
9
|
+
import { BinaryTreeNested, BinaryTreePrintOptions, BiTreeDeleteResult, DFSOrderPattern, FamilyPosition, IterationType, NodeDisplayLayout } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
/**
|
|
12
12
|
* Represents a node in a binary tree.
|
|
@@ -62,8 +62,8 @@ export declare class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = Bi
|
|
|
62
62
|
* Represents a binary tree data structure.
|
|
63
63
|
* @template N - The type of the binary tree's nodes.
|
|
64
64
|
*/
|
|
65
|
-
export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>> implements IBinaryTree<V, N> {
|
|
66
|
-
|
|
65
|
+
export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>, TREE extends BinaryTree<V, N, TREE> = BinaryTree<V, N, BinaryTreeNested<V, N>>> implements IBinaryTree<V, N, TREE> {
|
|
66
|
+
options: BinaryTreeOptions;
|
|
67
67
|
/**
|
|
68
68
|
* Creates a new instance of BinaryTree.
|
|
69
69
|
* @param {BinaryTreeOptions} [options] - The options for the binary tree.
|
|
@@ -86,6 +86,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
86
86
|
* @returns {N} - The newly created BinaryTreeNode.
|
|
87
87
|
*/
|
|
88
88
|
createNode(key: BTNKey, value?: V): N;
|
|
89
|
+
createTree(options?: BinaryTreeOptions): TREE;
|
|
89
90
|
/**
|
|
90
91
|
* Time Complexity: O(n)
|
|
91
92
|
* Space Complexity: O(1)
|
|
@@ -181,7 +182,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
181
182
|
* values:
|
|
182
183
|
* @returns the height of the binary tree.
|
|
183
184
|
*/
|
|
184
|
-
getHeight(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): number;
|
|
185
|
+
getHeight(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType | undefined): number;
|
|
185
186
|
/**
|
|
186
187
|
* Time Complexity: O(n)
|
|
187
188
|
* Space Complexity: O(log n)
|
|
@@ -200,7 +201,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
200
201
|
* to calculate the minimum height of a binary tree. It can have two possible values:
|
|
201
202
|
* @returns The function `getMinHeight` returns the minimum height of a binary tree.
|
|
202
203
|
*/
|
|
203
|
-
getMinHeight(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): number;
|
|
204
|
+
getMinHeight(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType | undefined): number;
|
|
204
205
|
/**
|
|
205
206
|
* Time Complexity: O(n)
|
|
206
207
|
* Space Complexity: O(log n)
|
|
@@ -306,7 +307,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
306
307
|
* @returns The function `getLeftMost` returns the leftmost node (`N`) in the binary tree. If there
|
|
307
308
|
* is no leftmost node, it returns `null` or `undefined` depending on the input.
|
|
308
309
|
*/
|
|
309
|
-
getLeftMost(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
310
|
+
getLeftMost(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType | undefined): N | null | undefined;
|
|
310
311
|
/**
|
|
311
312
|
* Time Complexity: O(log n)
|
|
312
313
|
* Space Complexity: O(1)
|
|
@@ -326,7 +327,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
326
327
|
* @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If there
|
|
327
328
|
* is no rightmost node, it returns `null` or `undefined`, depending on the input.
|
|
328
329
|
*/
|
|
329
|
-
getRightMost(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
330
|
+
getRightMost(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType | undefined): N | null | undefined;
|
|
330
331
|
/**
|
|
331
332
|
* Time Complexity: O(n)
|
|
332
333
|
* Space Complexity: O(1)
|
|
@@ -343,7 +344,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
343
344
|
* possible values:
|
|
344
345
|
* @returns a boolean value.
|
|
345
346
|
*/
|
|
346
|
-
isSubtreeBST(beginRoot: BTNKey | N | null | undefined, iterationType?: IterationType): boolean;
|
|
347
|
+
isSubtreeBST(beginRoot: BTNKey | N | null | undefined, iterationType?: IterationType | undefined): boolean;
|
|
347
348
|
/**
|
|
348
349
|
* Time Complexity: O(n)
|
|
349
350
|
* Space Complexity: O(1)
|
|
@@ -359,7 +360,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
359
360
|
* expected to be
|
|
360
361
|
* @returns a boolean value.
|
|
361
362
|
*/
|
|
362
|
-
isBST(iterationType?: IterationType): boolean;
|
|
363
|
+
isBST(iterationType?: IterationType | undefined): boolean;
|
|
363
364
|
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
364
365
|
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
365
366
|
subTreeTraverse<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
@@ -429,6 +430,10 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
429
430
|
* by the return type of the `callback` function.
|
|
430
431
|
*/
|
|
431
432
|
morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined): ReturnType<C>[];
|
|
433
|
+
forEach(callback: (entry: [BTNKey, V | undefined], tree: typeof this) => void): void;
|
|
434
|
+
filter(predicate: (entry: [BTNKey, V | undefined], tree: typeof this) => boolean): TREE;
|
|
435
|
+
map(callback: (entry: [BTNKey, V | undefined], tree: typeof this) => V): TREE;
|
|
436
|
+
reduce<T>(callback: (accumulator: T, entry: [BTNKey, V | undefined], tree: typeof this) => T, initialValue: T): T;
|
|
432
437
|
/**
|
|
433
438
|
* The above function is an iterator for a binary tree that can be used to traverse the tree in
|
|
434
439
|
* either an iterative or recursive manner.
|
|
@@ -438,15 +443,16 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
438
443
|
* @returns The `*[Symbol.iterator]` method returns a generator object that yields the keys of the
|
|
439
444
|
* binary tree nodes in a specific order.
|
|
440
445
|
*/
|
|
441
|
-
[Symbol.iterator](node?: N | null | undefined): Generator<BTNKey, void, undefined>;
|
|
446
|
+
[Symbol.iterator](node?: N | null | undefined): Generator<[BTNKey, V | undefined], void, undefined>;
|
|
442
447
|
/**
|
|
443
448
|
* The `print` function is used to display a binary tree structure in a visually appealing way.
|
|
444
|
-
* @param {N | null | undefined} beginRoot - The `root` parameter is of type `BTNKey | N | null |
|
|
449
|
+
* @param {BTNKey | N | null | undefined} [beginRoot=this.root] - The `root` parameter is of type `BTNKey | N | null |
|
|
445
450
|
* undefined`. It represents the root node of a binary tree. The root node can have one of the
|
|
446
451
|
* following types:
|
|
452
|
+
* @param {BinaryTreePrintOptions} [options={ isShowUndefined: false, isShowNull: false, isShowRedBlackNIL: false}] - Options object that controls printing behavior. You can specify whether to display undefined, null, or sentinel nodes.
|
|
447
453
|
*/
|
|
448
|
-
print(beginRoot?: BTNKey | N | null | undefined): void;
|
|
449
|
-
protected _displayAux(node: N | null | undefined
|
|
454
|
+
print(beginRoot?: BTNKey | N | null | undefined, options?: BinaryTreePrintOptions): void;
|
|
455
|
+
protected _displayAux(node: N | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
450
456
|
protected _defaultOneParamCallback: (node: N) => number;
|
|
451
457
|
/**
|
|
452
458
|
* Swap the data of two nodes in the binary tree.
|