data-structure-typed 1.50.8 → 1.51.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 +74 -76
- package/benchmark/report.html +2 -2
- package/benchmark/report.json +15 -15
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +15 -3
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +14 -2
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +2 -2
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +11 -11
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +19 -2
- package/dist/cjs/data-structures/binary-tree/bst.js +20 -2
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +5 -5
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +42 -44
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +40 -22
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +43 -27
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +1 -1
- package/dist/cjs/data-structures/heap/heap.js +5 -5
- package/dist/cjs/types/common.d.ts +1 -1
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -4
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.js +0 -6
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +15 -3
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +14 -2
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +11 -11
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +19 -2
- package/dist/mjs/data-structures/binary-tree/bst.js +20 -2
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +5 -5
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +42 -44
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +40 -22
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +43 -27
- package/dist/mjs/data-structures/heap/heap.d.ts +1 -1
- package/dist/mjs/data-structures/heap/heap.js +5 -5
- package/dist/mjs/types/common.d.ts +1 -1
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -4
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.js +1 -5
- package/dist/umd/data-structure-typed.js +135 -97
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +7 -7
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +17 -3
- package/src/data-structures/binary-tree/binary-tree.ts +36 -24
- package/src/data-structures/binary-tree/bst.ts +32 -11
- package/src/data-structures/binary-tree/rb-tree.ts +44 -44
- package/src/data-structures/binary-tree/tree-multi-map.ts +46 -27
- package/src/data-structures/heap/heap.ts +5 -5
- package/src/types/common.ts +1 -1
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
- package/test/integration/all-in-one.test.ts +2 -2
- package/test/integration/avl-tree.test.ts +4 -4
- package/test/integration/bst.test.ts +7 -7
- package/test/integration/index.html +2 -2
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +20 -15
- package/test/performance/data-structures/binary-tree/binary-tree.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +7 -7
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +24 -24
- package/test/unit/data-structures/binary-tree/bst.test.ts +12 -12
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +25 -25
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +19 -19
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file.
|
|
|
8
8
|
- [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
|
|
9
9
|
- [`auto-changelog`](https://github.com/CookPete/auto-changelog)
|
|
10
10
|
|
|
11
|
-
## [v1.
|
|
11
|
+
## [v1.51.0](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
|
|
12
12
|
|
|
13
13
|
### Changes
|
|
14
14
|
|
package/README.md
CHANGED
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
## Why
|
|
17
17
|
|
|
18
18
|
Do you envy C++ with [STL]() (std::), Python with [collections](), and Java with [java.util]() ? Well, no need to envy
|
|
19
|
-
anymore! JavaScript and TypeScript now have [data-structure-typed]().**`Benchmark`** compared with C++ STL.
|
|
20
|
-
|
|
19
|
+
anymore! JavaScript and TypeScript now have [data-structure-typed]().**`Benchmark`** compared with C++ STL.
|
|
20
|
+
**`API standards`** aligned with ES6 and Java. **`Usability`** is comparable to Python
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
[//]: # ()
|
|
@@ -45,56 +45,56 @@ Performance surpasses that of native JS/TS
|
|
|
45
45
|
<th>Time Taken</th>
|
|
46
46
|
<th>Data Scale</th>
|
|
47
47
|
<th>Belongs To</th>
|
|
48
|
-
<th>
|
|
48
|
+
<th>big O</th>
|
|
49
49
|
</tr>
|
|
50
50
|
</thead>
|
|
51
51
|
<tbody>
|
|
52
52
|
<tr>
|
|
53
53
|
<td>Queue.push & shift</td>
|
|
54
54
|
<td>5.83 ms</td>
|
|
55
|
-
<td>
|
|
55
|
+
<td>100K</td>
|
|
56
56
|
<td>Ours</td>
|
|
57
57
|
<td>O(1)</td>
|
|
58
58
|
</tr>
|
|
59
59
|
<tr>
|
|
60
60
|
<td>Array.push & shift</td>
|
|
61
61
|
<td>2829.59 ms</td>
|
|
62
|
-
<td>
|
|
62
|
+
<td>100K</td>
|
|
63
63
|
<td>Native JS</td>
|
|
64
64
|
<td>O(n)</td>
|
|
65
65
|
</tr>
|
|
66
66
|
<tr>
|
|
67
67
|
<td>Deque.unshift & shift</td>
|
|
68
68
|
<td>2.44 ms</td>
|
|
69
|
-
<td>
|
|
69
|
+
<td>100K</td>
|
|
70
70
|
<td>Ours</td>
|
|
71
71
|
<td>O(1)</td>
|
|
72
72
|
</tr>
|
|
73
73
|
<tr>
|
|
74
74
|
<td>Array.unshift & shift</td>
|
|
75
75
|
<td>4750.37 ms</td>
|
|
76
|
-
<td>
|
|
76
|
+
<td>100K</td>
|
|
77
77
|
<td>Native JS</td>
|
|
78
78
|
<td>O(n)</td>
|
|
79
79
|
</tr>
|
|
80
80
|
<tr>
|
|
81
81
|
<td>HashMap.set</td>
|
|
82
82
|
<td>122.51 ms</td>
|
|
83
|
-
<td>
|
|
83
|
+
<td>1M</td>
|
|
84
84
|
<td>Ours</td>
|
|
85
85
|
<td>O(1)</td>
|
|
86
86
|
</tr>
|
|
87
87
|
<tr>
|
|
88
88
|
<td>Map.set</td>
|
|
89
89
|
<td>223.80 ms</td>
|
|
90
|
-
<td>
|
|
90
|
+
<td>1M</td>
|
|
91
91
|
<td>Native JS</td>
|
|
92
92
|
<td>O(1)</td>
|
|
93
93
|
</tr>
|
|
94
94
|
<tr>
|
|
95
95
|
<td>Set.add</td>
|
|
96
96
|
<td>185.06 ms</td>
|
|
97
|
-
<td>
|
|
97
|
+
<td>1M</td>
|
|
98
98
|
<td>Native JS</td>
|
|
99
99
|
<td>O(1)</td>
|
|
100
100
|
</tr>
|
|
@@ -102,9 +102,9 @@ Performance surpasses that of native JS/TS
|
|
|
102
102
|
</table>
|
|
103
103
|
|
|
104
104
|
### Conciseness and uniformity
|
|
105
|
-
In
|
|
105
|
+
In [java.utils](), you need to memorize a table for all sequential data structures(Queue, Deque, LinkedList),
|
|
106
106
|
|
|
107
|
-
<table>
|
|
107
|
+
<table style="display: table; width:100%; table-layout: fixed;">
|
|
108
108
|
<thead>
|
|
109
109
|
<tr>
|
|
110
110
|
<th>Java ArrayList</th>
|
|
@@ -141,7 +141,7 @@ In Java.utils, you need to memorize a table for all sequential data structures(Q
|
|
|
141
141
|
</tbody>
|
|
142
142
|
</table>
|
|
143
143
|
|
|
144
|
-
whereas in our data-structure-typed, you **only** need to remember four methods: `push`, `pop`, `shift`, and `unshift` for all sequential data structures.
|
|
144
|
+
whereas in our [data-structure-typed](), you **only** need to remember four methods: `push`, `pop`, `shift`, and `unshift` for all sequential data structures(Queue, Deque, DoublyLinkedList, SinglyLinkedList and Array).
|
|
145
145
|
|
|
146
146
|
## Installation and Usage
|
|
147
147
|
|
|
@@ -667,6 +667,67 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', '
|
|
|
667
667
|
</tbody>
|
|
668
668
|
</table>
|
|
669
669
|
|
|
670
|
+
## Benchmark
|
|
671
|
+
|
|
672
|
+
MacBook Pro (15-inch, 2018)
|
|
673
|
+
|
|
674
|
+
Processor 2.2 GHz 6-Core Intel Core i7
|
|
675
|
+
|
|
676
|
+
Memory 16 GB 2400 MHz DDR4
|
|
677
|
+
|
|
678
|
+
Graphics Radeon Pro 555X 4 GB
|
|
679
|
+
|
|
680
|
+
Intel UHD Graphics 630 1536 MB
|
|
681
|
+
|
|
682
|
+
macOS Big Sur
|
|
683
|
+
|
|
684
|
+
Version 11.7.9
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
[//]: # (No deletion!!! Start of Replace Section)
|
|
688
|
+
<div class="json-to-html-collapse clearfix 0">
|
|
689
|
+
<div class='collapsible level0' ><span class='json-to-html-label'>heap</span></div>
|
|
690
|
+
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>6.58</td><td>152.07</td><td>3.13e-4</td></tr><tr><td>100,000 add & poll</td><td>35.67</td><td>28.03</td><td>0.01</td></tr></table></div>
|
|
691
|
+
</div><div class="json-to-html-collapse clearfix 0">
|
|
692
|
+
<div class='collapsible level0' ><span class='json-to-html-label'>rb-tree</span></div>
|
|
693
|
+
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>55.91</td><td>17.89</td><td>0.01</td></tr><tr><td>100,000 get</td><td>125.11</td><td>7.99</td><td>0.01</td></tr><tr><td>100,000 iterator</td><td>27.97</td><td>35.76</td><td>0.01</td></tr><tr><td>100,000 add & delete orderly</td><td>125.06</td><td>8.00</td><td>0.00</td></tr><tr><td>100,000 add & delete randomly</td><td>242.78</td><td>4.12</td><td>0.01</td></tr></table></div>
|
|
694
|
+
</div><div class="json-to-html-collapse clearfix 0">
|
|
695
|
+
<div class='collapsible level0' ><span class='json-to-html-label'>queue</span></div>
|
|
696
|
+
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>44.81</td><td>22.32</td><td>0.01</td></tr><tr><td>100,000 push & shift</td><td>4.99</td><td>200.39</td><td>7.40e-4</td></tr><tr><td>Native JS Array 100,000 push & shift</td><td>2234.97</td><td>0.45</td><td>0.19</td></tr></table></div>
|
|
697
|
+
</div><div class="json-to-html-collapse clearfix 0">
|
|
698
|
+
<div class='collapsible level0' ><span class='json-to-html-label'>deque</span></div>
|
|
699
|
+
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>24.34</td><td>41.08</td><td>0.01</td></tr><tr><td>1,000,000 push & pop</td><td>31.41</td><td>31.83</td><td>0.00</td></tr><tr><td>1,000,000 push & shift</td><td>31.12</td><td>32.13</td><td>0.00</td></tr><tr><td>100,000 push & shift</td><td>3.27</td><td>306.17</td><td>2.62e-4</td></tr><tr><td>Native JS Array 100,000 push & shift</td><td>2362.95</td><td>0.42</td><td>0.12</td></tr><tr><td>100,000 unshift & shift</td><td>2.89</td><td>345.46</td><td>3.23e-4</td></tr><tr><td>Native JS Array 100,000 unshift & shift</td><td>4313.81</td><td>0.23</td><td>0.13</td></tr></table></div>
|
|
700
|
+
</div><div class="json-to-html-collapse clearfix 0">
|
|
701
|
+
<div class='collapsible level0' ><span class='json-to-html-label'>hash-map</span></div>
|
|
702
|
+
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 set</td><td>118.81</td><td>8.42</td><td>0.02</td></tr><tr><td>Native JS Map 1,000,000 set</td><td>218.24</td><td>4.58</td><td>0.02</td></tr><tr><td>Native JS Set 1,000,000 add</td><td>180.64</td><td>5.54</td><td>0.03</td></tr><tr><td>1,000,000 set & get</td><td>121.23</td><td>8.25</td><td>0.01</td></tr><tr><td>Native JS Map 1,000,000 set & get</td><td>273.71</td><td>3.65</td><td>0.01</td></tr><tr><td>Native JS Set 1,000,000 add & has</td><td>173.69</td><td>5.76</td><td>0.01</td></tr><tr><td>1,000,000 ObjKey set & get</td><td>331.89</td><td>3.01</td><td>0.04</td></tr><tr><td>Native JS Map 1,000,000 ObjKey set & get</td><td>331.49</td><td>3.02</td><td>0.05</td></tr><tr><td>Native JS Set 1,000,000 ObjKey add & has</td><td>308.15</td><td>3.25</td><td>0.04</td></tr></table></div>
|
|
703
|
+
</div><div class="json-to-html-collapse clearfix 0">
|
|
704
|
+
<div class='collapsible level0' ><span class='json-to-html-label'>trie</span></div>
|
|
705
|
+
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 push</td><td>58.78</td><td>17.01</td><td>0.02</td></tr><tr><td>100,000 getWords</td><td>95.99</td><td>10.42</td><td>0.01</td></tr></table></div>
|
|
706
|
+
</div><div class="json-to-html-collapse clearfix 0">
|
|
707
|
+
<div class='collapsible level0' ><span class='json-to-html-label'>avl-tree</span></div>
|
|
708
|
+
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 add randomly</td><td>50.17</td><td>19.93</td><td>0.01</td></tr><tr><td>10,000 get</td><td>20.86</td><td>47.94</td><td>0.00</td></tr><tr><td>10,000 add & delete randomly</td><td>79.18</td><td>12.63</td><td>0.00</td></tr><tr><td>10,000 addMany</td><td>52.92</td><td>18.90</td><td>0.00</td></tr></table></div>
|
|
709
|
+
</div><div class="json-to-html-collapse clearfix 0">
|
|
710
|
+
<div class='collapsible level0' ><span class='json-to-html-label'>binary-tree-overall</span></div>
|
|
711
|
+
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 RBTree add</td><td>5.69</td><td>175.82</td><td>5.70e-4</td></tr><tr><td>10,000 RBTree add & delete randomly</td><td>19.94</td><td>50.16</td><td>0.00</td></tr><tr><td>10,000 RBTree get</td><td>0.65</td><td>1543.77</td><td>1.81e-5</td></tr><tr><td>10,000 AVLTree add</td><td>44.46</td><td>22.49</td><td>0.00</td></tr><tr><td>10,000 AVLTree get</td><td>20.07</td><td>49.84</td><td>0.00</td></tr><tr><td>10,000 AVLTree add & delete randomly</td><td>77.29</td><td>12.94</td><td>0.01</td></tr></table></div>
|
|
712
|
+
</div><div class="json-to-html-collapse clearfix 0">
|
|
713
|
+
<div class='collapsible level0' ><span class='json-to-html-label'>directed-graph</span></div>
|
|
714
|
+
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000 addVertex</td><td>0.10</td><td>9883.75</td><td>9.48e-7</td></tr><tr><td>1,000 addEdge</td><td>6.05</td><td>165.15</td><td>1.08e-4</td></tr><tr><td>1,000 getVertex</td><td>0.05</td><td>2.15e+4</td><td>5.74e-7</td></tr><tr><td>1,000 getEdge</td><td>23.58</td><td>42.41</td><td>0.00</td></tr><tr><td>tarjan</td><td>208.84</td><td>4.79</td><td>0.01</td></tr><tr><td>topologicalSort</td><td>180.27</td><td>5.55</td><td>0.00</td></tr></table></div>
|
|
715
|
+
</div><div class="json-to-html-collapse clearfix 0">
|
|
716
|
+
<div class='collapsible level0' ><span class='json-to-html-label'>doubly-linked-list</span></div>
|
|
717
|
+
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>208.91</td><td>4.79</td><td>0.07</td></tr><tr><td>1,000,000 unshift</td><td>202.73</td><td>4.93</td><td>0.03</td></tr><tr><td>1,000,000 unshift & shift</td><td>182.70</td><td>5.47</td><td>0.06</td></tr><tr><td>1,000,000 addBefore</td><td>314.16</td><td>3.18</td><td>0.06</td></tr></table></div>
|
|
718
|
+
</div><div class="json-to-html-collapse clearfix 0">
|
|
719
|
+
<div class='collapsible level0' ><span class='json-to-html-label'>singly-linked-list</span></div>
|
|
720
|
+
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push & shift</td><td>207.94</td><td>4.81</td><td>0.05</td></tr><tr><td>10,000 push & pop</td><td>216.07</td><td>4.63</td><td>0.01</td></tr><tr><td>10,000 addBefore</td><td>246.19</td><td>4.06</td><td>0.00</td></tr></table></div>
|
|
721
|
+
</div><div class="json-to-html-collapse clearfix 0">
|
|
722
|
+
<div class='collapsible level0' ><span class='json-to-html-label'>priority-queue</span></div>
|
|
723
|
+
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>27.00</td><td>37.04</td><td>2.43e-4</td></tr><tr><td>100,000 add & poll</td><td>77.16</td><td>12.96</td><td>0.00</td></tr></table></div>
|
|
724
|
+
</div><div class="json-to-html-collapse clearfix 0">
|
|
725
|
+
<div class='collapsible level0' ><span class='json-to-html-label'>stack</span></div>
|
|
726
|
+
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>39.29</td><td>25.45</td><td>0.00</td></tr><tr><td>1,000,000 push & pop</td><td>48.05</td><td>20.81</td><td>0.00</td></tr></table></div>
|
|
727
|
+
</div>
|
|
728
|
+
|
|
729
|
+
[//]: # (No deletion!!! End of Replace Section)
|
|
730
|
+
|
|
670
731
|
## The corresponding relationships between data structures in different language standard libraries.
|
|
671
732
|
|
|
672
733
|
<table style="display: table; width:100%; table-layout: fixed;">
|
|
@@ -982,69 +1043,6 @@ concurrently.
|
|
|
982
1043
|
</tr>
|
|
983
1044
|
</table>
|
|
984
1045
|
|
|
985
|
-
## Benchmark
|
|
986
|
-
|
|
987
|
-
MacBook Pro (15-inch, 2018)
|
|
988
|
-
|
|
989
|
-
Processor 2.2 GHz 6-Core Intel Core i7
|
|
990
|
-
|
|
991
|
-
Memory 16 GB 2400 MHz DDR4
|
|
992
|
-
|
|
993
|
-
Graphics Radeon Pro 555X 4 GB
|
|
994
|
-
|
|
995
|
-
Intel UHD Graphics 630 1536 MB
|
|
996
|
-
|
|
997
|
-
macOS Big Sur
|
|
998
|
-
|
|
999
|
-
Version 11.7.9
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
[//]: # (No deletion!!! Start of Replace Section)
|
|
1003
|
-
<div class="json-to-html-collapse clearfix 0">
|
|
1004
|
-
<div class='collapsible level0' ><span class='json-to-html-label'>heap</span></div>
|
|
1005
|
-
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>6.46</td><td>154.91</td><td>3.36e-4</td></tr><tr><td>100,000 add & poll</td><td>31.62</td><td>31.62</td><td>8.04e-4</td></tr></table></div>
|
|
1006
|
-
</div><div id="json-to-html"><div class="json-to-html-collapse clearfix 0">
|
|
1007
|
-
<div class="collapsible level0"><span class="json-to-html-label">rb-tree</span></div>
|
|
1008
|
-
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tbody><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>92.86</td><td>10.77</td><td>0.00</td></tr><tr><td>100,000 get</td><td>112.39</td><td>8.90</td><td>8.37e-4</td></tr><tr><td>100,000 iterator</td><td>30.56</td><td>32.72</td><td>0.00</td></tr><tr><td>100,000 add & delete orderly</td><td>175.06</td><td>5.71</td><td>0.02</td></tr><tr><td>100,000 add & delete randomly</td><td>263.48</td><td>3.80</td><td>0.00</td></tr></tbody></table></div>
|
|
1009
|
-
</div>
|
|
1010
|
-
|
|
1011
|
-
</div><div class="json-to-html-collapse clearfix 0">
|
|
1012
|
-
<div class='collapsible level0' ><span class='json-to-html-label'>queue</span></div>
|
|
1013
|
-
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>44.07</td><td>22.69</td><td>0.01</td></tr><tr><td>100,000 push & shift</td><td>4.89</td><td>204.65</td><td>5.60e-4</td></tr><tr><td>Native JS Array 100,000 push & shift</td><td>2305.44</td><td>0.43</td><td>0.31</td></tr></table></div>
|
|
1014
|
-
</div><div class="json-to-html-collapse clearfix 0">
|
|
1015
|
-
<div class='collapsible level0' ><span class='json-to-html-label'>deque</span></div>
|
|
1016
|
-
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>24.69</td><td>40.50</td><td>0.00</td></tr><tr><td>1,000,000 push & pop</td><td>31.59</td><td>31.66</td><td>0.00</td></tr><tr><td>1,000,000 push & shift</td><td>31.17</td><td>32.09</td><td>0.00</td></tr><tr><td>100,000 push & shift</td><td>3.27</td><td>305.75</td><td>2.76e-4</td></tr><tr><td>Native JS Array 100,000 push & shift</td><td>2511.34</td><td>0.40</td><td>0.37</td></tr><tr><td>100,000 unshift & shift</td><td>2.97</td><td>336.26</td><td>2.53e-4</td></tr><tr><td>Native JS Array 100,000 unshift & shift</td><td>4097.31</td><td>0.24</td><td>0.34</td></tr></table></div>
|
|
1017
|
-
</div><div class="json-to-html-collapse clearfix 0">
|
|
1018
|
-
<div class='collapsible level0' ><span class='json-to-html-label'>hash-map</span></div>
|
|
1019
|
-
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 set</td><td>114.37</td><td>8.74</td><td>0.02</td></tr><tr><td>Native JS Map 1,000,000 set</td><td>202.67</td><td>4.93</td><td>0.00</td></tr><tr><td>Native JS Set 1,000,000 add</td><td>168.24</td><td>5.94</td><td>0.00</td></tr><tr><td>1,000,000 set & get</td><td>124.10</td><td>8.06</td><td>0.03</td></tr><tr><td>Native JS Map 1,000,000 set & get</td><td>266.46</td><td>3.75</td><td>0.01</td></tr><tr><td>Native JS Set 1,000,000 add & has</td><td>175.14</td><td>5.71</td><td>0.02</td></tr><tr><td>1,000,000 ObjKey set & get</td><td>341.26</td><td>2.93</td><td>0.05</td></tr><tr><td>Native JS Map 1,000,000 ObjKey set & get</td><td>311.60</td><td>3.21</td><td>0.04</td></tr><tr><td>Native JS Set 1,000,000 ObjKey add & has</td><td>274.81</td><td>3.64</td><td>0.03</td></tr></table></div>
|
|
1020
|
-
</div><div class="json-to-html-collapse clearfix 0">
|
|
1021
|
-
<div class='collapsible level0' ><span class='json-to-html-label'>trie</span></div>
|
|
1022
|
-
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 push</td><td>59.08</td><td>16.93</td><td>0.00</td></tr><tr><td>100,000 getWords</td><td>82.92</td><td>12.06</td><td>0.00</td></tr></table></div>
|
|
1023
|
-
</div><div class="json-to-html-collapse clearfix 0">
|
|
1024
|
-
<div class='collapsible level0' ><span class='json-to-html-label'>avl-tree</span></div>
|
|
1025
|
-
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 add randomly</td><td>48.66</td><td>20.55</td><td>0.01</td></tr><tr><td>10,000 get</td><td>19.36</td><td>51.64</td><td>2.95e-4</td></tr><tr><td>10,000 add & delete randomly</td><td>77.68</td><td>12.87</td><td>0.00</td></tr><tr><td>10,000 addMany</td><td>52.04</td><td>19.22</td><td>0.01</td></tr></table></div>
|
|
1026
|
-
</div><div class="json-to-html-collapse clearfix 0">
|
|
1027
|
-
<div class='collapsible level0' ><span class='json-to-html-label'>binary-tree-overall</span></div>
|
|
1028
|
-
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 RBTree add</td><td>8.07</td><td>123.87</td><td>8.53e-5</td></tr><tr><td>10,000 RBTree add & delete randomly</td><td>22.38</td><td>44.68</td><td>5.81e-4</td></tr><tr><td>10,000 RBTree get</td><td>0.62</td><td>1602.15</td><td>7.37e-6</td></tr><tr><td>10,000 AVLTree add</td><td>46.27</td><td>21.61</td><td>8.12e-4</td></tr><tr><td>10,000 AVLTree get</td><td>20.02</td><td>49.95</td><td>4.21e-4</td></tr><tr><td>10,000 AVLTree add & delete randomly</td><td>75.96</td><td>13.16</td><td>0.00</td></tr></table></div>
|
|
1029
|
-
</div><div class="json-to-html-collapse clearfix 0">
|
|
1030
|
-
<div class='collapsible level0' ><span class='json-to-html-label'>directed-graph</span></div>
|
|
1031
|
-
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000 addVertex</td><td>0.10</td><td>9647.19</td><td>9.43e-7</td></tr><tr><td>1,000 addEdge</td><td>6.06</td><td>164.98</td><td>1.09e-4</td></tr><tr><td>1,000 getVertex</td><td>0.05</td><td>2.17e+4</td><td>2.85e-7</td></tr><tr><td>1,000 getEdge</td><td>23.47</td><td>42.60</td><td>0.00</td></tr><tr><td>tarjan</td><td>208.86</td><td>4.79</td><td>0.01</td></tr><tr><td>topologicalSort</td><td>186.70</td><td>5.36</td><td>0.02</td></tr></table></div>
|
|
1032
|
-
</div><div class="json-to-html-collapse clearfix 0">
|
|
1033
|
-
<div class='collapsible level0' ><span class='json-to-html-label'>doubly-linked-list</span></div>
|
|
1034
|
-
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>209.57</td><td>4.77</td><td>0.06</td></tr><tr><td>1,000,000 unshift</td><td>203.85</td><td>4.91</td><td>0.03</td></tr><tr><td>1,000,000 unshift & shift</td><td>172.64</td><td>5.79</td><td>0.02</td></tr><tr><td>1,000,000 addBefore</td><td>315.26</td><td>3.17</td><td>0.08</td></tr></table></div>
|
|
1035
|
-
</div><div class="json-to-html-collapse clearfix 0">
|
|
1036
|
-
<div class='collapsible level0' ><span class='json-to-html-label'>singly-linked-list</span></div>
|
|
1037
|
-
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push & shift</td><td>218.01</td><td>4.59</td><td>0.06</td></tr><tr><td>10,000 push & pop</td><td>216.06</td><td>4.63</td><td>0.01</td></tr><tr><td>10,000 addBefore</td><td>248.62</td><td>4.02</td><td>0.01</td></tr></table></div>
|
|
1038
|
-
</div><div class="json-to-html-collapse clearfix 0">
|
|
1039
|
-
<div class='collapsible level0' ><span class='json-to-html-label'>priority-queue</span></div>
|
|
1040
|
-
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>27.52</td><td>36.34</td><td>0.00</td></tr><tr><td>100,000 add & poll</td><td>75.49</td><td>13.25</td><td>5.41e-4</td></tr></table></div>
|
|
1041
|
-
</div><div class="json-to-html-collapse clearfix 0">
|
|
1042
|
-
<div class='collapsible level0' ><span class='json-to-html-label'>stack</span></div>
|
|
1043
|
-
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>41.24</td><td>24.25</td><td>0.01</td></tr><tr><td>1,000,000 push & pop</td><td>49.67</td><td>20.13</td><td>0.01</td></tr></table></div>
|
|
1044
|
-
</div>
|
|
1045
|
-
|
|
1046
|
-
[//]: # (No deletion!!! End of Replace Section)
|
|
1047
|
-
|
|
1048
1046
|
## supported module system
|
|
1049
1047
|
|
|
1050
1048
|
Now you can use it in Node.js and browser environments
|
package/benchmark/report.html
CHANGED
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
</head>
|
|
43
43
|
<body>
|
|
44
44
|
<div id="json-to-html"><div class="json-to-html-collapse clearfix 0">
|
|
45
|
-
<div class='collapsible level0' ><span class='json-to-html-label'>
|
|
46
|
-
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>
|
|
45
|
+
<div class='collapsible level0' ><span class='json-to-html-label'>avl-tree</span></div>
|
|
46
|
+
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>459.43</td><td>2.18</td><td>0.00</td></tr><tr><td>100,000 get</td><td>319.24</td><td>3.13</td><td>0.00</td></tr><tr><td>100,000 iterator</td><td>31.27</td><td>31.98</td><td>0.00</td></tr><tr><td>100,000 add & delete orderly</td><td>711.71</td><td>1.41</td><td>0.00</td></tr><tr><td>100,000 add & delete randomly</td><td>1082.68</td><td>0.92</td><td>0.09</td></tr></table></div>
|
|
47
47
|
</div>
|
|
48
48
|
|
|
49
49
|
</div>
|
package/benchmark/report.json
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"avl-tree": {
|
|
3
3
|
"benchmarks": [
|
|
4
4
|
{
|
|
5
5
|
"test name": "100,000 add",
|
|
6
|
-
"time taken (ms)": "
|
|
7
|
-
"executions per sec": "
|
|
6
|
+
"time taken (ms)": "459.43",
|
|
7
|
+
"executions per sec": "2.18",
|
|
8
8
|
"sample deviation": "0.00"
|
|
9
9
|
},
|
|
10
10
|
{
|
|
11
11
|
"test name": "100,000 get",
|
|
12
|
-
"time taken (ms)": "
|
|
13
|
-
"executions per sec": "
|
|
14
|
-
"sample deviation": "
|
|
12
|
+
"time taken (ms)": "319.24",
|
|
13
|
+
"executions per sec": "3.13",
|
|
14
|
+
"sample deviation": "0.00"
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
"test name": "100,000 iterator",
|
|
18
|
-
"time taken (ms)": "
|
|
19
|
-
"executions per sec": "
|
|
18
|
+
"time taken (ms)": "31.27",
|
|
19
|
+
"executions per sec": "31.98",
|
|
20
20
|
"sample deviation": "0.00"
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
23
|
"test name": "100,000 add & delete orderly",
|
|
24
|
-
"time taken (ms)": "
|
|
25
|
-
"executions per sec": "
|
|
26
|
-
"sample deviation": "0.
|
|
24
|
+
"time taken (ms)": "711.71",
|
|
25
|
+
"executions per sec": "1.41",
|
|
26
|
+
"sample deviation": "0.00"
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
29
|
"test name": "100,000 add & delete randomly",
|
|
30
|
-
"time taken (ms)": "
|
|
31
|
-
"executions per sec": "
|
|
32
|
-
"sample deviation": "0.
|
|
30
|
+
"time taken (ms)": "1082.68",
|
|
31
|
+
"executions per sec": "0.92",
|
|
32
|
+
"sample deviation": "0.09"
|
|
33
33
|
}
|
|
34
34
|
],
|
|
35
|
-
"testName": "
|
|
35
|
+
"testName": "avl-tree"
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, KeyOrNodeOrEntry } from '../../types';
|
|
8
|
+
import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, IterationType, KeyOrNodeOrEntry } from '../../types';
|
|
9
9
|
import { IBinaryTree } from '../../interfaces';
|
|
10
10
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
11
11
|
export declare class AVLTreeMultiMapNode<K = any, V = any, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>> extends AVLTreeNode<K, V, NODE> {
|
|
@@ -45,7 +45,19 @@ export declare class AVLTreeMultiMap<K = any, V = any, NODE extends AVLTreeMulti
|
|
|
45
45
|
* @returns the sum of the count property of all nodes in the tree.
|
|
46
46
|
*/
|
|
47
47
|
get count(): number;
|
|
48
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Time Complexity: O(n)
|
|
50
|
+
* Space Complexity: O(1)
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* Time Complexity: O(n)
|
|
54
|
+
* Space Complexity: O(1)
|
|
55
|
+
*
|
|
56
|
+
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
57
|
+
* search.
|
|
58
|
+
* @returns the sum of the count property of all nodes in the tree.
|
|
59
|
+
*/
|
|
60
|
+
getComputedCount(): number;
|
|
49
61
|
/**
|
|
50
62
|
* The function creates a new BSTNode with the given key, value, and count.
|
|
51
63
|
* @param {K} key - The key parameter is the unique identifier for the binary tree node. It is used to
|
|
@@ -156,7 +168,7 @@ export declare class AVLTreeMultiMap<K = any, V = any, NODE extends AVLTreeMulti
|
|
|
156
168
|
* values:
|
|
157
169
|
* @returns a boolean value.
|
|
158
170
|
*/
|
|
159
|
-
perfectlyBalance(iterationType?:
|
|
171
|
+
perfectlyBalance(iterationType?: IterationType): boolean;
|
|
160
172
|
/**
|
|
161
173
|
* Time complexity: O(n)
|
|
162
174
|
* Space complexity: O(n)
|
|
@@ -54,7 +54,19 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
54
54
|
get count() {
|
|
55
55
|
return this._count;
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Time Complexity: O(n)
|
|
59
|
+
* Space Complexity: O(1)
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* Time Complexity: O(n)
|
|
63
|
+
* Space Complexity: O(1)
|
|
64
|
+
*
|
|
65
|
+
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
66
|
+
* search.
|
|
67
|
+
* @returns the sum of the count property of all nodes in the tree.
|
|
68
|
+
*/
|
|
69
|
+
getComputedCount() {
|
|
58
70
|
let sum = 0;
|
|
59
71
|
this.dfs(node => (sum += node.count));
|
|
60
72
|
return sum;
|
|
@@ -270,7 +282,7 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
270
282
|
* @returns a boolean value.
|
|
271
283
|
*/
|
|
272
284
|
perfectlyBalance(iterationType = this.iterationType) {
|
|
273
|
-
const sorted = this.dfs(node => node, '
|
|
285
|
+
const sorted = this.dfs(node => node, 'IN'), n = sorted.length;
|
|
274
286
|
if (sorted.length < 1)
|
|
275
287
|
return false;
|
|
276
288
|
this.clear();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avl-tree-multi-map.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/avl-tree-multi-map.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"avl-tree-multi-map.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/avl-tree-multi-map.ts"],"names":[],"mappings":";;;AAkBA,yCAAkD;AAElD,MAAa,mBAIX,SAAQ,sBAAuB;IAC/B;;;;;;;;;OASG;IACH,YAAY,GAAM,EAAE,KAAS,EAAE,KAAK,GAAG,CAAC;QACtC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAIV,WAAM,GAAW,CAAC,CAAC;QAH3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAID;;;OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,IAAI,KAAK,CAAC,KAAa;QACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;CACF;AAtCD,kDAsCC;AAED;;GAEG;AACH,MAAa,eAMX,SAAQ,kBAAyB;IAEjC,YAAY,uBAA+D,EAAE,EAAE,OAAmC;QAChH,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAIX,WAAM,GAAG,CAAC,CAAC;QAHnB,IAAI,oBAAoB;YAAE,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC/D,CAAC;IAID,6DAA6D;IAC7D;;;;OAIG;IACH,I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C,KAAK,CAAC;gBAC/B,QAAQ,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;gBAC/B,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;gBAEjC,OAAO,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC;gBAC3B,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;gBAC/B,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;gBAC/B,OAAO,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;YACnC,CAAC;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;;OAOG;IACgB,YAAY,CAAC,OAAa,EAAE,OAAa;QAC1D,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC9C,OAAO,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;CACF;AAtXD,0CAsXC"}
|
|
@@ -139,7 +139,7 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
139
139
|
* @returns either the node corresponding to the given key if it is a valid node key, or the key
|
|
140
140
|
* itself if it is not a valid node key.
|
|
141
141
|
*/
|
|
142
|
-
ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, iterationType?:
|
|
142
|
+
ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
143
143
|
/**
|
|
144
144
|
* The function "isNode" checks if an keyOrNodeOrEntry is an instance of the BinaryTreeNode class.
|
|
145
145
|
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V,NODE>`.
|
|
@@ -248,7 +248,7 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
248
248
|
* @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
|
|
249
249
|
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
250
250
|
*/
|
|
251
|
-
getNodeByKey(key: K, iterationType?:
|
|
251
|
+
getNodeByKey(key: K, iterationType?: IterationType): NODE | undefined;
|
|
252
252
|
get<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
253
253
|
get<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
254
254
|
get<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
@@ -1110,7 +1110,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1110
1110
|
* `false`, null or undefined
|
|
1111
1111
|
* @returns an array of values that are the return values of the callback function.
|
|
1112
1112
|
*/
|
|
1113
|
-
dfs(callback = this._defaultOneParamCallback, pattern = '
|
|
1113
|
+
dfs(callback = this._defaultOneParamCallback, pattern = 'IN', beginRoot = this.root, iterationType = 'ITERATIVE', includeNull = false) {
|
|
1114
1114
|
beginRoot = this.ensureNode(beginRoot);
|
|
1115
1115
|
if (!beginRoot)
|
|
1116
1116
|
return [];
|
|
@@ -1118,7 +1118,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1118
1118
|
if (iterationType === 'RECURSIVE') {
|
|
1119
1119
|
const _traverse = (node) => {
|
|
1120
1120
|
switch (pattern) {
|
|
1121
|
-
case '
|
|
1121
|
+
case 'IN':
|
|
1122
1122
|
if (includeNull) {
|
|
1123
1123
|
if (this.isRealNode(node) && this.isNodeOrNull(node.left))
|
|
1124
1124
|
_traverse(node.left);
|
|
@@ -1134,7 +1134,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1134
1134
|
_traverse(node.right);
|
|
1135
1135
|
}
|
|
1136
1136
|
break;
|
|
1137
|
-
case '
|
|
1137
|
+
case 'PRE':
|
|
1138
1138
|
if (includeNull) {
|
|
1139
1139
|
this.isNodeOrNull(node) && ans.push(callback(node));
|
|
1140
1140
|
if (this.isRealNode(node) && this.isNodeOrNull(node.left))
|
|
@@ -1150,7 +1150,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1150
1150
|
_traverse(node.right);
|
|
1151
1151
|
}
|
|
1152
1152
|
break;
|
|
1153
|
-
case '
|
|
1153
|
+
case 'POST':
|
|
1154
1154
|
if (includeNull) {
|
|
1155
1155
|
if (this.isRealNode(node) && this.isNodeOrNull(node.left))
|
|
1156
1156
|
_traverse(node.left);
|
|
@@ -1190,17 +1190,17 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1190
1190
|
}
|
|
1191
1191
|
else {
|
|
1192
1192
|
switch (pattern) {
|
|
1193
|
-
case '
|
|
1193
|
+
case 'IN':
|
|
1194
1194
|
cur.node && stack.push({ opt: 0, node: cur.node.right });
|
|
1195
1195
|
stack.push({ opt: 1, node: cur.node });
|
|
1196
1196
|
cur.node && stack.push({ opt: 0, node: cur.node.left });
|
|
1197
1197
|
break;
|
|
1198
|
-
case '
|
|
1198
|
+
case 'PRE':
|
|
1199
1199
|
cur.node && stack.push({ opt: 0, node: cur.node.right });
|
|
1200
1200
|
cur.node && stack.push({ opt: 0, node: cur.node.left });
|
|
1201
1201
|
stack.push({ opt: 1, node: cur.node });
|
|
1202
1202
|
break;
|
|
1203
|
-
case '
|
|
1203
|
+
case 'POST':
|
|
1204
1204
|
stack.push({ opt: 1, node: cur.node });
|
|
1205
1205
|
cur.node && stack.push({ opt: 0, node: cur.node.right });
|
|
1206
1206
|
cur.node && stack.push({ opt: 0, node: cur.node.left });
|
|
@@ -1390,7 +1390,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1390
1390
|
* `callback` function on each node in the binary tree. The type of the array nodes is determined
|
|
1391
1391
|
* by the return type of the `callback` function.
|
|
1392
1392
|
*/
|
|
1393
|
-
morris(callback = this._defaultOneParamCallback, pattern = '
|
|
1393
|
+
morris(callback = this._defaultOneParamCallback, pattern = 'IN', beginRoot = this.root) {
|
|
1394
1394
|
beginRoot = this.ensureNode(beginRoot);
|
|
1395
1395
|
if (beginRoot === null)
|
|
1396
1396
|
return [];
|
|
@@ -1417,7 +1417,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1417
1417
|
_reverseEdge(tail);
|
|
1418
1418
|
};
|
|
1419
1419
|
switch (pattern) {
|
|
1420
|
-
case '
|
|
1420
|
+
case 'IN':
|
|
1421
1421
|
while (cur) {
|
|
1422
1422
|
if (cur.left) {
|
|
1423
1423
|
const predecessor = this.getPredecessor(cur);
|
|
@@ -1434,7 +1434,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1434
1434
|
cur = cur.right;
|
|
1435
1435
|
}
|
|
1436
1436
|
break;
|
|
1437
|
-
case '
|
|
1437
|
+
case 'PRE':
|
|
1438
1438
|
while (cur) {
|
|
1439
1439
|
if (cur.left) {
|
|
1440
1440
|
const predecessor = this.getPredecessor(cur);
|
|
@@ -1454,7 +1454,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1454
1454
|
cur = cur.right;
|
|
1455
1455
|
}
|
|
1456
1456
|
break;
|
|
1457
|
-
case '
|
|
1457
|
+
case 'POST':
|
|
1458
1458
|
while (cur) {
|
|
1459
1459
|
if (cur.left) {
|
|
1460
1460
|
const predecessor = this.getPredecessor(cur);
|