data-structure-typed 1.52.3 → 1.52.5
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 +2 -1
- package/README.md +13 -13
- package/README_zh-CN.md +216 -26
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +158 -158
- package/dist/cjs/data-structures/base/iterable-element-base.d.ts +1 -37
- package/dist/cjs/data-structures/base/iterable-element-base.js +1 -37
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +2 -54
- package/dist/cjs/data-structures/base/iterable-entry-base.js +1 -49
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +0 -46
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +0 -46
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +82 -147
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +299 -331
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +1 -40
- package/dist/cjs/data-structures/binary-tree/bst.js +12 -44
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +0 -48
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +2 -50
- 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 +0 -32
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +9 -41
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +0 -75
- package/dist/cjs/data-structures/graph/abstract-graph.js +0 -75
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +0 -98
- package/dist/cjs/data-structures/graph/directed-graph.js +0 -98
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +0 -50
- package/dist/cjs/data-structures/graph/undirected-graph.js +0 -50
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +5 -92
- package/dist/cjs/data-structures/hash/hash-map.js +29 -115
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +0 -32
- package/dist/cjs/data-structures/heap/heap.js +0 -32
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +5 -88
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +1 -83
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +2 -84
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +1 -35
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +1 -35
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +1 -98
- package/dist/cjs/data-structures/queue/deque.js +3 -99
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +5 -58
- package/dist/cjs/data-structures/queue/queue.js +4 -57
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +1 -34
- package/dist/cjs/data-structures/stack/stack.js +1 -34
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/tree/tree.js +0 -1
- package/dist/cjs/data-structures/tree/tree.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +0 -64
- package/dist/cjs/data-structures/trie/trie.js +0 -64
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +6 -0
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/types/utils/utils.d.ts +13 -12
- package/dist/cjs/utils/number.d.ts +13 -0
- package/dist/cjs/utils/number.js +13 -0
- package/dist/cjs/utils/number.js.map +1 -1
- package/dist/cjs/utils/utils.d.ts +125 -3
- package/dist/cjs/utils/utils.js +177 -21
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/base/iterable-element-base.d.ts +1 -37
- package/dist/mjs/data-structures/base/iterable-element-base.js +1 -37
- package/dist/mjs/data-structures/base/iterable-entry-base.d.ts +2 -54
- package/dist/mjs/data-structures/base/iterable-entry-base.js +1 -49
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +0 -46
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +0 -46
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +82 -147
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +298 -332
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +1 -40
- package/dist/mjs/data-structures/binary-tree/bst.js +12 -44
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +0 -48
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +2 -50
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +9 -41
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +0 -75
- package/dist/mjs/data-structures/graph/abstract-graph.js +0 -75
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +0 -98
- package/dist/mjs/data-structures/graph/directed-graph.js +0 -98
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +0 -50
- package/dist/mjs/data-structures/graph/undirected-graph.js +0 -50
- package/dist/mjs/data-structures/hash/hash-map.d.ts +5 -92
- package/dist/mjs/data-structures/hash/hash-map.js +29 -115
- package/dist/mjs/data-structures/heap/heap.d.ts +0 -32
- package/dist/mjs/data-structures/heap/heap.js +0 -32
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +5 -88
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +1 -83
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +2 -84
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +1 -35
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +1 -35
- package/dist/mjs/data-structures/queue/deque.d.ts +1 -98
- package/dist/mjs/data-structures/queue/deque.js +3 -99
- package/dist/mjs/data-structures/queue/queue.d.ts +5 -58
- package/dist/mjs/data-structures/queue/queue.js +4 -57
- package/dist/mjs/data-structures/stack/stack.d.ts +1 -34
- package/dist/mjs/data-structures/stack/stack.js +1 -34
- package/dist/mjs/data-structures/tree/tree.js +0 -1
- package/dist/mjs/data-structures/trie/trie.d.ts +0 -64
- package/dist/mjs/data-structures/trie/trie.js +0 -64
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +5 -1
- package/dist/mjs/types/utils/utils.d.ts +13 -12
- package/dist/mjs/utils/number.d.ts +13 -0
- package/dist/mjs/utils/number.js +13 -0
- package/dist/mjs/utils/utils.d.ts +125 -3
- package/dist/mjs/utils/utils.js +177 -21
- package/dist/umd/data-structure-typed.js +414 -1482
- package/dist/umd/data-structure-typed.min.js +5 -4
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +6 -6
- package/src/data-structures/base/iterable-element-base.ts +2 -42
- package/src/data-structures/base/iterable-entry-base.ts +3 -62
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +8 -48
- package/src/data-structures/binary-tree/avl-tree.ts +0 -57
- package/src/data-structures/binary-tree/binary-tree.ts +329 -358
- package/src/data-structures/binary-tree/bst.ts +11 -54
- package/src/data-structures/binary-tree/rb-tree.ts +2 -62
- package/src/data-structures/binary-tree/tree-multi-map.ts +8 -48
- package/src/data-structures/graph/abstract-graph.ts +0 -92
- package/src/data-structures/graph/directed-graph.ts +0 -122
- package/src/data-structures/graph/undirected-graph.ts +0 -62
- package/src/data-structures/hash/hash-map.ts +31 -139
- package/src/data-structures/heap/heap.ts +0 -40
- package/src/data-structures/linked-list/doubly-linked-list.ts +5 -112
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -104
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -44
- package/src/data-structures/queue/deque.ts +2 -125
- package/src/data-structures/queue/queue.ts +5 -72
- package/src/data-structures/stack/stack.ts +1 -43
- package/src/data-structures/tree/tree.ts +1 -1
- package/src/data-structures/trie/trie.ts +0 -80
- package/src/types/data-structures/binary-tree/binary-tree.ts +8 -1
- package/src/types/utils/utils.ts +17 -15
- package/src/utils/number.ts +13 -0
- package/src/utils/utils.ts +174 -18
- package/test/config.ts +8 -0
- package/test/integration/all-in-one.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +13 -13
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +18 -13
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +471 -64
- package/test/unit/data-structures/binary-tree/bst.test.ts +167 -23
- package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +136 -13
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +18 -13
- package/test/unit/data-structures/graph/directed-graph.test.ts +46 -32
- package/test/unit/data-structures/graph/map-graph.test.ts +24 -2
- package/test/unit/data-structures/graph/undirected-graph.test.ts +24 -24
- package/test/unit/data-structures/hash/hash-map.test.ts +225 -35
- package/test/unit/data-structures/heap/heap.test.ts +47 -39
- package/test/unit/data-structures/heap/min-heap.test.ts +5 -5
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +34 -4
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +32 -0
- package/test/unit/data-structures/matrix/matrix.test.ts +35 -5
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +31 -0
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +18 -0
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +17 -0
- package/test/unit/data-structures/queue/deque.test.ts +288 -47
- package/test/unit/data-structures/queue/queue.test.ts +62 -37
- package/test/unit/data-structures/stack/stack.test.ts +30 -5
- package/test/unit/data-structures/tree/tree.test.ts +58 -0
- package/test/unit/data-structures/trie/trie.test.ts +46 -5
- package/test/unit/utils/utils.test.ts +169 -0
package/CHANGELOG.md
CHANGED
|
@@ -8,10 +8,11 @@ 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.52.
|
|
11
|
+
## [v1.52.5](https://github.com/zrwusa/data-structure-typed/compare/v1.51.5...main) (upcoming)
|
|
12
12
|
|
|
13
13
|
### Changes
|
|
14
14
|
|
|
15
|
+
- docs(queue): fix mismatch between typings and jsdoc [`#95`](https://github.com/zrwusa/data-structure-typed/pull/95)
|
|
15
16
|
- fix(trie): trie returns invalid string when only the fist character m… [`#94`](https://github.com/zrwusa/data-structure-typed/pull/94)
|
|
16
17
|
|
|
17
18
|
## [v1.51.5](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...v1.51.5) (18 January 2024)
|
package/README.md
CHANGED
|
@@ -823,43 +823,43 @@ Version 11.7.9
|
|
|
823
823
|
[//]: # (No deletion!!! Start of Replace Section)
|
|
824
824
|
<div class="json-to-html-collapse clearfix 0">
|
|
825
825
|
<div class='collapsible level0' ><span class='json-to-html-label'>heap</span></div>
|
|
826
|
-
<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>
|
|
826
|
+
<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>7.51</td><td>133.17</td><td>1.36e-4</td></tr><tr><td>100,000 add & poll</td><td>44.25</td><td>22.60</td><td>0.00</td></tr></table></div>
|
|
827
827
|
</div><div class="json-to-html-collapse clearfix 0">
|
|
828
828
|
<div class='collapsible level0' ><span class='json-to-html-label'>rb-tree</span></div>
|
|
829
|
-
<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>
|
|
829
|
+
<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>76.98</td><td>12.99</td><td>0.00</td></tr><tr><td>100,000 add randomly</td><td>80.96</td><td>12.35</td><td>0.00</td></tr><tr><td>100,000 get</td><td>111.72</td><td>8.95</td><td>0.00</td></tr><tr><td>100,000 iterator</td><td>29.58</td><td>33.81</td><td>0.00</td></tr><tr><td>100,000 add & delete orderly</td><td>153.21</td><td>6.53</td><td>0.00</td></tr><tr><td>100,000 add & delete randomly</td><td>233.26</td><td>4.29</td><td>0.00</td></tr></table></div>
|
|
830
830
|
</div><div class="json-to-html-collapse clearfix 0">
|
|
831
831
|
<div class='collapsible level0' ><span class='json-to-html-label'>queue</span></div>
|
|
832
|
-
<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>
|
|
832
|
+
<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>42.18</td><td>23.71</td><td>0.01</td></tr><tr><td>100,000 push & shift</td><td>5.16</td><td>193.66</td><td>7.47e-4</td></tr><tr><td>Native JS Array 100,000 push & shift</td><td>2386.29</td><td>0.42</td><td>0.30</td></tr></table></div>
|
|
833
833
|
</div><div class="json-to-html-collapse clearfix 0">
|
|
834
834
|
<div class='collapsible level0' ><span class='json-to-html-label'>deque</span></div>
|
|
835
|
-
<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>
|
|
835
|
+
<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>23.59</td><td>42.40</td><td>0.00</td></tr><tr><td>1,000,000 push & pop</td><td>31.93</td><td>31.32</td><td>0.00</td></tr><tr><td>1,000,000 push & shift</td><td>33.12</td><td>30.19</td><td>0.00</td></tr><tr><td>100,000 push & shift</td><td>3.50</td><td>285.57</td><td>9.51e-4</td></tr><tr><td>Native JS Array 100,000 push & shift</td><td>2211.26</td><td>0.45</td><td>0.34</td></tr><tr><td>100,000 unshift & shift</td><td>3.41</td><td>292.89</td><td>5.52e-4</td></tr><tr><td>Native JS Array 100,000 unshift & shift</td><td>4343.81</td><td>0.23</td><td>0.25</td></tr></table></div>
|
|
836
836
|
</div><div class="json-to-html-collapse clearfix 0">
|
|
837
837
|
<div class='collapsible level0' ><span class='json-to-html-label'>hash-map</span></div>
|
|
838
|
-
<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>
|
|
838
|
+
<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>259.74</td><td>3.85</td><td>0.07</td></tr><tr><td>Native JS Map 1,000,000 set</td><td>208.35</td><td>4.80</td><td>0.02</td></tr><tr><td>Native JS Set 1,000,000 add</td><td>167.66</td><td>5.96</td><td>0.01</td></tr><tr><td>1,000,000 set & get</td><td>260.46</td><td>3.84</td><td>0.04</td></tr><tr><td>Native JS Map 1,000,000 set & get</td><td>265.09</td><td>3.77</td><td>0.02</td></tr><tr><td>Native JS Set 1,000,000 add & has</td><td>169.15</td><td>5.91</td><td>0.01</td></tr><tr><td>1,000,000 ObjKey set & get</td><td>317.23</td><td>3.15</td><td>0.04</td></tr><tr><td>Native JS Map 1,000,000 ObjKey set & get</td><td>304.84</td><td>3.28</td><td>0.04</td></tr><tr><td>Native JS Set 1,000,000 ObjKey add & has</td><td>278.30</td><td>3.59</td><td>0.05</td></tr></table></div>
|
|
839
839
|
</div><div class="json-to-html-collapse clearfix 0">
|
|
840
840
|
<div class='collapsible level0' ><span class='json-to-html-label'>trie</span></div>
|
|
841
|
-
<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>
|
|
841
|
+
<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>43.93</td><td>22.76</td><td>5.95e-4</td></tr><tr><td>100,000 getWords</td><td>82.18</td><td>12.17</td><td>0.00</td></tr></table></div>
|
|
842
842
|
</div><div class="json-to-html-collapse clearfix 0">
|
|
843
843
|
<div class='collapsible level0' ><span class='json-to-html-label'>avl-tree</span></div>
|
|
844
|
-
<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>
|
|
844
|
+
<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>275.72</td><td>3.63</td><td>0.00</td></tr><tr><td>100,000 add randomly</td><td>332.35</td><td>3.01</td><td>0.00</td></tr><tr><td>100,000 get</td><td>129.56</td><td>7.72</td><td>0.00</td></tr><tr><td>100,000 iterator</td><td>32.03</td><td>31.22</td><td>0.01</td></tr><tr><td>100,000 add & delete orderly</td><td>447.87</td><td>2.23</td><td>0.00</td></tr><tr><td>100,000 add & delete randomly</td><td>605.40</td><td>1.65</td><td>0.03</td></tr></table></div>
|
|
845
845
|
</div><div class="json-to-html-collapse clearfix 0">
|
|
846
846
|
<div class='collapsible level0' ><span class='json-to-html-label'>binary-tree-overall</span></div>
|
|
847
|
-
<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 randomly</td><td>
|
|
847
|
+
<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 randomly</td><td>6.91</td><td>144.82</td><td>1.13e-4</td></tr><tr><td>10,000 RBTree get randomly</td><td>9.08</td><td>110.14</td><td>7.72e-5</td></tr><tr><td>10,000 RBTree add & delete randomly</td><td>18.97</td><td>52.71</td><td>8.49e-4</td></tr><tr><td>10,000 AVLTree add randomly</td><td>24.97</td><td>40.05</td><td>4.34e-4</td></tr><tr><td>10,000 AVLTree get randomly</td><td>9.95</td><td>100.47</td><td>0.00</td></tr><tr><td>10,000 AVLTree add & delete randomly</td><td>45.96</td><td>21.76</td><td>5.77e-4</td></tr></table></div>
|
|
848
848
|
</div><div class="json-to-html-collapse clearfix 0">
|
|
849
849
|
<div class='collapsible level0' ><span class='json-to-html-label'>directed-graph</span></div>
|
|
850
|
-
<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.
|
|
850
|
+
<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>9730.42</td><td>1.39e-6</td></tr><tr><td>1,000 addEdge</td><td>6.01</td><td>166.32</td><td>9.47e-5</td></tr><tr><td>1,000 getVertex</td><td>0.04</td><td>2.59e+4</td><td>3.52e-7</td></tr><tr><td>1,000 getEdge</td><td>23.80</td><td>42.03</td><td>0.00</td></tr><tr><td>tarjan</td><td>215.66</td><td>4.64</td><td>0.01</td></tr><tr><td>topologicalSort</td><td>187.85</td><td>5.32</td><td>0.00</td></tr></table></div>
|
|
851
851
|
</div><div class="json-to-html-collapse clearfix 0">
|
|
852
852
|
<div class='collapsible level0' ><span class='json-to-html-label'>doubly-linked-list</span></div>
|
|
853
|
-
<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>
|
|
853
|
+
<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>197.45</td><td>5.06</td><td>0.03</td></tr><tr><td>1,000,000 unshift</td><td>214.02</td><td>4.67</td><td>0.08</td></tr><tr><td>1,000,000 unshift & shift</td><td>198.97</td><td>5.03</td><td>0.05</td></tr><tr><td>1,000,000 addBefore</td><td>315.44</td><td>3.17</td><td>0.05</td></tr></table></div>
|
|
854
854
|
</div><div class="json-to-html-collapse clearfix 0">
|
|
855
855
|
<div class='collapsible level0' ><span class='json-to-html-label'>singly-linked-list</span></div>
|
|
856
|
-
<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>
|
|
856
|
+
<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>196.91</td><td>5.08</td><td>0.04</td></tr><tr><td>10,000 push & pop</td><td>222.29</td><td>4.50</td><td>0.01</td></tr><tr><td>10,000 addBefore</td><td>248.87</td><td>4.02</td><td>0.01</td></tr></table></div>
|
|
857
857
|
</div><div class="json-to-html-collapse clearfix 0">
|
|
858
858
|
<div class='collapsible level0' ><span class='json-to-html-label'>priority-queue</span></div>
|
|
859
|
-
<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.
|
|
859
|
+
<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.69</td><td>36.11</td><td>8.96e-4</td></tr><tr><td>100,000 add & poll</td><td>75.38</td><td>13.27</td><td>6.45e-4</td></tr></table></div>
|
|
860
860
|
</div><div class="json-to-html-collapse clearfix 0">
|
|
861
861
|
<div class='collapsible level0' ><span class='json-to-html-label'>stack</span></div>
|
|
862
|
-
<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>
|
|
862
|
+
<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.19</td><td>25.52</td><td>0.00</td></tr><tr><td>1,000,000 push & pop</td><td>45.24</td><td>22.10</td><td>0.00</td></tr></table></div>
|
|
863
863
|
</div>
|
|
864
864
|
|
|
865
865
|
[//]: # (No deletion!!! End of Replace Section)
|
package/README_zh-CN.md
CHANGED
|
@@ -22,15 +22,13 @@ JavaScript和TypeScript的数据结构。
|
|
|
22
22
|
|
|
23
23
|
**`基准测试`** 与C++ STL相比。**`API 标准`** 与ES6和Java对齐。**`易用性`** 可与Python媲美。
|
|
24
24
|
|
|
25
|
-
|
|
26
25
|
### 提供了JS/TS中没有的数据结构
|
|
27
26
|
|
|
28
|
-
Heap, Binary Tree, RedBlack Tree, Linked List, Deque, Trie, Directed Graph, Undirected Graph, BST, AVL Tree, Priority
|
|
29
|
-
|
|
27
|
+
Heap, Binary Tree, RedBlack Tree, Linked List, Deque, Trie, Directed Graph, Undirected Graph, BST, AVL Tree, Priority
|
|
28
|
+
Queue, Queue, Tree Multiset.
|
|
30
29
|
|
|
31
30
|
### 性能超越原生JS/TS
|
|
32
31
|
|
|
33
|
-
|
|
34
32
|
<table style="display: table; width:100%; table-layout: fixed;">
|
|
35
33
|
<thead>
|
|
36
34
|
<tr>
|
|
@@ -133,19 +131,21 @@ import {
|
|
|
133
131
|
#### 开发环境
|
|
134
132
|
|
|
135
133
|
```html
|
|
134
|
+
|
|
136
135
|
<script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.js'></script>
|
|
137
136
|
```
|
|
138
137
|
|
|
139
138
|
#### 生产环境
|
|
140
139
|
|
|
141
140
|
```html
|
|
141
|
+
|
|
142
142
|
<script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.min.js'></script>
|
|
143
143
|
```
|
|
144
144
|
|
|
145
145
|
将下面的代码复制到你的 HTML 的 script 标签中,你就可以开始你的开发了。
|
|
146
146
|
|
|
147
147
|
```js
|
|
148
|
-
const {Heap} = dataStructureTyped;
|
|
148
|
+
const { Heap } = dataStructureTyped;
|
|
149
149
|
const {
|
|
150
150
|
BinaryTree, Graph, Queue, Stack, PriorityQueue, BST, Trie, DoublyLinkedList,
|
|
151
151
|
AVLTree, MinHeap, SinglyLinkedList, DirectedGraph, TreeMultiMap,
|
|
@@ -157,7 +157,8 @@ const {
|
|
|
157
157
|
|
|
158
158
|
### Binary Tree(二叉树)
|
|
159
159
|
|
|
160
|
-
[试一下](https://vivid-algorithm.vercel.app/)
|
|
160
|
+
[试一下](https://vivid-algorithm.vercel.app/)
|
|
161
|
+
,或者你可以使用我们的可视化工具运行自己的代码 [visual tool](https://github.com/zrwusa/vivid-algorithm)
|
|
161
162
|
|
|
162
163
|

|
|
163
164
|
|
|
@@ -202,8 +203,9 @@ const {
|
|
|
202
203
|
### 红黑树 代码示例
|
|
203
204
|
|
|
204
205
|
#### TS
|
|
206
|
+
|
|
205
207
|
```ts
|
|
206
|
-
import {RedBlackTree} from 'data-structure-typed';
|
|
208
|
+
import { RedBlackTree } from 'data-structure-typed';
|
|
207
209
|
|
|
208
210
|
const rbTree = new RedBlackTree<number>();
|
|
209
211
|
rbTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
|
|
@@ -223,8 +225,9 @@ rbTree.print()
|
|
|
223
225
|
```
|
|
224
226
|
|
|
225
227
|
#### JS
|
|
228
|
+
|
|
226
229
|
```js
|
|
227
|
-
import {RedBlackTree} from 'data-structure-typed';
|
|
230
|
+
import { RedBlackTree } from 'data-structure-typed';
|
|
228
231
|
|
|
229
232
|
const rbTree = new RedBlackTree();
|
|
230
233
|
rbTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
|
|
@@ -246,7 +249,7 @@ rbTree.print()
|
|
|
246
249
|
### 二叉搜索树 (BST) 代码示例
|
|
247
250
|
|
|
248
251
|
```ts
|
|
249
|
-
import {BST, BSTNode} from 'data-structure-typed';
|
|
252
|
+
import { BST, BSTNode } from 'data-structure-typed';
|
|
250
253
|
|
|
251
254
|
const bst = new BST<number>();
|
|
252
255
|
bst.add(11);
|
|
@@ -278,7 +281,7 @@ bst.print()
|
|
|
278
281
|
// \
|
|
279
282
|
// 7
|
|
280
283
|
|
|
281
|
-
const objBST = new BST<number, {height: number, age: number}>();
|
|
284
|
+
const objBST = new BST<number, { height: number, age: number }>();
|
|
282
285
|
|
|
283
286
|
objBST.add(11, { "name": "Pablo", "age": 15 });
|
|
284
287
|
objBST.add(3, { "name": "Kirk", "age": 1 });
|
|
@@ -307,7 +310,7 @@ objBST.delete(11);
|
|
|
307
310
|
### AVL树 代码示例
|
|
308
311
|
|
|
309
312
|
```ts
|
|
310
|
-
import {AVLTree} from 'data-structure-typed';
|
|
313
|
+
import { AVLTree } from 'data-structure-typed';
|
|
311
314
|
|
|
312
315
|
const avlTree = new AVLTree<number>();
|
|
313
316
|
avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
|
|
@@ -319,7 +322,7 @@ avlTree.isAVLBalanced(); // true
|
|
|
319
322
|
### 有向图代码示例
|
|
320
323
|
|
|
321
324
|
```ts
|
|
322
|
-
import {DirectedGraph} from 'data-structure-typed';
|
|
325
|
+
import { DirectedGraph } from 'data-structure-typed';
|
|
323
326
|
|
|
324
327
|
const graph = new DirectedGraph<string>();
|
|
325
328
|
|
|
@@ -348,7 +351,7 @@ const topologicalOrderKeys = graph.topologicalSort(); // ['A', 'B', 'C']
|
|
|
348
351
|
### 无向图代码示例
|
|
349
352
|
|
|
350
353
|
```ts
|
|
351
|
-
import {UndirectedGraph} from 'data-structure-typed';
|
|
354
|
+
import { UndirectedGraph } from 'data-structure-typed';
|
|
352
355
|
|
|
353
356
|
const graph = new UndirectedGraph<string>();
|
|
354
357
|
graph.addVertex('A');
|
|
@@ -373,31 +376,31 @@ const orgStrArr = ["trie", "trial", "trick", "trip", "tree", "trend", "triangle"
|
|
|
373
376
|
const entries = [[6, 6], [1, 1], [2, 2], [7, 7], [5, 5], [3, 3], [4, 4], [9, 9], [8, 8]];
|
|
374
377
|
|
|
375
378
|
const queue = new Queue(orgArr);
|
|
376
|
-
queue.print();
|
|
379
|
+
queue.print();
|
|
377
380
|
// [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
378
381
|
|
|
379
382
|
const deque = new Deque(orgArr);
|
|
380
|
-
deque.print();
|
|
383
|
+
deque.print();
|
|
381
384
|
// [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
382
385
|
|
|
383
386
|
const sList = new SinglyLinkedList(orgArr);
|
|
384
|
-
sList.print();
|
|
387
|
+
sList.print();
|
|
385
388
|
// [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
386
389
|
|
|
387
390
|
const dList = new DoublyLinkedList(orgArr);
|
|
388
|
-
dList.print();
|
|
391
|
+
dList.print();
|
|
389
392
|
// [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
390
393
|
|
|
391
394
|
const stack = new Stack(orgArr);
|
|
392
|
-
stack.print();
|
|
395
|
+
stack.print();
|
|
393
396
|
// [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
394
397
|
|
|
395
398
|
const minHeap = new MinHeap(orgArr);
|
|
396
|
-
minHeap.print();
|
|
399
|
+
minHeap.print();
|
|
397
400
|
// [1, 5, 2, 7, 6, 3, 4, 9, 8]
|
|
398
401
|
|
|
399
402
|
const maxPQ = new MaxPriorityQueue(orgArr);
|
|
400
|
-
maxPQ.print();
|
|
403
|
+
maxPQ.print();
|
|
401
404
|
// [9, 8, 4, 7, 5, 2, 3, 1, 6]
|
|
402
405
|
|
|
403
406
|
const biTree = new BinaryTree(entries);
|
|
@@ -453,7 +456,7 @@ treeMulti.print();
|
|
|
453
456
|
// 7 9
|
|
454
457
|
|
|
455
458
|
const hm = new HashMap(entries);
|
|
456
|
-
hm.print()
|
|
459
|
+
hm.print()
|
|
457
460
|
// [[6, 6], [1, 1], [2, 2], [7, 7], [5, 5], [3, 3], [4, 4], [9, 9], [8, 8]]
|
|
458
461
|
|
|
459
462
|
const rbTreeH = new RedBlackTree(hm);
|
|
@@ -467,7 +470,7 @@ rbTreeH.print();
|
|
|
467
470
|
// 7 9
|
|
468
471
|
|
|
469
472
|
const pq = new MinPriorityQueue(orgArr);
|
|
470
|
-
pq.print();
|
|
473
|
+
pq.print();
|
|
471
474
|
// [1, 5, 2, 7, 6, 3, 4, 9, 8]
|
|
472
475
|
|
|
473
476
|
const bst1 = new BST(pq);
|
|
@@ -481,7 +484,7 @@ bst1.print();
|
|
|
481
484
|
// 4 9
|
|
482
485
|
|
|
483
486
|
const dq1 = new Deque(orgArr);
|
|
484
|
-
dq1.print();
|
|
487
|
+
dq1.print();
|
|
485
488
|
// [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
486
489
|
const rbTree1 = new RedBlackTree(dq1);
|
|
487
490
|
rbTree1.print();
|
|
@@ -495,13 +498,13 @@ rbTree1.print();
|
|
|
495
498
|
|
|
496
499
|
|
|
497
500
|
const trie2 = new Trie(orgStrArr);
|
|
498
|
-
trie2.print();
|
|
501
|
+
trie2.print();
|
|
499
502
|
// ['trie', 'trial', 'triangle', 'trick', 'trip', 'tree', 'trend', 'track', 'trace', 'transmit']
|
|
500
503
|
const heap2 = new Heap(trie2, { comparator: (a, b) => Number(a) - Number(b) });
|
|
501
|
-
heap2.print();
|
|
504
|
+
heap2.print();
|
|
502
505
|
// ['transmit', 'trace', 'tree', 'trend', 'track', 'trial', 'trip', 'trie', 'trick', 'triangle']
|
|
503
506
|
const dq2 = new Deque(heap2);
|
|
504
|
-
dq2.print();
|
|
507
|
+
dq2.print();
|
|
505
508
|
// ['transmit', 'trace', 'tree', 'trend', 'track', 'trial', 'trip', 'trie', 'trick', 'triangle']
|
|
506
509
|
const entries2 = dq2.map((el, i) => [i, el]);
|
|
507
510
|
const avl2 = new AVLTree(entries2);
|
|
@@ -670,6 +673,193 @@ avl2.print();
|
|
|
670
673
|
</tbody>
|
|
671
674
|
</table>
|
|
672
675
|
|
|
676
|
+
## 形象比喻与选型
|
|
677
|
+
|
|
678
|
+
<table>
|
|
679
|
+
<tr>
|
|
680
|
+
<th>分类</th>
|
|
681
|
+
<th>数据结构</th>
|
|
682
|
+
<th>选型原因</th>
|
|
683
|
+
<th>大白话描述</th>
|
|
684
|
+
<th>图示</th>
|
|
685
|
+
</tr>
|
|
686
|
+
<tr>
|
|
687
|
+
<td rowspan="7">线性结构</td>
|
|
688
|
+
<td>Array</td>
|
|
689
|
+
<td>需要快速随机访问,固定大小,元素类型相同</td>
|
|
690
|
+
<td>
|
|
691
|
+
一排编号的兔子。如果你想找到名叫Pablo的兔子,你可以直接喊出Pablo的号码0680(通过数组索引直接找到元素,时间复杂度O(1))。但是,如果你不知道Pablo的号码,你仍然需要逐个搜索(时间复杂度O(n))。此外,如果你想在Pablo后面添加一只名叫Vicky的兔子,你需要重新为Vicky之后的所有兔子编号(时间复杂度O(n))。
|
|
692
|
+
</td>
|
|
693
|
+
<td><img width="200" alt="array"
|
|
694
|
+
src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/array.png"/>
|
|
695
|
+
</td>
|
|
696
|
+
</tr>
|
|
697
|
+
<tr>
|
|
698
|
+
<td>Linked List</td>
|
|
699
|
+
<td>需要频繁插入删除,大小可变</td>
|
|
700
|
+
<td>
|
|
701
|
+
一排兔子,每只兔子抓着前面兔子的尾巴(每只兔子只知道它后面兔子的名字)。你想找一只名叫Pablo的兔子,你必须从第一只兔子开始搜索。如果不是Pablo,你就继续顺着那只兔子的尾巴找下一只。所以,你可能需要搜索n次才能找到Pablo(时间复杂度O(n))。如果你想在Pablo和Vicky之间插入一只名叫Remi的兔子,这很简单。你只需让Vicky放开Pablo的尾巴,让Remi抓住Pablo的尾巴,然后让Vicky抓住Remi的尾巴(时间复杂度O(1))。
|
|
702
|
+
</td>
|
|
703
|
+
<td><img width="200" alt="singly linked list"
|
|
704
|
+
src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/singly-linked-list.png"/>
|
|
705
|
+
</td>
|
|
706
|
+
</tr>
|
|
707
|
+
<tr>
|
|
708
|
+
<td>Singly Linked List</td>
|
|
709
|
+
<td>只需要单向遍历,内存占用较少</td>
|
|
710
|
+
<td>与链表描述相同。</td>
|
|
711
|
+
<td><img width="200" alt="singly linked list"
|
|
712
|
+
src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/singly-linked-list.png"/>
|
|
713
|
+
</td>
|
|
714
|
+
</tr>
|
|
715
|
+
<tr>
|
|
716
|
+
<td>Doubly Linked List</td>
|
|
717
|
+
<td>需要双向遍历,允许从尾部快速删除</td>
|
|
718
|
+
<td>
|
|
719
|
+
一排兔子,每只兔子抓着前面兔子的尾巴(每只兔子知道相邻两只兔子的名字)。这为单向链表提供了向前搜索的能力,仅此而已。例如,如果你直接来到队列中的Remi兔子那里,问她Vicky在哪里,她会说在我后面抓着我尾巴的那只,如果你问她Pablo在哪里,她会说就在前面。
|
|
720
|
+
</td>
|
|
721
|
+
<td><img width="200" alt="doubly linked list"
|
|
722
|
+
src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/doubly-linked-list.png"/>
|
|
723
|
+
</td>
|
|
724
|
+
</tr>
|
|
725
|
+
<tr>
|
|
726
|
+
<td>Queue</td>
|
|
727
|
+
<td>需要先进先出(FIFO)的处理顺序</td>
|
|
728
|
+
<td>
|
|
729
|
+
一排编号的兔子,第一只兔子身上贴着便利贴。对于这个贴有便利贴的队列,每当我们想从队列前面移除一只兔子时,我们只需要将便利贴移到下一只兔子的脸上,而不需要实际移除兔子,以避免重新为后面所有的兔子编号(从前面移除也是O(1)时间复杂度)。对于队列尾部,我们不需要担心,因为每只新添加到尾部的兔子直接被赋予一个新编号(O(1)时间复杂度),不需要重新为之前所有的兔子编号。
|
|
730
|
+
</td>
|
|
731
|
+
<td><img width="200" alt="queue"
|
|
732
|
+
src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/queue.jpg"/>
|
|
733
|
+
</td>
|
|
734
|
+
</tr>
|
|
735
|
+
<tr>
|
|
736
|
+
<td>Deque</td>
|
|
737
|
+
<td>需要在两端都能快速插入和删除</td>
|
|
738
|
+
<td>
|
|
739
|
+
一排分组编号的兔子,第一只兔子身上贴着便利贴。对于这个队列,我们按组管理。每次从队列前面移除一只兔子时,我们只将便利贴移到下一只兔子身上。这样,我们不需要每次移除第一只兔子时都重新为后面所有的兔子编号。只有当一个组的所有成员都被移除时,我们才重新分配编号和分组。尾部的处理也是类似的。这是一种延迟和批量操作的策略,以抵消数组数据结构在中间插入或删除元素时需要移动所有后续元素的缺点。
|
|
740
|
+
</td>
|
|
741
|
+
<td><img width="200" alt="deque"
|
|
742
|
+
src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/deque.png"/>
|
|
743
|
+
</td>
|
|
744
|
+
</tr>
|
|
745
|
+
<tr>
|
|
746
|
+
<td>Stack</td>
|
|
747
|
+
<td>需要后进先出(LIFO)的处理顺序</td>
|
|
748
|
+
<td>一排兔子在一个死胡同隧道里,兔子只能从隧道入口(末端)被移除,新兔子也只能从入口(末端)被添加。</td>
|
|
749
|
+
<td><img width="200" alt="stack"
|
|
750
|
+
src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/stack.jpg"/>
|
|
751
|
+
</td>
|
|
752
|
+
</tr>
|
|
753
|
+
<tr>
|
|
754
|
+
<td rowspan="5">树结构</td>
|
|
755
|
+
<td>Binary Tree</td>
|
|
756
|
+
<td>需要层次结构,每个节点最多有两个子节点</td>
|
|
757
|
+
<td>顾名思义,它是一棵每个节点最多有两个子节点的树。当你添加连续的数据如[4, 2, 6, 1, 3, 5, 7]时,它将是一个完全二叉树。当你添加像[4,
|
|
758
|
+
2, 6, null, 1, 3, null, 5, null, 7]这样的数据时,你可以指定任何左或右子节点是否为空,树的形状是完全可控的。
|
|
759
|
+
</td>
|
|
760
|
+
<td><img width="200" alt="binary tree"
|
|
761
|
+
src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/binary-tree.png"/>
|
|
762
|
+
</td>
|
|
763
|
+
</tr>
|
|
764
|
+
<tr>
|
|
765
|
+
<td>Binary Search Tree</td>
|
|
766
|
+
<td>需要快速查找、插入和删除,但不要求严格平衡</td>
|
|
767
|
+
<td>一个由双向链表组成的树状兔子群落,每只兔子最多有两条尾巴。这些兔子有纪律且听话,按照一定的顺序排列在自己的位置上。二叉树中最重要的数据结构(核心是插入、删除、修改、查找的时间复杂度为O(log
|
|
768
|
+
n))。BST中存储的数据是结构化和有序的,不是严格的1、2、3、4、5这样的顺序,而是保持左子树中的所有节点小于节点,右子树中的所有节点大于节点。这种顺序为插入、删除、修改和搜索提供了O(log
|
|
769
|
+
n)的时间复杂度。将O(n)降低到O(log n)是计算机领域最常见的算法复杂度优化,效率提升是指数级的。它也是将无序数据组织成有序数据的最有效方式(大多数排序算法只能保持O(n
|
|
770
|
+
log n))。当然,我们提供的二叉搜索树支持以升序和降序组织数据。请记住,基本的BST没有自平衡能力,如果你顺序添加已排序的数据到这个数据结构中,它将退化成一个列表,从而失去O(log
|
|
771
|
+
n)的能力。当然,我们的addMany方法经过特殊处理以防止退化。但是,对于实际应用,请尽可能使用红黑树或AVL树,因为它们天生就具有自平衡功能。
|
|
772
|
+
</td>
|
|
773
|
+
<td><img width="200" alt="binary search tree"
|
|
774
|
+
src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/binary-search-tree.png"/>
|
|
775
|
+
</td>
|
|
776
|
+
</tr>
|
|
777
|
+
<tr>
|
|
778
|
+
<td>Red Black Tree</td>
|
|
779
|
+
<td>需要自平衡的二叉搜索树,保证最坏情况下的性能</td>
|
|
780
|
+
<td>
|
|
781
|
+
一个由双向链表组成的树状兔子群落,每只兔子最多有两条尾巴。这些兔子不仅听话,而且聪明,会自动按照一定的顺序排列自己的位置。一种自平衡的二叉搜索树。每个节点都标有红黑标记。确保没有任何路径比其他路径长两倍以上(保持一定的平衡以提高搜索、添加和删除的速度)。
|
|
782
|
+
</td>
|
|
783
|
+
<td><img width="200" alt="red-black tree"
|
|
784
|
+
src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/red-black tree.png"/>
|
|
785
|
+
</td>
|
|
786
|
+
</tr>
|
|
787
|
+
<tr>
|
|
788
|
+
<td>AVL Tree</td>
|
|
789
|
+
<td>需要严格平衡的二叉搜索树,读取操作频繁</td>
|
|
790
|
+
<td>
|
|
791
|
+
一个由双向链表组成的树状兔子群落,每只兔子最多有两条尾巴。这些兔子不仅听话和聪明,会自动按照一定的顺序排列自己的位置,而且遵循非常严格的规则。一种自平衡的二叉搜索树。每个节点都标有平衡因子,表示其左右子树的高度差。平衡因子的绝对值不超过1(保持更严格的平衡,使得搜索效率高于红黑树,但插入和删除操作会更复杂,相对效率较低)。
|
|
792
|
+
</td>
|
|
793
|
+
<td><img width="200" alt="avl tree"
|
|
794
|
+
src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/avl-tree.png"/>
|
|
795
|
+
</td>
|
|
796
|
+
</tr>
|
|
797
|
+
<tr>
|
|
798
|
+
<td>Trie</td>
|
|
799
|
+
<td>需要高效地存储和搜索字符串,特别是前缀匹配</td>
|
|
800
|
+
<td>一种特殊的树结构,用于高效存储和检索字符串数据集中的键。这种结构特别适用于实现字典和支持前缀搜索。</td>
|
|
801
|
+
<td>(图示暂缺)</td>
|
|
802
|
+
</tr>
|
|
803
|
+
<tr>
|
|
804
|
+
<td rowspan="2">堆</td>
|
|
805
|
+
<td>Heap</td>
|
|
806
|
+
<td>需要快速获取最大或最小元素</td>
|
|
807
|
+
<td>
|
|
808
|
+
一种特殊的完全二叉树,通常存储在数组中,其中索引为i的节点的子节点位于索引2i+1和2i+2处。自然地,任何节点的父节点位于⌊(i−1)/2⌋处。
|
|
809
|
+
</td>
|
|
810
|
+
<td><img width="200" alt="heap"
|
|
811
|
+
src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/heap.jpg"/>
|
|
812
|
+
</td>
|
|
813
|
+
</tr>
|
|
814
|
+
<tr>
|
|
815
|
+
<td>Priority Queue</td>
|
|
816
|
+
<td>需要按优先级处理元素</td>
|
|
817
|
+
<td>实际上就是一个堆。</td>
|
|
818
|
+
<td><img width="200" alt="priority queue"
|
|
819
|
+
src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/heap.jpg"/>
|
|
820
|
+
</td>
|
|
821
|
+
</tr>
|
|
822
|
+
<tr>
|
|
823
|
+
<td rowspan="3">图结构</td>
|
|
824
|
+
<td>Graph</td>
|
|
825
|
+
<td>需要表示复杂的关系网络</td>
|
|
826
|
+
<td>有向图和无向图的基类,提供一些公共方法。</td>
|
|
827
|
+
<td><img width="200" alt="graph"
|
|
828
|
+
src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/graph.png"/>
|
|
829
|
+
</td>
|
|
830
|
+
</tr>
|
|
831
|
+
<tr>
|
|
832
|
+
<td>Directed Graph</td>
|
|
833
|
+
<td>需要表示单向关系</td>
|
|
834
|
+
<td>一个网络状的兔子群,每只兔子最多可以有n条尾巴(单向链表)。</td>
|
|
835
|
+
<td><img width="200" alt="directed graph"
|
|
836
|
+
src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/directed-graph.png"/>
|
|
837
|
+
</td>
|
|
838
|
+
</tr>
|
|
839
|
+
<tr>
|
|
840
|
+
<td>Undirected Graph</td>
|
|
841
|
+
<td>需要表示双向关系</td>
|
|
842
|
+
<td>一个网络状的兔子群,每只兔子最多可以有n条尾巴(双向链表)。</td>
|
|
843
|
+
<td><img width="200" alt="undirected graph"
|
|
844
|
+
src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/undirected-graph.png"/>
|
|
845
|
+
</td>
|
|
846
|
+
</tr>
|
|
847
|
+
<tr>
|
|
848
|
+
<td>哈希结构</td>
|
|
849
|
+
<td>HashMap</td>
|
|
850
|
+
<td>需要快速的键值对查找</td>
|
|
851
|
+
<td>一种基于键的哈希值来存储数据的结构,允许以接近O(1)的时间复杂度进行插入、删除和查找操作。</td>
|
|
852
|
+
<td>(图示暂缺)</td>
|
|
853
|
+
</tr>
|
|
854
|
+
<tr>
|
|
855
|
+
<td>集合结构</td>
|
|
856
|
+
<td>Multiset</td>
|
|
857
|
+
<td>需要存储重复元素并快速统计元素出现次数</td>
|
|
858
|
+
<td>一种允许重复元素的集合,通常用于需要快速统计元素出现次数的场景。</td>
|
|
859
|
+
<td>(图示暂缺)</td>
|
|
860
|
+
</tr>
|
|
861
|
+
</table>
|
|
862
|
+
|
|
673
863
|
## 不同编程语言中的数据结构对应关系
|
|
674
864
|
|
|
675
865
|
<table style="display: table; width:100%; table-layout: fixed;">
|