[test] null should be ignored in travesal method in BST

This commit is contained in:
Revone 2023-11-06 19:36:09 +08:00
parent 25b9e1e9e4
commit be38422de9
4 changed files with 24 additions and 14 deletions

View file

@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file.
- [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
- [`auto-changelog`](https://github.com/CookPete/auto-changelog)
## [v1.42.1](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
## [v1.42.2](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
### Changes

View file

@ -636,40 +636,40 @@ optimal approach to data structure design.
[//]: # (Start of Replace Section)
<div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>avl-tree</span></div>
<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>30.74</td><td>32.53</td><td>7.33e-4</td></tr><tr><td>10,000 add & delete randomly</td><td>67.99</td><td>14.71</td><td>0.00</td></tr><tr><td>10,000 addMany</td><td>39.82</td><td>25.11</td><td>4.59e-4</td></tr><tr><td>10,000 get</td><td>26.70</td><td>37.46</td><td>2.61e-4</td></tr></table></div>
<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>31.93</td><td>31.32</td><td>2.30e-4</td></tr><tr><td>10,000 add & delete randomly</td><td>69.12</td><td>14.47</td><td>0.00</td></tr><tr><td>10,000 addMany</td><td>41.14</td><td>24.31</td><td>1.60e-4</td></tr><tr><td>10,000 get</td><td>28.68</td><td>34.86</td><td>7.65e-4</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>binary-tree</span></div>
<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 add randomly</td><td>12.91</td><td>77.44</td><td>5.52e-4</td></tr><tr><td>1,000 add & delete randomly</td><td>15.90</td><td>62.88</td><td>1.24e-4</td></tr><tr><td>1,000 addMany</td><td>10.72</td><td>93.27</td><td>1.52e-4</td></tr><tr><td>1,000 get</td><td>18.39</td><td>54.39</td><td>2.28e-4</td></tr><tr><td>1,000 dfs</td><td>71.58</td><td>13.97</td><td>0.00</td></tr><tr><td>1,000 bfs</td><td>57.62</td><td>17.35</td><td>0.00</td></tr><tr><td>1,000 morris</td><td>37.17</td><td>26.90</td><td>2.13e-4</td></tr></table></div>
<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 add randomly</td><td>13.12</td><td>76.21</td><td>3.40e-4</td></tr><tr><td>1,000 add & delete randomly</td><td>16.33</td><td>61.22</td><td>4.17e-4</td></tr><tr><td>1,000 addMany</td><td>10.96</td><td>91.22</td><td>3.99e-4</td></tr><tr><td>1,000 get</td><td>18.65</td><td>53.63</td><td>4.20e-4</td></tr><tr><td>1,000 dfs</td><td>71.82</td><td>13.92</td><td>0.00</td></tr><tr><td>1,000 bfs</td><td>58.95</td><td>16.96</td><td>0.00</td></tr><tr><td>1,000 morris</td><td>37.46</td><td>26.70</td><td>4.60e-4</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>bst</span></div>
<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>30.50</td><td>32.79</td><td>0.00</td></tr><tr><td>10,000 add & delete randomly</td><td>68.35</td><td>14.63</td><td>8.92e-4</td></tr><tr><td>10,000 addMany</td><td>29.41</td><td>34.00</td><td>9.96e-4</td></tr><tr><td>10,000 get</td><td>28.27</td><td>35.37</td><td>5.46e-4</td></tr></table></div>
<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>32.98</td><td>30.32</td><td>0.00</td></tr><tr><td>10,000 add & delete randomly</td><td>74.47</td><td>13.43</td><td>0.00</td></tr><tr><td>10,000 addMany</td><td>29.93</td><td>33.41</td><td>6.02e-4</td></tr><tr><td>10,000 get</td><td>29.92</td><td>33.42</td><td>8.61e-4</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>rb-tree</span></div>
<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 randomly</td><td>82.19</td><td>12.17</td><td>0.01</td></tr><tr><td>100,000 add & 1000 delete randomly</td><td>99.74</td><td>10.03</td><td>0.03</td></tr><tr><td>100,000 getNode</td><td>78.27</td><td>12.78</td><td>0.04</td></tr></table></div>
<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 randomly</td><td>80.49</td><td>12.42</td><td>0.01</td></tr><tr><td>100,000 add & 1000 delete randomly</td><td>89.97</td><td>11.11</td><td>0.01</td></tr><tr><td>100,000 getNode</td><td>68.63</td><td>14.57</td><td>0.01</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>directed-graph</span></div>
<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>9687.71</td><td>1.14e-5</td></tr><tr><td>1,000 addEdge</td><td>7.42</td><td>134.68</td><td>0.00</td></tr><tr><td>1,000 getVertex</td><td>0.05</td><td>2.05e+4</td><td>9.33e-6</td></tr><tr><td>1,000 getEdge</td><td>20.29</td><td>49.29</td><td>0.00</td></tr><tr><td>tarjan</td><td>190.48</td><td>5.25</td><td>0.01</td></tr><tr><td>tarjan all</td><td>190.72</td><td>5.24</td><td>0.00</td></tr><tr><td>topologicalSort</td><td>161.21</td><td>6.20</td><td>0.02</td></tr></table></div>
<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>9878.72</td><td>1.87e-6</td></tr><tr><td>1,000 addEdge</td><td>6.34</td><td>157.78</td><td>2.53e-4</td></tr><tr><td>1,000 getVertex</td><td>0.05</td><td>2.12e+4</td><td>1.05e-6</td></tr><tr><td>1,000 getEdge</td><td>23.08</td><td>43.33</td><td>0.00</td></tr><tr><td>tarjan</td><td>217.75</td><td>4.59</td><td>0.01</td></tr><tr><td>tarjan all</td><td>219.23</td><td>4.56</td><td>0.01</td></tr><tr><td>topologicalSort</td><td>175.73</td><td>5.69</td><td>0.02</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>heap</span></div>
<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 & pop</td><td>4.70</td><td>212.55</td><td>5.89e-4</td></tr><tr><td>10,000 fib add & pop</td><td>366.96</td><td>2.73</td><td>0.02</td></tr></table></div>
<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 & pop</td><td>4.64</td><td>215.44</td><td>6.89e-5</td></tr><tr><td>10,000 fib add & pop</td><td>357.37</td><td>2.80</td><td>0.01</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>doubly-linked-list</span></div>
<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 unshift</td><td>226.42</td><td>4.42</td><td>0.04</td></tr><tr><td>1,000,000 unshift & shift</td><td>163.14</td><td>6.13</td><td>0.01</td></tr><tr><td>1,000,000 insertBefore</td><td>343.18</td><td>2.91</td><td>0.08</td></tr></table></div>
<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 unshift</td><td>239.34</td><td>4.18</td><td>0.04</td></tr><tr><td>1,000,000 unshift & shift</td><td>168.74</td><td>5.93</td><td>0.04</td></tr><tr><td>1,000,000 insertBefore</td><td>324.74</td><td>3.08</td><td>0.06</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>singly-linked-list</span></div>
<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 push & pop</td><td>217.34</td><td>4.60</td><td>0.01</td></tr><tr><td>10,000 insertBefore</td><td>248.51</td><td>4.02</td><td>0.00</td></tr></table></div>
<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 push & pop</td><td>213.86</td><td>4.68</td><td>0.01</td></tr><tr><td>10,000 insertBefore</td><td>254.02</td><td>3.94</td><td>0.02</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>max-priority-queue</span></div>
<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 refill & poll</td><td>11.65</td><td>85.81</td><td>3.52e-4</td></tr></table></div>
<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 refill & poll</td><td>11.39</td><td>87.76</td><td>2.14e-4</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>deque</span></div>
<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>224.57</td><td>4.45</td><td>0.04</td></tr><tr><td>1,000,000 shift</td><td>25.15</td><td>39.77</td><td>0.00</td></tr></table></div>
<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>233.91</td><td>4.28</td><td>0.05</td></tr><tr><td>1,000,000 shift</td><td>25.61</td><td>39.05</td><td>0.00</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>queue</span></div>
<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>43.52</td><td>22.98</td><td>0.01</td></tr><tr><td>1,000,000 push & shift</td><td>79.71</td><td>12.55</td><td>0.00</td></tr></table></div>
<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>43.88</td><td>22.79</td><td>0.01</td></tr><tr><td>1,000,000 push & shift</td><td>81.71</td><td>12.24</td><td>0.00</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>trie</span></div>
<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.28</td><td>16.87</td><td>0.00</td></tr><tr><td>100,000 getWords</td><td>106.79</td><td>9.36</td><td>0.00</td></tr></table></div>
<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.93</td><td>16.69</td><td>0.01</td></tr><tr><td>100,000 getWords</td><td>93.10</td><td>10.74</td><td>0.01</td></tr></table></div>
</div>
[//]: # (End of Replace Section)

View file

@ -1,6 +1,6 @@
{
"name": "data-structure-typed",
"version": "1.42.1",
"version": "1.42.2",
"description": "Data Structures of Javascript & TypeScript. Binary Tree, BST, Graph, Heap, Priority Queue, Linked List, Queue, Deque, Stack, AVL Tree, Tree Multiset, Trie, Directed Graph, Undirected Graph, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue.",
"main": "dist/cjs/src/index.js",
"module": "dist/mjs/src/index.js",

View file

@ -837,4 +837,14 @@ describe('BST Performance test', function () {
bst.addMany([9, 8, 7, 3, 1, 2, 5, 4, 6], undefined, false);
expect(bst.lastKey()).toBe(9);
});
it('should subTreeTraverse, null should be ignored', () => {
const bst = new BST();
bst.addMany([4, 2, 6, null, 1, 3, null, 5, null, 7]);
expect(bst.subTreeTraverse(node => node.key, bst.getNode(6), IterationType.ITERATIVE)).toEqual([6,5, 7]);
expect(bst.subTreeTraverse(node => node.key, bst.getNode(6), IterationType.RECURSIVE)).toEqual([6,5, 7]);
expect(bst.subTreeTraverse(node => node === null ? null : node.key, bst.getNode(6), IterationType.ITERATIVE, true)).toEqual([6, 5, 7]);
expect(bst.subTreeTraverse(node => node === null ? null : node.key, bst.getNode(6), IterationType.RECURSIVE, true)).toEqual([6, 5, 7]);
});
});