Skip to content

Commit

Permalink
docs: playground project added
Browse files Browse the repository at this point in the history
  • Loading branch information
zrwusa committed Nov 30, 2024
1 parent dd27393 commit 1163246
Show file tree
Hide file tree
Showing 16 changed files with 480 additions and 279 deletions.
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
src/types/data-structures/binary-tree/binary-tree.ts
src/types/data-structures/binary-tree/bst.ts
src/types/data-structures/binary-tree/avl-tree.ts
src/types/data-structures/binary-tree/rb-tree.ts
src/types/data-structures/binary-tree/red-black-tree.ts
src/types/data-structures/binary-tree/tree-multi-map.ts
src/types/data-structures/binary-tree/avl-tree-multi-map.ts
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.54.1](https://github.com/zrwusa/data-structure-typed/compare/v1.51.5...main) (upcoming)
## [v1.54.2](https://github.com/zrwusa/data-structure-typed/compare/v1.51.5...main) (upcoming)

### Changes

Expand Down
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
45 changes: 18 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -830,37 +830,28 @@ Version 11.7.9

***Our performance testing is conducted directly on the TypeScript source code. The actual performance of the compiled JavaScript code is generally 3 times higher. We have compared it with C++, and it is only 30% slower than C++.***

Try it [on gitpod](https://gitpod.io#snapshot/93383de4-ca4c-4854-8c80-4359e681a96f)

Just run
```shell
pnpm perf:rbtree
```

```html
1,000,000 add randomly: 1.367s
1,000,000 add: 374.859ms
1,000,000 get: 8.025ms
1,000,000 getNode: 1.293s
```


[//]: # (No deletion!!! Start of Replace Section)
<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>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>6.85</td><td>0.01</td><td>3.38e-4</td></tr><tr><td>100,000 add & poll</td><td>35.35</td><td>0.04</td><td>8.44e-4</td></tr></table></div>
</div><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>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>302.89</td><td>0.30</td><td>0.01</td></tr><tr><td>100,000 add randomly</td><td>381.83</td><td>0.38</td><td>0.00</td></tr><tr><td>100,000 get</td><td>0.60</td><td>5.95e-4</td><td>2.33e-4</td></tr><tr><td>100,000 getNode</td><td>150.61</td><td>0.15</td><td>0.00</td></tr><tr><td>100,000 iterator</td><td>28.23</td><td>0.03</td><td>0.00</td></tr><tr><td>100,000 add & delete orderly</td><td>505.57</td><td>0.51</td><td>0.01</td></tr><tr><td>100,000 add & delete randomly</td><td>677.36</td><td>0.68</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'>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>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>212.77</td><td>0.21</td><td>9.84e-4</td></tr><tr><td>100,000 add randomly</td><td>163.70</td><td>0.16</td><td>0.00</td></tr><tr><td>100,000 get</td><td>1.19</td><td>0.00</td><td>2.44e-4</td></tr><tr><td>100,000 getNode</td><td>347.39</td><td>0.35</td><td>0.01</td></tr><tr><td>100,000 node mode add randomly</td><td>162.26</td><td>0.16</td><td>0.00</td></tr><tr><td>100,000 node mode get</td><td>344.90</td><td>0.34</td><td>0.00</td></tr><tr><td>100,000 iterator</td><td>27.48</td><td>0.03</td><td>0.00</td></tr><tr><td>100,000 add & delete orderly</td><td>386.33</td><td>0.39</td><td>0.00</td></tr><tr><td>100,000 add & delete randomly</td><td>520.66</td><td>0.52</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'>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>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>179.28</td><td>0.18</td><td>0.02</td></tr><tr><td>1,000,000 unshift</td><td>197.22</td><td>0.20</td><td>0.05</td></tr><tr><td>1,000,000 unshift & shift</td><td>153.16</td><td>0.15</td><td>0.00</td></tr><tr><td>1,000,000 addBefore</td><td>247.30</td><td>0.25</td><td>0.03</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>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1,000 addVertex</td><td>0.10</td><td>9.92e-5</td><td>1.16e-6</td></tr><tr><td>1,000 addEdge</td><td>6.44</td><td>0.01</td><td>0.00</td></tr><tr><td>1,000 getVertex</td><td>0.10</td><td>9.82e-5</td><td>1.13e-6</td></tr><tr><td>1,000 getEdge</td><td>22.60</td><td>0.02</td><td>0.00</td></tr><tr><td>tarjan</td><td>186.56</td><td>0.19</td><td>0.00</td></tr><tr><td>topologicalSort</td><td>145.42</td><td>0.15</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'>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>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>47.74</td><td>0.05</td><td>0.02</td></tr><tr><td>100,000 push & shift</td><td>5.39</td><td>0.01</td><td>1.25e-4</td></tr><tr><td>Native JS Array 100,000 push & shift</td><td>2225.50</td><td>2.23</td><td>0.10</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>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>22.88</td><td>0.02</td><td>0.01</td></tr><tr><td>1,000,000 push & pop</td><td>27.95</td><td>0.03</td><td>0.01</td></tr><tr><td>1,000,000 push & shift</td><td>29.83</td><td>0.03</td><td>0.01</td></tr><tr><td>100,000 push & shift</td><td>2.71</td><td>0.00</td><td>9.03e-4</td></tr><tr><td>Native JS Array 100,000 push & shift</td><td>2182.03</td><td>2.18</td><td>0.04</td></tr><tr><td>100,000 unshift & shift</td><td>2.61</td><td>0.00</td><td>8.71e-4</td></tr><tr><td>Native JS Array 100,000 unshift & shift</td><td>4185.90</td><td>4.19</td><td>0.04</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>hash-map</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>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1,000,000 set</td><td>253.45</td><td>0.25</td><td>0.07</td></tr><tr><td>Native JS Map 1,000,000 set</td><td>228.90</td><td>0.23</td><td>0.02</td></tr><tr><td>Native JS Set 1,000,000 add</td><td>179.65</td><td>0.18</td><td>0.01</td></tr><tr><td>1,000,000 set & get</td><td>234.96</td><td>0.23</td><td>0.06</td></tr><tr><td>Native JS Map 1,000,000 set & get</td><td>284.90</td><td>0.28</td><td>0.01</td></tr><tr><td>Native JS Set 1,000,000 add & has</td><td>254.90</td><td>0.25</td><td>0.03</td></tr><tr><td>1,000,000 ObjKey set & get</td><td>403.74</td><td>0.40</td><td>0.10</td></tr><tr><td>Native JS Map 1,000,000 ObjKey set & get</td><td>340.18</td><td>0.34</td><td>0.07</td></tr><tr><td>Native JS Set 1,000,000 ObjKey add & has</td><td>300.25</td><td>0.30</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'>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>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>100,000 push</td><td>44.11</td><td>0.04</td><td>8.55e-4</td></tr><tr><td>100,000 getWords</td><td>86.67</td><td>0.09</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>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>100,000 add randomly</td><td>526.46</td><td>0.53</td><td>0.01</td></tr><tr><td>100,000 add</td><td>474.38</td><td>0.47</td><td>0.00</td></tr><tr><td>100,000 get</td><td>0.72</td><td>7.17e-4</td><td>3.47e-4</td></tr><tr><td>100,000 getNode</td><td>252.58</td><td>0.25</td><td>0.01</td></tr><tr><td>100,000 iterator</td><td>24.84</td><td>0.02</td><td>0.00</td></tr><tr><td>100,000 add & delete orderly</td><td>717.48</td><td>0.72</td><td>0.02</td></tr><tr><td>100,000 add & delete randomly</td><td>898.45</td><td>0.90</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'>stack</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>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>43.18</td><td>0.04</td><td>0.01</td></tr><tr><td>1,000,000 push & pop</td><td>48.40</td><td>0.05</td><td>0.02</td></tr></table></div>
<div class='collapsible level0' ><span class='json-to-html-label'>red-black-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>sample mean (secs)</th><th>sample deviation</th></tr><tr><td>100,000 add randomly</td><td>144.49</td><td>0.14</td><td>0.01</td></tr><tr><td>100,000 add</td><td>190.53</td><td>0.19</td><td>0.00</td></tr><tr><td>100,000 get</td><td>0.91</td><td>9.14e-4</td><td>2.11e-4</td></tr><tr><td>100,000 getNode</td><td>323.66</td><td>0.32</td><td>0.00</td></tr><tr><td>100,000 node mode add randomly</td><td>139.71</td><td>0.14</td><td>0.00</td></tr><tr><td>100,000 node mode get</td><td>322.39</td><td>0.32</td><td>7.58e-4</td></tr><tr><td>100,000 iterator</td><td>27.07</td><td>0.03</td><td>0.00</td></tr><tr><td>100,000 add & delete orderly</td><td>349.17</td><td>0.35</td><td>0.00</td></tr><tr><td>100,000 add & delete randomly</td><td>482.61</td><td>0.48</td><td>0.01</td></tr></table></div>
</div>

[//]: # (No deletion!!! End of Replace Section)
Expand Down
2 changes: 1 addition & 1 deletion README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ avl2.print();
<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>55.04</td><td>18.17</td><td>0.01</td></tr><tr><td>10,000 add & delete randomly</td><td>129.85</td><td>7.70</td><td>0.01</td></tr><tr><td>10,000 addMany</td><td>50.40</td><td>19.84</td><td>0.01</td></tr><tr><td>10,000 get</td><td>63.39</td><td>15.78</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'>rb-tree</span></div>
<div class='collapsible level0' ><span class='json-to-html-label'>red-black-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</td><td>113.25</td><td>8.83</td><td>0.02</td></tr><tr><td>100,000 add & delete randomly</td><td>305.28</td><td>3.28</td><td>0.03</td></tr><tr><td>100,000 getNode</td><td>73.20</td><td>13.66</td><td>0.03</td></tr><tr><td>100,000 add & iterator</td><td>159.80</td><td>6.26</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'>comparison</span></div>
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"gen:examples": "ts-node scripts/testToExample.ts",
"test:in-band": "jest --runInBand",
"test": "npm run test:in-band",
"test:integration": "npm run update:subs && jest --config jest.integration.config.js && tsc test/integration/compile.ts",
"test:integration": "npm run update:subs && jest --config jest.integration.config.js && tsc test/integration/compile.ts && node test/integration/compile.mjs",
"test:perf": "npm run build:cjs && npm run build:esm && ts-node test/performance/reportor.ts",
"check": "tsc --noEmit",
"check:circular-refs": "dependency-cruiser src",
Expand Down Expand Up @@ -65,11 +65,11 @@
"@typescript-eslint/eslint-plugin": "^8.12.1",
"@typescript-eslint/parser": "^8.12.1",
"auto-changelog": "^2.5.0",
"avl-tree-typed": "^1.54.0",
"avl-tree-typed": "^1.54.1",
"benchmark": "^2.1.4",
"binary-tree-typed": "^1.54.0",
"bst-typed": "^1.54.0",
"data-structure-typed": "^1.54.0",
"binary-tree-typed": "^1.54.1",
"bst-typed": "^1.54.1",
"data-structure-typed": "^1.54.2",
"dependency-cruiser": "^16.5.0",
"doctoc": "^2.2.1",
"eslint": "^9.13.0",
Expand All @@ -78,7 +78,7 @@
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import": "^2.31.0",
"fast-glob": "^3.3.2",
"heap-typed": "^1.54.0",
"heap-typed": "^1.54.1",
"istanbul-badges-readme": "^1.9.0",
"jest": "^29.7.0",
"js-sdsl": "^4.4.2",
Expand Down
4 changes: 2 additions & 2 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* data-structure-typed
*
* @author Tyler Zeng
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
* @author Pablo Zeng
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import type { Comparable, ComparablePrimitive, Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from '../types';
Expand Down
42 changes: 21 additions & 21 deletions test/integration/compile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ const entries = [
[8, '8']
];
const queue = new Queue(orgArr);
queue.print();

// [6, 1, 2, 7, 5, 3, 4, 9, 8]
const deque = new Deque(orgArr);
deque.print();

// [6, 1, 2, 7, 5, 3, 4, 9, 8]
const sList = new SinglyLinkedList(orgArr);
sList.print();

// [6, 1, 2, 7, 5, 3, 4, 9, 8]
const dList = new DoublyLinkedList(orgArr);
dList.print();

// [6, 1, 2, 7, 5, 3, 4, 9, 8]
const stack = new Stack(orgArr);
stack.print();

// [6, 1, 2, 7, 5, 3, 4, 9, 8]
const minHeap = new MinHeap(orgArr);
minHeap.print();

// [1, 5, 2, 7, 6, 3, 4, 9, 8]
const maxPQ = new MaxPriorityQueue(orgArr);
maxPQ.print();

// [9, 8, 4, 7, 5, 2, 3, 1, 6]
const biTree = new BinaryTree(entries);
biTree.print();

// ___6___
// / \
// ___1_ _2_
Expand All @@ -43,7 +43,7 @@ biTree.print();
// / \
// 9 8
const bst = new BST(entries);
bst.print();

// _____5___
// / \
// _2_ _7_
Expand All @@ -52,7 +52,7 @@ bst.print();
// \ \
// 4 9
const rbTree = new RedBlackTree(entries);
rbTree.print();

// ___4___
// / \
// _2_ _6___
Expand All @@ -61,7 +61,7 @@ rbTree.print();
// / \
// 7 9
const avl = new AVLTree(entries);
avl.print();

// ___4___
// / \
// _2_ _6___
Expand All @@ -70,7 +70,7 @@ avl.print();
// / \
// 7 9
const treeMulti = new TreeMultiMap(entries);
treeMulti.print();

// ___4___
// / \
// _2_ _6___
Expand All @@ -79,10 +79,10 @@ treeMulti.print();
// / \
// 7 9
const hm = new HashMap(entries);
hm.print();

// [[6, "6"], [1, "1"], [2, "2"], [7, "7"], [5, "5"], [3, "3"], [4, "4"], [9, "9"], [8, "8"]]
const rbTreeH = new RedBlackTree(hm);
rbTreeH.print();

// ___4___
// / \
// _2_ _6___
Expand All @@ -91,10 +91,10 @@ rbTreeH.print();
// / \
// 7 9
const pq = new MinPriorityQueue(orgArr);
pq.print();

// [1, 5, 2, 7, 6, 3, 4, 9, 8]
const bst1 = new BST(pq);
bst1.print();

// _____5___
// / \
// _2_ _7_
Expand All @@ -103,10 +103,10 @@ bst1.print();
// \ \
// 4 9
const dq1 = new Deque(orgArr);
dq1.print();

// [6, 1, 2, 7, 5, 3, 4, 9, 8]
const rbTree1 = new RedBlackTree(dq1);
rbTree1.print();

// _____5___
// / \
// _2___ _7___
Expand All @@ -115,13 +115,13 @@ rbTree1.print();
// / /
// 3 8
const trie2 = new Trie(orgStrArr);
trie2.print();

// ['trie', 'trial', 'triangle', 'trick', 'trip', 'tree', 'trend', 'track', 'trace', 'transmit']
const heap2 = new Heap(trie2, { comparator: (a, b) => Number(a) - Number(b) });
heap2.print();

// ['transmit', 'trace', 'tree', 'trend', 'track', 'trial', 'trip', 'trie', 'trick', 'triangle']
const dq2 = new Deque(heap2);
dq2.print();

// ['transmit', 'trace', 'tree', 'trend', 'track', 'trial', 'trip', 'trie', 'trick', 'triangle']
const entries2 = dq2.map((el, i) => [i, el]);
const avl2 = new AVLTree(entries2);
Expand Down
Loading

0 comments on commit 1163246

Please sign in to comment.