[graph] use 'Set' in dfs instead of 'Map'

This commit is contained in:
Revone 2023-11-04 15:47:24 +08:00
parent 0ecc163944
commit 025a90a145
6 changed files with 66 additions and 63 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.41.5](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
## [v1.41.7](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
### Changes

View file

@ -658,37 +658,37 @@ 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><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000 add randomly</td><td>2.21</td><td>451.50</td><td>24</td><td>0.00</td><td>9.12e-5</td></tr><tr><td>1000 add & delete randomly</td><td>5.02</td><td>199.23</td><td>11</td><td>0.01</td><td>6.31e-4</td></tr><tr><td>1000 addMany</td><td>2.96</td><td>338.41</td><td>18</td><td>0.00</td><td>2.09e-4</td></tr><tr><td>1000 get</td><td>2.00</td><td>499.79</td><td>26</td><td>0.00</td><td>1.89e-4</td></tr></table></div>
<div class="content"><table><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000 add randomly</td><td>2.28</td><td>438.38</td><td>23</td><td>0.00</td><td>2.56e-5</td></tr><tr><td>1000 add & delete randomly</td><td>5.16</td><td>193.94</td><td>11</td><td>0.01</td><td>7.96e-4</td></tr><tr><td>1000 addMany</td><td>3.05</td><td>328.30</td><td>17</td><td>0.00</td><td>3.13e-4</td></tr><tr><td>1000 get</td><td>2.08</td><td>480.72</td><td>25</td><td>0.00</td><td>9.01e-5</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><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000 add randomly</td><td>12.95</td><td>77.23</td><td>5</td><td>0.01</td><td>1.82e-4</td></tr><tr><td>1000 add & delete randomly</td><td>15.94</td><td>62.73</td><td>4</td><td>0.02</td><td>1.95e-4</td></tr><tr><td>1000 addMany</td><td>10.81</td><td>92.48</td><td>5</td><td>0.01</td><td>5.30e-4</td></tr><tr><td>1000 get</td><td>18.16</td><td>55.07</td><td>3</td><td>0.02</td><td>2.99e-4</td></tr><tr><td>1000 dfs</td><td>69.52</td><td>14.38</td><td>1</td><td>0.07</td><td>0.00</td></tr><tr><td>1000 bfs</td><td>54.84</td><td>18.24</td><td>1</td><td>0.05</td><td>7.36e-4</td></tr><tr><td>1000 morris</td><td>38.26</td><td>26.13</td><td>2</td><td>0.04</td><td>0.00</td></tr></table></div>
<div class="content"><table><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000 add randomly</td><td>12.88</td><td>77.65</td><td>5</td><td>0.01</td><td>1.17e-4</td></tr><tr><td>1000 add & delete randomly</td><td>15.95</td><td>62.70</td><td>4</td><td>0.02</td><td>1.78e-4</td></tr><tr><td>1000 addMany</td><td>10.61</td><td>94.25</td><td>5</td><td>0.01</td><td>1.16e-4</td></tr><tr><td>1000 get</td><td>18.02</td><td>55.51</td><td>3</td><td>0.02</td><td>1.59e-4</td></tr><tr><td>1000 dfs</td><td>69.95</td><td>14.30</td><td>1</td><td>0.07</td><td>6.49e-4</td></tr><tr><td>1000 bfs</td><td>54.78</td><td>18.25</td><td>1</td><td>0.05</td><td>4.98e-4</td></tr><tr><td>1000 morris</td><td>37.26</td><td>26.83</td><td>2</td><td>0.04</td><td>2.16e-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><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000 add randomly</td><td>2.22</td><td>450.51</td><td>24</td><td>0.00</td><td>6.06e-5</td></tr><tr><td>1000 add & delete randomly</td><td>5.04</td><td>198.59</td><td>11</td><td>0.01</td><td>2.52e-4</td></tr><tr><td>1000 addMany</td><td>2.14</td><td>467.96</td><td>25</td><td>0.00</td><td>6.00e-5</td></tr><tr><td>1000 get</td><td>2.06</td><td>486.16</td><td>25</td><td>0.00</td><td>1.15e-4</td></tr></table></div>
<div class="content"><table><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000 add randomly</td><td>2.02</td><td>496.10</td><td>25</td><td>0.00</td><td>1.56e-5</td></tr><tr><td>1000 add & delete randomly</td><td>4.60</td><td>217.31</td><td>12</td><td>0.00</td><td>4.43e-4</td></tr><tr><td>1000 addMany</td><td>2.23</td><td>448.71</td><td>24</td><td>0.00</td><td>2.96e-4</td></tr><tr><td>1000 get</td><td>2.09</td><td>479.52</td><td>25</td><td>0.00</td><td>1.27e-5</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><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000 addVertex</td><td>0.10</td><td>9726.70</td><td>496</td><td>1.03e-4</td><td>1.60e-6</td></tr><tr><td>1000 addEdge</td><td>6.23</td><td>160.46</td><td>9</td><td>0.01</td><td>5.60e-4</td></tr><tr><td>1000 getVertex</td><td>0.05</td><td>2.17e+4</td><td>1097</td><td>4.61e-5</td><td>3.68e-7</td></tr><tr><td>1000 getEdge</td><td>23.53</td><td>42.49</td><td>3</td><td>0.02</td><td>0.00</td></tr><tr><td>tarjan</td><td>216.40</td><td>4.62</td><td>1</td><td>0.22</td><td>0.01</td></tr><tr><td>tarjan all</td><td>218.57</td><td>4.58</td><td>1</td><td>0.22</td><td>0.00</td></tr><tr><td>topologicalSort</td><td>186.63</td><td>5.36</td><td>1</td><td>0.19</td><td>0.03</td></tr></table></div>
<div class="content"><table><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000 addVertex</td><td>0.10</td><td>9871.96</td><td>501</td><td>1.01e-4</td><td>7.32e-7</td></tr><tr><td>1000 addEdge</td><td>6.48</td><td>154.29</td><td>9</td><td>0.01</td><td>0.00</td></tr><tr><td>1000 getVertex</td><td>0.05</td><td>2.17e+4</td><td>1110</td><td>4.61e-5</td><td>3.80e-7</td></tr><tr><td>1000 getEdge</td><td>24.65</td><td>40.57</td><td>3</td><td>0.02</td><td>0.01</td></tr><tr><td>tarjan</td><td>208.00</td><td>4.81</td><td>1</td><td>0.21</td><td>0.01</td></tr><tr><td>tarjan all</td><td>212.97</td><td>4.70</td><td>1</td><td>0.21</td><td>0.00</td></tr><tr><td>topologicalSort</td><td>171.49</td><td>5.83</td><td>1</td><td>0.17</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'>heap</span></div>
<div class="content"><table><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000 add & pop</td><td>0.34</td><td>2927.03</td><td>149</td><td>3.42e-4</td><td>3.47e-6</td></tr><tr><td>1000 fib add & pop</td><td>3.91</td><td>255.63</td><td>13</td><td>0.00</td><td>4.55e-5</td></tr></table></div>
<div class="content"><table><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000 add & pop</td><td>0.34</td><td>2929.81</td><td>149</td><td>3.41e-4</td><td>2.37e-6</td></tr><tr><td>1000 fib add & pop</td><td>3.89</td><td>257.31</td><td>14</td><td>0.00</td><td>2.53e-5</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><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000000 unshift</td><td>200.25</td><td>4.99</td><td>1</td><td>0.20</td><td>0.03</td></tr><tr><td>1000000 unshift & shift</td><td>183.25</td><td>5.46</td><td>1</td><td>0.18</td><td>0.05</td></tr><tr><td>1000 insertBefore</td><td>0.03</td><td>3.64e+4</td><td>2005</td><td>2.75e-5</td><td>8.47e-7</td></tr></table></div>
<div class="content"><table><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000000 unshift</td><td>212.40</td><td>4.71</td><td>1</td><td>0.21</td><td>0.02</td></tr><tr><td>1000000 unshift & shift</td><td>172.94</td><td>5.78</td><td>1</td><td>0.17</td><td>0.03</td></tr><tr><td>1000 insertBefore</td><td>0.03</td><td>3.70e+4</td><td>1903</td><td>2.71e-5</td><td>2.38e-6</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><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000 push & pop</td><td>1.79</td><td>558.34</td><td>30</td><td>0.00</td><td>6.00e-5</td></tr><tr><td>1000 insertBefore</td><td>2.40</td><td>417.00</td><td>22</td><td>0.00</td><td>3.01e-4</td></tr></table></div>
<div class="content"><table><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000 push & pop</td><td>1.75</td><td>571.73</td><td>30</td><td>0.00</td><td>5.06e-5</td></tr><tr><td>1000 insertBefore</td><td>2.30</td><td>434.82</td><td>22</td><td>0.00</td><td>5.10e-5</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><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>10000 refill & poll</td><td>11.77</td><td>84.98</td><td>5</td><td>0.01</td><td>0.00</td></tr></table></div>
<div class="content"><table><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>10000 refill & poll</td><td>11.41</td><td>87.65</td><td>5</td><td>0.01</td><td>1.49e-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><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000000 push</td><td>224.48</td><td>4.45</td><td>1</td><td>0.22</td><td>0.03</td></tr><tr><td>1000000 shift</td><td>27.21</td><td>36.76</td><td>3</td><td>0.03</td><td>0.00</td></tr></table></div>
<div class="content"><table><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000000 push</td><td>212.51</td><td>4.71</td><td>1</td><td>0.21</td><td>0.06</td></tr><tr><td>1000000 shift</td><td>24.98</td><td>40.04</td><td>3</td><td>0.02</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><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000000 push</td><td>46.46</td><td>21.52</td><td>2</td><td>0.05</td><td>0.01</td></tr><tr><td>1000000 push & shift</td><td>78.88</td><td>12.68</td><td>1</td><td>0.08</td><td>0.00</td></tr></table></div>
<div class="content"><table><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1000000 push</td><td>41.97</td><td>23.83</td><td>2</td><td>0.04</td><td>0.01</td></tr><tr><td>1000000 push & shift</td><td>79.08</td><td>12.65</td><td>1</td><td>0.08</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><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>100000 push</td><td>54.62</td><td>18.31</td><td>1</td><td>0.05</td><td>9.87e-4</td></tr><tr><td>100000 getWords</td><td>89.26</td><td>11.20</td><td>1</td><td>0.09</td><td>0.00</td></tr></table></div>
<div class="content"><table><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>executed times</th><th>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>100000 push</td><td>54.24</td><td>18.44</td><td>1</td><td>0.05</td><td>7.00e-4</td></tr><tr><td>100000 getWords</td><td>96.12</td><td>10.40</td><td>1</td><td>0.10</td><td>0.00</td></tr></table></div>
</div>
[//]: # (End of Replace Section)

50
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "data-structure-typed",
"version": "1.41.3",
"version": "1.41.6",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "data-structure-typed",
"version": "1.41.3",
"version": "1.41.6",
"license": "MIT",
"devDependencies": {
"@types/benchmark": "^2.1.3",
@ -16,10 +16,10 @@
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"auto-changelog": "^2.4.0",
"avl-tree-typed": "^1.41.2",
"avl-tree-typed": "^1.41.6",
"benchmark": "^2.1.4",
"binary-tree-typed": "^1.41.2",
"bst-typed": "^1.41.2",
"binary-tree-typed": "^1.41.6",
"bst-typed": "^1.41.6",
"dependency-cruiser": "^14.1.0",
"eslint": "^8.50.0",
"eslint-config-prettier": "^9.0.0",
@ -27,7 +27,7 @@
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.28.1",
"fast-glob": "^3.3.1",
"heap-typed": "^1.41.2",
"heap-typed": "^1.41.6",
"istanbul-badges-readme": "^1.8.5",
"jest": "^29.7.0",
"prettier": "^3.0.3",
@ -2789,12 +2789,12 @@
}
},
"node_modules/avl-tree-typed": {
"version": "1.41.2",
"resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.41.2.tgz",
"integrity": "sha512-J3g1PuuxJdun24hgOgSvFwbOu3xykqabTRGRd78IU9yZBBVNNVTZ+oJkNR5OYWG3bgPhcv5x8dHbWsHi3S5QGQ==",
"version": "1.41.6",
"resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.41.6.tgz",
"integrity": "sha512-r7XvaFjgHKR1P/7YD8vC11p4MHgiDVzMU1vmIcQ44q0wxXkQ/YIncJhUSa7oM6PZpSoPRLk33wPpY3+1AUrnKQ==",
"dev": true,
"dependencies": {
"data-structure-typed": "^1.41.2"
"data-structure-typed": "^1.41.6"
}
},
"node_modules/babel-jest": {
@ -2988,12 +2988,12 @@
}
},
"node_modules/binary-tree-typed": {
"version": "1.41.2",
"resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.41.2.tgz",
"integrity": "sha512-x0nOUvCEWNpJsQXqXbEoGuVFt2dFpL/vRi8xny/sqvqeygDv/Vsw4puoLBXFd+UfmZN3Q/KBULHoy6pKTaXBqw==",
"version": "1.41.6",
"resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.41.6.tgz",
"integrity": "sha512-B9FnRYxDIibvnKFnkm+zNwI62AwOPXMv0gQtAI6mvxuBYPUhy8tGGc5bZnQCisT/KFfrWwUj/1T72kgmyl4h1Q==",
"dev": true,
"dependencies": {
"data-structure-typed": "^1.41.2"
"data-structure-typed": "^1.41.6"
}
},
"node_modules/brace-expansion": {
@ -3072,12 +3072,12 @@
}
},
"node_modules/bst-typed": {
"version": "1.41.2",
"resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.41.2.tgz",
"integrity": "sha512-94a99sgCzWYddsHTPQaB3LzQeEGbQWnte/Wg6EMccH6Dpt42FJMXMQMP6N+3Y373wSppI804kN58EKWemo+4xA==",
"version": "1.41.6",
"resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.41.6.tgz",
"integrity": "sha512-GSiJ4JbszYhthcfPpu7+jyXNGzs94Il2111v94s288scZvvRCNjw7cBNUPScf2yAHJ6t4GMlz+ikPu4apoyA5g==",
"dev": true,
"dependencies": {
"data-structure-typed": "^1.41.2"
"data-structure-typed": "^1.41.6"
}
},
"node_modules/buffer-from": {
@ -3480,9 +3480,9 @@
}
},
"node_modules/data-structure-typed": {
"version": "1.41.2",
"resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.41.2.tgz",
"integrity": "sha512-NqySco4pSZWLD1Y277AxTU+lJgiVIlkGkFSLdMRyYGsWcMCYlqmu2pryzm4E2jgI6FFzIgVqA6FBSTQKmxNchw==",
"version": "1.41.6",
"resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.41.6.tgz",
"integrity": "sha512-Yi7Kj5wQtjo/h6vE40dMOOma7BHc5ob3/Y6z0N3+zQjUpTUkYBN5jKl24RhxYVfWBCvWrK434prrxVMonwo0BA==",
"dev": true
},
"node_modules/debug": {
@ -4847,12 +4847,12 @@
}
},
"node_modules/heap-typed": {
"version": "1.41.2",
"resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.41.2.tgz",
"integrity": "sha512-fDLjM5HJOqGFS52LJYOh3t5dUebh1ZPdRW83gtgqx3xfV1lVfM0RRFLFMJZ3OAqDVwE3XxKlUirOIfIL/Xfe9Q==",
"version": "1.41.6",
"resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.41.6.tgz",
"integrity": "sha512-rrquP8vWOgEGWmF8aUmpYKKwFFu3+mk0eH0kwvlQr/dUybuHXf+JwzjBY9kvtaW1IuP8zhK9kK31mTPTjGs/Zw==",
"dev": true,
"dependencies": {
"data-structure-typed": "^1.41.2"
"data-structure-typed": "^1.41.6"
}
},
"node_modules/html-escaper": {

View file

@ -1,6 +1,6 @@
{
"name": "data-structure-typed",
"version": "1.41.6",
"version": "1.41.7",
"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",
@ -64,10 +64,10 @@
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"auto-changelog": "^2.4.0",
"avl-tree-typed": "^1.41.2",
"avl-tree-typed": "^1.41.6",
"benchmark": "^2.1.4",
"binary-tree-typed": "^1.41.2",
"bst-typed": "^1.41.2",
"binary-tree-typed": "^1.41.6",
"bst-typed": "^1.41.6",
"dependency-cruiser": "^14.1.0",
"eslint": "^8.50.0",
"eslint-config-prettier": "^9.0.0",
@ -75,7 +75,7 @@
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.28.1",
"fast-glob": "^3.3.1",
"heap-typed": "^1.41.2",
"heap-typed": "^1.41.6",
"istanbul-badges-readme": "^1.8.5",
"jest": "^29.7.0",
"prettier": "^3.0.3",

View file

@ -233,8 +233,8 @@ export abstract class AbstractGraph<
return [];
}
const dfs = (cur: VO, dest: VO, visiting: Map<VO, boolean>, path: VO[]) => {
visiting.set(cur, true);
const dfs = (cur: VO, dest: VO, visiting: Set<VO>, path: VO[]) => {
visiting.add(cur);
if (cur === dest) {
paths.push([vertex1, ...path]);
@ -242,17 +242,17 @@ export abstract class AbstractGraph<
const neighbors = this.getNeighbors(cur);
for (const neighbor of neighbors) {
if (!visiting.get(neighbor)) {
if (!visiting.has(neighbor)) {
path.push(neighbor);
dfs(neighbor, dest, visiting, path);
arrayRemove(path, (vertex: VO) => vertex === neighbor);
path.pop();
}
}
visiting.set(cur, false);
visiting.delete(cur);
};
dfs(vertex1, vertex2, new Map<VO, boolean>(), []);
dfs(vertex1, vertex2, new Set<VO>(), []);
return paths;
}

View file

@ -1,6 +1,6 @@
import {UndirectedEdge, UndirectedGraph, UndirectedVertex} from '../../../../src';
import saltyVertexes from './SaltyGateStreetIntersections.json';
import saltyEdges from './SaltyGateStreetConnections.json';
import saltyVertexes from './salty-vertexes.json';
import saltyEdges from './salty-edges.json';
describe('UndirectedGraph Operation Test', () => {
let graph: UndirectedGraph;
@ -149,17 +149,20 @@ describe('UndirectedGraph', () => {
expect(degreeOfC).toBe(1);
});
// it('xxx', () => {
// const start = performance.now();
// const graph = new UndirectedGraph<{ fromFeatureId: number; name: string; parentName: string; distanceFromParent: number; coordinates: number[]; }, number >()
// for (const v of saltyVertexes) {
// graph.addVertex(v.name, v);
// }
// for (const e of saltyEdges) {
// const [s,d] = e;
// graph.addEdge( s.name, d.name, d.distanceFromParent );
// }
// const result = graph.getAllPathsBetween('Intersection_1','Intersection_5');
// console.log('---xxx', performance.now() - start, result)
// })
it('xxx', () => {
// const start = performance.now();
const graph = new UndirectedGraph<{ name: string }, number >()
for (const v of saltyVertexes) {
graph.addVertex(v.name, v);
}
for (const e of saltyEdges) {
const [s,d] = e;
graph.addEdge( s.name, d.name, d.weight );
}
// const result = graph.getAllPathsBetween('Intersection_1','Intersection_5');
// console.log('---xxx', performance.now() - start, result)
// const result = graph.dijkstra('Intersection_1','Intersection_5', true, true);
// console.log('---xxx', performance.now() - start, result)
})
});