Skip to content

Commit

Permalink
[BST, AVL] The 'get' method follows the binary search of a BST for bu…
Browse files Browse the repository at this point in the history
…g fixes during queries. [Project] The editor uses 'tsconfig.json' for code checking to be compatible with the 'test' directory, but compiles using their respective configuration files.
  • Loading branch information
zrwusa committed Nov 4, 2023
1 parent 0ab8054 commit 24a961f
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 62 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,40 @@ inherit the existing data structures to implement the customized ones you need.
optimal approach to data structure design.
## Benchmark
<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.12</td><td>470.70</td><td>24</td><td>0.00</td><td>3.55e-5</td></tr><tr><td>1000 add & delete randomly</td><td>5.12</td><td>195.21</td><td>11</td><td>0.01</td><td>8.78e-4</td></tr><tr><td>1000 addMany</td><td>3.95</td><td>253.32</td><td>18</td><td>0.00</td><td>0.00</td></tr><tr><td>1000 get</td><td>3.04</td><td>328.49</td><td>22</td><td>0.00</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'>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>13.44</td><td>74.39</td><td>4</td><td>0.01</td><td>0.00</td></tr><tr><td>1000 add & delete randomly</td><td>15.93</td><td>62.78</td><td>4</td><td>0.02</td><td>2.08e-4</td></tr><tr><td>1000 addMany</td><td>10.71</td><td>93.41</td><td>5</td><td>0.01</td><td>2.11e-4</td></tr><tr><td>1000 get</td><td>17.90</td><td>55.86</td><td>3</td><td>0.02</td><td>1.30e-4</td></tr><tr><td>1000 dfs</td><td>68.52</td><td>14.59</td><td>1</td><td>0.07</td><td>3.98e-4</td></tr><tr><td>1000 bfs</td><td>54.57</td><td>18.33</td><td>1</td><td>0.05</td><td>4.34e-4</td></tr><tr><td>1000 morris</td><td>37.37</td><td>26.76</td><td>2</td><td>0.04</td><td>3.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><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.15</td><td>465.28</td><td>24</td><td>0.00</td><td>1.79e-5</td></tr><tr><td>1000 add & delete randomly</td><td>5.08</td><td>196.92</td><td>10</td><td>0.01</td><td>4.34e-5</td></tr><tr><td>1000 addMany</td><td>2.14</td><td>467.28</td><td>24</td><td>0.00</td><td>4.18e-5</td></tr><tr><td>1000 get</td><td>2.35</td><td>426.21</td><td>22</td><td>0.00</td><td>5.24e-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>9846.76</td><td>505</td><td>1.02e-4</td><td>2.82e-6</td></tr><tr><td>1000 addEdge</td><td>6.23</td><td>160.47</td><td>9</td><td>0.01</td><td>5.72e-4</td></tr><tr><td>1000 getVertex</td><td>0.05</td><td>2.18e+4</td><td>1100</td><td>4.59e-5</td><td>3.84e-7</td></tr><tr><td>1000 getEdge</td><td>23.96</td><td>41.73</td><td>3</td><td>0.02</td><td>0.00</td></tr><tr><td>tarjan</td><td>217.41</td><td>4.60</td><td>1</td><td>0.22</td><td>0.01</td></tr><tr><td>tarjan all</td><td>242.30</td><td>4.13</td><td>1</td><td>0.24</td><td>0.06</td></tr><tr><td>topologicalSort</td><td>184.85</td><td>5.41</td><td>1</td><td>0.18</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.35</td><td>2823.44</td><td>149</td><td>3.54e-4</td><td>5.10e-5</td></tr><tr><td>1000 fib add & pop</td><td>3.92</td><td>255.12</td><td>14</td><td>0.00</td><td>6.68e-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>206.78</td><td>4.84</td><td>1</td><td>0.21</td><td>0.03</td></tr><tr><td>1000000 unshift & shift</td><td>170.95</td><td>5.85</td><td>1</td><td>0.17</td><td>0.04</td></tr><tr><td>1000 insertBefore</td><td>0.03</td><td>3.75e+4</td><td>1906</td><td>2.67e-5</td><td>3.24e-7</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.77</td><td>565.87</td><td>30</td><td>0.00</td><td>5.05e-5</td></tr><tr><td>1000 insertBefore</td><td>2.32</td><td>430.56</td><td>23</td><td>0.00</td><td>7.66e-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.45</td><td>87.31</td><td>5</td><td>0.01</td><td>1.45e-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>214.85</td><td>4.65</td><td>1</td><td>0.21</td><td>0.03</td></tr><tr><td>1000000 shift</td><td>26.08</td><td>38.34</td><td>3</td><td>0.03</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>44.32</td><td>22.56</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.64</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>56.20</td><td>17.79</td><td>1</td><td>0.06</td><td>0.01</td></tr><tr><td>100000 getWords</td><td>95.26</td><td>10.50</td><td>1</td><td>0.10</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'>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.22</td><td>449.77</td><td>23</td><td>0.00</td><td>2.65e-5</td></tr><tr><td>1000 add & delete randomly</td><td>11.58</td><td>86.37</td><td>5</td><td>0.01</td><td>5.00e-4</td></tr><tr><td>1000 addMany</td><td>3.10</td><td>322.62</td><td>17</td><td>0.00</td><td>1.23e-4</td></tr><tr><td>1000 get</td><td>24.91</td><td>40.14</td><td>3</td><td>0.02</td><td>7.25e-4</td></tr></table></div>
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
"name": "data-structure-typed",
"version": "1.41.5",
"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/index.js",
"module": "dist/mjs/index.js",
"types": "dist/mjs/index.d.ts",
"main": "dist/cjs/src/index.js",
"module": "dist/mjs/src/index.js",
"types": "dist/mjs/src/index.d.ts",
"umd:main": "dist/umd/data-structure-typed.min.js",
"exports": {
".": {
"import": "./dist/mjs/index.js",
"require": "./dist/cjs/index.js",
"types": "./dist/mjs/index.d.ts"
"import": "./dist/mjs/src/index.js",
"require": "./dist/cjs/src/index.js",
"types": "./dist/mjs/src/index.d.ts"
}
},
"scripts": {
"build": "npm run build:mjs && npm run build:cjs && npm run build:umd && npm run build:docs",
"build:mjs": "rm -rf dist/mjs && tsc -p tsconfig.json",
"build:mjs": "rm -rf dist/mjs && tsc -p tsconfig-mjs.json",
"build:cjs": "rm -rf dist/cjs && tsc -p tsconfig-cjs.json",
"build:umd": "tsup",
"build:docs": "typedoc --out docs ./src",
Expand Down
4 changes: 2 additions & 2 deletions src/data-structures/binary-tree/avl-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
* @param callback - The `callback` parameter is a function that takes a node as input and returns a
* value. This value is compared with the `identifier` parameter to determine if the node should be
* included in the result. The `callback` parameter has a default value of
* `((node: N) => node.key)`
* `this.defaultOneParamCallback`
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
*/
override delete<C extends BTNCallback<N>>(
identifier: ReturnType<C>,
callback: C = ((node: N) => node.key) as C
callback: C = this.defaultOneParamCallback as C
): BinaryTreeDeletedResult<N>[] {
if ((identifier as any) instanceof AVLTreeNode) callback = (node => node) as C;
const deletedResults = super.delete(identifier, callback);
Expand Down
Loading

0 comments on commit 24a961f

Please sign in to comment.