style: Prettier version updated. Code style adhered to Prettier strictly.

This commit is contained in:
Revone 2024-08-27 10:56:04 +12:00
parent ac1712ba04
commit 7e45aaf609
52 changed files with 1658 additions and 556 deletions

View file

@ -12,5 +12,6 @@ module.exports = {
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
"useTabs": false,
"semi": true,
}

View file

@ -823,43 +823,43 @@ Version 11.7.9
[//]: # (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>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>6.09</td><td>164.12</td><td>1.35e-4</td></tr><tr><td>100,000 add & poll</td><td>34.55</td><td>28.94</td><td>6.43e-4</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>8.07</td><td>123.93</td><td>0.00</td></tr><tr><td>100,000 add & poll</td><td>45.32</td><td>22.07</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="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.73</td><td>13.03</td><td>0.00</td></tr><tr><td>100,000 add randomly</td><td>80.67</td><td>12.40</td><td>0.00</td></tr><tr><td>100,000 get</td><td>110.86</td><td>9.02</td><td>0.00</td></tr><tr><td>100,000 iterator</td><td>24.99</td><td>40.02</td><td>0.00</td></tr><tr><td>100,000 add & delete orderly</td><td>152.66</td><td>6.55</td><td>0.00</td></tr><tr><td>100,000 add & delete randomly</td><td>230.75</td><td>4.33</td><td>0.00</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>77.03</td><td>12.98</td><td>0.00</td></tr><tr><td>100,000 add randomly</td><td>83.26</td><td>12.01</td><td>0.00</td></tr><tr><td>100,000 get</td><td>120.25</td><td>8.32</td><td>0.01</td></tr><tr><td>100,000 iterator</td><td>26.32</td><td>37.99</td><td>0.01</td></tr><tr><td>100,000 add & delete orderly</td><td>161.68</td><td>6.19</td><td>0.01</td></tr><tr><td>100,000 add & delete randomly</td><td>268.63</td><td>3.72</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'>queue</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>39.27</td><td>25.46</td><td>0.01</td></tr><tr><td>100,000 push & shift</td><td>4.53</td><td>220.81</td><td>4.84e-4</td></tr><tr><td>Native JS Array 100,000 push & shift</td><td>1948.05</td><td>0.51</td><td>0.02</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>45.55</td><td>21.96</td><td>0.02</td></tr><tr><td>100,000 push & shift</td><td>5.54</td><td>180.36</td><td>0.00</td></tr><tr><td>Native JS Array 100,000 push & shift</td><td>2467.71</td><td>0.41</td><td>0.20</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>deque</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>23.22</td><td>43.06</td><td>0.00</td></tr><tr><td>1,000,000 push & pop</td><td>29.68</td><td>33.69</td><td>0.00</td></tr><tr><td>1,000,000 push & shift</td><td>29.33</td><td>34.09</td><td>0.00</td></tr><tr><td>100,000 push & shift</td><td>3.10</td><td>323.01</td><td>2.47e-4</td></tr><tr><td>Native JS Array 100,000 push & shift</td><td>1942.12</td><td>0.51</td><td>0.02</td></tr><tr><td>100,000 unshift & shift</td><td>2.77</td><td>360.50</td><td>2.43e-4</td></tr><tr><td>Native JS Array 100,000 unshift & shift</td><td>3835.21</td><td>0.26</td><td>0.03</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>25.36</td><td>39.43</td><td>0.00</td></tr><tr><td>1,000,000 push & pop</td><td>32.13</td><td>31.12</td><td>0.00</td></tr><tr><td>1,000,000 push & shift</td><td>33.42</td><td>29.92</td><td>0.00</td></tr><tr><td>100,000 push & shift</td><td>3.59</td><td>278.92</td><td>3.21e-4</td></tr><tr><td>Native JS Array 100,000 push & shift</td><td>2427.03</td><td>0.41</td><td>0.21</td></tr><tr><td>100,000 unshift & shift</td><td>3.56</td><td>280.81</td><td>3.81e-4</td></tr><tr><td>Native JS Array 100,000 unshift & shift</td><td>4464.18</td><td>0.22</td><td>0.07</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>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 set</td><td>112.38</td><td>8.90</td><td>0.02</td></tr><tr><td>Native JS Map 1,000,000 set</td><td>199.97</td><td>5.00</td><td>0.01</td></tr><tr><td>Native JS Set 1,000,000 add</td><td>163.34</td><td>6.12</td><td>0.01</td></tr><tr><td>1,000,000 set & get</td><td>109.86</td><td>9.10</td><td>0.02</td></tr><tr><td>Native JS Map 1,000,000 set & get</td><td>255.33</td><td>3.92</td><td>0.00</td></tr><tr><td>Native JS Set 1,000,000 add & has</td><td>163.91</td><td>6.10</td><td>0.00</td></tr><tr><td>1,000,000 ObjKey set & get</td><td>317.89</td><td>3.15</td><td>0.04</td></tr><tr><td>Native JS Map 1,000,000 ObjKey set & get</td><td>282.99</td><td>3.53</td><td>0.03</td></tr><tr><td>Native JS Set 1,000,000 ObjKey add & has</td><td>253.93</td><td>3.94</td><td>0.03</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 set</td><td>313.05</td><td>3.19</td><td>0.07</td></tr><tr><td>Native JS Map 1,000,000 set</td><td>224.48</td><td>4.45</td><td>0.05</td></tr><tr><td>Native JS Set 1,000,000 add</td><td>203.46</td><td>4.91</td><td>0.05</td></tr><tr><td>1,000,000 set & get</td><td>281.79</td><td>3.55</td><td>0.07</td></tr><tr><td>Native JS Map 1,000,000 set & get</td><td>289.57</td><td>3.45</td><td>0.03</td></tr><tr><td>Native JS Set 1,000,000 add & has</td><td>195.73</td><td>5.11</td><td>0.02</td></tr><tr><td>1,000,000 ObjKey set & get</td><td>348.39</td><td>2.87</td><td>0.03</td></tr><tr><td>Native JS Map 1,000,000 ObjKey set & get</td><td>315.23</td><td>3.17</td><td>0.04</td></tr><tr><td>Native JS Set 1,000,000 ObjKey add & has</td><td>335.83</td><td>2.98</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>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 push</td><td>43.71</td><td>22.88</td><td>7.33e-4</td></tr><tr><td>100,000 getWords</td><td>83.63</td><td>11.96</td><td>0.00</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 push</td><td>48.09</td><td>20.79</td><td>0.00</td></tr><tr><td>100,000 getWords</td><td>93.17</td><td>10.73</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'>avl-tree</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>271.93</td><td>3.68</td><td>0.01</td></tr><tr><td>100,000 add randomly</td><td>318.27</td><td>3.14</td><td>0.00</td></tr><tr><td>100,000 get</td><td>128.85</td><td>7.76</td><td>0.00</td></tr><tr><td>100,000 iterator</td><td>29.09</td><td>34.38</td><td>0.00</td></tr><tr><td>100,000 add & delete orderly</td><td>435.48</td><td>2.30</td><td>7.44e-4</td></tr><tr><td>100,000 add & delete randomly</td><td>578.70</td><td>1.73</td><td>0.00</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>278.91</td><td>3.59</td><td>0.01</td></tr><tr><td>100,000 add randomly</td><td>350.65</td><td>2.85</td><td>0.02</td></tr><tr><td>100,000 get</td><td>154.97</td><td>6.45</td><td>0.03</td></tr><tr><td>100,000 iterator</td><td>34.78</td><td>28.75</td><td>0.02</td></tr><tr><td>100,000 add & delete orderly</td><td>445.45</td><td>2.24</td><td>0.00</td></tr><tr><td>100,000 add & delete randomly</td><td>616.61</td><td>1.62</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'>binary-tree-overall</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 RBTree add randomly</td><td>6.69</td><td>149.54</td><td>1.06e-4</td></tr><tr><td>10,000 RBTree get randomly</td><td>9.19</td><td>108.82</td><td>1.43e-4</td></tr><tr><td>10,000 RBTree add & delete randomly</td><td>18.54</td><td>53.94</td><td>1.73e-4</td></tr><tr><td>10,000 AVLTree add randomly</td><td>23.70</td><td>42.20</td><td>1.88e-4</td></tr><tr><td>10,000 AVLTree get randomly</td><td>9.89</td><td>101.11</td><td>0.00</td></tr><tr><td>10,000 AVLTree add & delete randomly</td><td>44.44</td><td>22.50</td><td>4.30e-4</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 RBTree add randomly</td><td>7.07</td><td>141.45</td><td>7.19e-4</td></tr><tr><td>10,000 RBTree get randomly</td><td>9.33</td><td>107.21</td><td>1.48e-4</td></tr><tr><td>10,000 RBTree add & delete randomly</td><td>18.60</td><td>53.77</td><td>3.93e-4</td></tr><tr><td>10,000 AVLTree add randomly</td><td>30.39</td><td>32.91</td><td>0.01</td></tr><tr><td>10,000 AVLTree get randomly</td><td>10.70</td><td>93.49</td><td>0.00</td></tr><tr><td>10,000 AVLTree add & delete randomly</td><td>46.04</td><td>21.72</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'>directed-graph</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000 addVertex</td><td>0.10</td><td>9766.65</td><td>9.83e-7</td></tr><tr><td>1,000 addEdge</td><td>6.15</td><td>162.57</td><td>7.99e-4</td></tr><tr><td>1,000 getVertex</td><td>0.05</td><td>2.18e+4</td><td>4.52e-7</td></tr><tr><td>1,000 getEdge</td><td>22.70</td><td>44.06</td><td>0.00</td></tr><tr><td>tarjan</td><td>203.00</td><td>4.93</td><td>0.01</td></tr><tr><td>topologicalSort</td><td>176.40</td><td>5.67</td><td>0.00</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000 addVertex</td><td>0.13</td><td>7502.53</td><td>6.69e-5</td></tr><tr><td>1,000 addEdge</td><td>7.93</td><td>126.13</td><td>0.00</td></tr><tr><td>1,000 getVertex</td><td>0.05</td><td>2.19e+4</td><td>1.17e-5</td></tr><tr><td>1,000 getEdge</td><td>18.65</td><td>53.61</td><td>0.00</td></tr><tr><td>tarjan</td><td>158.86</td><td>6.30</td><td>0.01</td></tr><tr><td>topologicalSort</td><td>141.91</td><td>7.05</td><td>0.01</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>doubly-linked-list</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>222.02</td><td>4.50</td><td>0.07</td></tr><tr><td>1,000,000 unshift</td><td>220.41</td><td>4.54</td><td>0.05</td></tr><tr><td>1,000,000 unshift & shift</td><td>185.31</td><td>5.40</td><td>0.01</td></tr><tr><td>1,000,000 addBefore</td><td>317.20</td><td>3.15</td><td>0.07</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>211.26</td><td>4.73</td><td>0.03</td></tr><tr><td>1,000,000 unshift</td><td>216.90</td><td>4.61</td><td>0.07</td></tr><tr><td>1,000,000 unshift & shift</td><td>208.45</td><td>4.80</td><td>0.05</td></tr><tr><td>1,000,000 addBefore</td><td>316.55</td><td>3.16</td><td>0.06</td></tr></table></div>
</div><div class="json-to-html-collapse clearfix 0">
<div class='collapsible level0' ><span class='json-to-html-label'>singly-linked-list</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push & shift</td><td>204.82</td><td>4.88</td><td>0.09</td></tr><tr><td>10,000 push & pop</td><td>221.88</td><td>4.51</td><td>0.03</td></tr><tr><td>10,000 addBefore</td><td>247.28</td><td>4.04</td><td>0.01</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push & shift</td><td>222.81</td><td>4.49</td><td>0.08</td></tr><tr><td>10,000 push & pop</td><td>235.91</td><td>4.24</td><td>0.01</td></tr><tr><td>10,000 addBefore</td><td>250.57</td><td>3.99</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'>priority-queue</span></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>26.97</td><td>37.08</td><td>7.97e-4</td></tr><tr><td>100,000 add & poll</td><td>74.55</td><td>13.41</td><td>5.19e-4</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>27.64</td><td>36.17</td><td>8.81e-4</td></tr><tr><td>100,000 add & poll</td><td>75.52</td><td>13.24</td><td>9.91e-4</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>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>35.54</td><td>28.14</td><td>0.00</td></tr><tr><td>1,000,000 push & pop</td><td>44.89</td><td>22.27</td><td>0.01</td></tr></table></div>
<div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>40.47</td><td>24.71</td><td>0.01</td></tr><tr><td>1,000,000 push & pop</td><td>47.47</td><td>21.07</td><td>0.01</td></tr></table></div>
</div>
[//]: # (No deletion!!! End of Replace Section)

1586
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{
"name": "data-structure-typed",
"version": "1.52.1",
"version": "1.52.2",
"description": "Javascript Data Structure. Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack. Benchmark compared with C++ STL. API aligned with ES6 and Java.util. Usability is comparable to Python",
"main": "dist/cjs/index.js",
"module": "dist/mjs/index.js",
@ -83,7 +83,7 @@
"istanbul-badges-readme": "^1.8.5",
"jest": "^29.7.0",
"js-sdsl": "^4.4.2",
"prettier": "^3.0.3",
"prettier": "^3.3.3",
"ts-jest": "^29.1.1",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",

View file

@ -42,7 +42,7 @@ export abstract class IterableElementBase<E, R, C> {
* allows the function to accept any number of arguments as an array. In this case, the `args`
* parameter is used to pass any number of arguments to the `_getIterator` method.
*/
* [Symbol.iterator](...args: any[]): IterableIterator<E> {
*[Symbol.iterator](...args: any[]): IterableIterator<E> {
yield* this._getIterator(...args);
}
@ -56,7 +56,7 @@ export abstract class IterableElementBase<E, R, C> {
*
* The function returns an iterator that yields all the values in the object.
*/
* values(): IterableIterator<E> {
*values(): IterableIterator<E> {
for (const item of this) {
yield item;
}

View file

@ -35,7 +35,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
* allows the function to accept any number of arguments as an array. In this case, the `args`
* parameter is used to pass any additional arguments to the `_getIterator` method.
*/
* [Symbol.iterator](...args: any[]): IterableIterator<[K, V]> {
*[Symbol.iterator](...args: any[]): IterableIterator<[K, V]> {
yield* this._getIterator(...args);
}
@ -50,7 +50,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
* The function returns an iterator that yields key-value pairs from the object, where the value can
* be undefined.
*/
* entries(): IterableIterator<[K, V | undefined]> {
*entries(): IterableIterator<[K, V | undefined]> {
for (const item of this) {
yield item;
}
@ -66,7 +66,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
*
* The function returns an iterator that yields the keys of a data structure.
*/
* keys(): IterableIterator<K> {
*keys(): IterableIterator<K> {
for (const item of this) {
yield item[0];
}
@ -82,7 +82,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
*
* The function returns an iterator that yields the values of a collection.
*/
* values(): IterableIterator<V> {
*values(): IterableIterator<V> {
for (const item of this) {
yield item[1];
}

View file

@ -63,20 +63,21 @@ export class AVLTreeMultiMapNode<
* The only distinction between a AVLTreeMultiMap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
*/
export class AVLTreeMultiMap<
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>,
TREE extends AVLTreeMultiMap<K, V, R, NODE, TREE> = AVLTreeMultiMap<
K,
V,
R,
NODE,
AVLTreeMultiMapNested<K, V, R, NODE>
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>,
TREE extends AVLTreeMultiMap<K, V, R, NODE, TREE> = AVLTreeMultiMap<
K,
V,
R,
NODE,
AVLTreeMultiMapNested<K, V, R, NODE>
>
>
>
extends AVLTree<K, V, R, NODE, TREE>
implements IBinaryTree<K, V, R, NODE, TREE> {
implements IBinaryTree<K, V, R, NODE, TREE>
{
/**
* The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
* @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an

View file

@ -66,14 +66,15 @@ export class AVLTreeNode<
* 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
*/
export class AVLTree<
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>,
TREE extends AVLTree<K, V, R, NODE, TREE> = AVLTree<K, V, R, NODE, AVLTreeNested<K, V, R, NODE>>
>
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>,
TREE extends AVLTree<K, V, R, NODE, TREE> = AVLTree<K, V, R, NODE, AVLTreeNested<K, V, R, NODE>>
>
extends BST<K, V, R, NODE, TREE>
implements IBinaryTree<K, V, R, NODE, TREE> {
implements IBinaryTree<K, V, R, NODE, TREE>
{
/**
* This is a constructor function for an AVLTree class that initializes the tree with keys, nodes,
* entries, or raw elements.
@ -503,7 +504,7 @@ export class AVLTree<
// Balance Restoration: If a balance issue is discovered after inserting a node, it requires balance restoration operations. Balance restoration includes four basic cases where rotation operations need to be performed to fix the balance:
switch (
this._balanceFactor(A) // second O(1)
) {
) {
case -2:
if (A && A.left) {
if (this._balanceFactor(A.left) <= 0) {

View file

@ -131,14 +131,15 @@ export class BinaryTreeNode<
*/
export class BinaryTree<
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>,
TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTree<K, V, R, NODE, BinaryTreeNested<K, V, R, NODE>>
>
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>,
TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTree<K, V, R, NODE, BinaryTreeNested<K, V, R, NODE>>
>
extends IterableEntryBase<K, V | undefined>
implements IBinaryTree<K, V, R, NODE, TREE> {
implements IBinaryTree<K, V, R, NODE, TREE>
{
iterationType: IterationType = 'ITERATIVE';
/**
@ -1155,8 +1156,8 @@ export class BinaryTree<
if (!this.isRealNode(node.right) || last === node.right) {
node = stack.pop();
if (this.isRealNode(node)) {
const leftMinHeight = this.isRealNode(node.left) ? depths.get(node.left) ?? -1 : -1;
const rightMinHeight = this.isRealNode(node.right) ? depths.get(node.right) ?? -1 : -1;
const leftMinHeight = this.isRealNode(node.left) ? (depths.get(node.left) ?? -1) : -1;
const rightMinHeight = this.isRealNode(node.right) ? (depths.get(node.right) ?? -1) : -1;
depths.set(node, 1 + Math.min(leftMinHeight, rightMinHeight));
last = node;
node = null;
@ -1937,7 +1938,7 @@ export class BinaryTree<
* initially set to the root node of the tree.
* @returns an IterableIterator<[K, V | undefined]>.
*/
protected* _getIterator(node = this.root): IterableIterator<[K, V | undefined]> {
protected *_getIterator(node = this.root): IterableIterator<[K, V | undefined]> {
if (!node) return;
if (this.iterationType === 'ITERATIVE') {

View file

@ -94,14 +94,15 @@ export class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNod
* 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
*/
export class BST<
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>,
TREE extends BST<K, V, R, NODE, TREE> = BST<K, V, R, NODE, BSTNested<K, V, R, NODE>>
>
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>,
TREE extends BST<K, V, R, NODE, TREE> = BST<K, V, R, NODE, BSTNested<K, V, R, NODE>>
>
extends BinaryTree<K, V, R, NODE, TREE>
implements IBinaryTree<K, V, R, NODE, TREE> {
implements IBinaryTree<K, V, R, NODE, TREE>
{
/**
* This is the constructor function for a Binary Search Tree class in TypeScript.
* @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
@ -786,8 +787,8 @@ export class BST<
if (!node.right || last === node.right) {
node = stack.pop();
if (node) {
const left = node.left ? depths.get(node.left) ?? -1 : -1;
const right = node.right ? depths.get(node.right) ?? -1 : -1;
const left = node.left ? (depths.get(node.left) ?? -1) : -1;
const right = node.right ? (depths.get(node.right) ?? -1) : -1;
if (Math.abs(left - right) > 1) return false;
depths.set(node, 1 + Math.max(left, right));
last = node;

View file

@ -53,14 +53,15 @@ export class RedBlackTreeNode<
}
export class RedBlackTree<
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>,
TREE extends RedBlackTree<K, V, R, NODE, TREE> = RedBlackTree<K, V, R, NODE, RedBlackTreeNested<K, V, R, NODE>>
>
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>,
TREE extends RedBlackTree<K, V, R, NODE, TREE> = RedBlackTree<K, V, R, NODE, RedBlackTreeNested<K, V, R, NODE>>
>
extends BST<K, V, R, NODE, TREE>
implements IBinaryTree<K, V, R, NODE, TREE> {
implements IBinaryTree<K, V, R, NODE, TREE>
{
/**
* This is the constructor function for a Red-Black Tree data structure in TypeScript.
* @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an

View file

@ -63,14 +63,15 @@ export class TreeMultiMapNode<
}
export class TreeMultiMap<
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>,
TREE extends TreeMultiMap<K, V, R, NODE, TREE> = TreeMultiMap<K, V, R, NODE, TreeMultiMapNested<K, V, R, NODE>>
>
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>,
TREE extends TreeMultiMap<K, V, R, NODE, TREE> = TreeMultiMap<K, V, R, NODE, TreeMultiMapNested<K, V, R, NODE>>
>
extends RedBlackTree<K, V, R, NODE, TREE>
implements IBinaryTree<K, V, R, NODE, TREE> {
implements IBinaryTree<K, V, R, NODE, TREE>
{
/**
* The constructor function initializes a TreeMultiMap object with optional initial data.
* @param keysOrNodesOrEntriesOrRawElements - The parameter `keysOrNodesOrEntriesOrRawElements` is an

View file

@ -61,13 +61,14 @@ export abstract class AbstractEdge<E = any> {
}
export abstract class AbstractGraph<
V = any,
E = any,
VO extends AbstractVertex<V> = AbstractVertex<V>,
EO extends AbstractEdge<E> = AbstractEdge<E>
>
V = any,
E = any,
VO extends AbstractVertex<V> = AbstractVertex<V>,
EO extends AbstractEdge<E> = AbstractEdge<E>
>
extends IterableEntryBase<VertexKey, V | undefined>
implements IGraph<V, E, VO, EO> {
implements IGraph<V, E, VO, EO>
{
constructor() {
super();
}
@ -618,14 +619,14 @@ export abstract class AbstractGraph<
}
getMinDist &&
distMap.forEach((d, v) => {
if (v !== srcVertex) {
if (d < minDist) {
minDist = d;
if (genPaths) minDest = v;
distMap.forEach((d, v) => {
if (v !== srcVertex) {
if (d < minDist) {
minDist = d;
if (genPaths) minDest = v;
}
}
}
});
});
genPaths && getPaths(minDest);
@ -1069,7 +1070,7 @@ export abstract class AbstractGraph<
return mapped;
}
protected* _getIterator(): IterableIterator<[VertexKey, V | undefined]> {
protected *_getIterator(): IterableIterator<[VertexKey, V | undefined]> {
for (const vertex of this._vertexMap.values()) {
yield [vertex.key, vertex.value];
}

View file

@ -46,13 +46,14 @@ export class DirectedEdge<E = any> extends AbstractEdge<E> {
}
export class DirectedGraph<
V = any,
E = any,
VO extends DirectedVertex<V> = DirectedVertex<V>,
EO extends DirectedEdge<E> = DirectedEdge<E>
>
V = any,
E = any,
VO extends DirectedVertex<V> = DirectedVertex<V>,
EO extends DirectedEdge<E> = DirectedEdge<E>
>
extends AbstractGraph<V, E, VO, EO>
implements IGraph<V, E, VO, EO> {
implements IGraph<V, E, VO, EO>
{
/**
* The constructor function initializes an instance of a class.
*/

View file

@ -43,13 +43,14 @@ export class UndirectedEdge<E = number> extends AbstractEdge<E> {
}
export class UndirectedGraph<
V = any,
E = any,
VO extends UndirectedVertex<V> = UndirectedVertex<V>,
EO extends UndirectedEdge<E> = UndirectedEdge<E>
>
V = any,
E = any,
VO extends UndirectedVertex<V> = UndirectedVertex<V>,
EO extends UndirectedEdge<E> = UndirectedEdge<E>
>
extends AbstractGraph<V, E, VO, EO>
implements IGraph<V, E, VO, EO> {
implements IGraph<V, E, VO, EO>
{
/**
* The constructor initializes a new Map object to store edgeMap.
*/

View file

@ -322,7 +322,7 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
* The function returns an iterator that yields key-value pairs from both an object store and an
* object map.
*/
protected* _getIterator(): IterableIterator<[K, V]> {
protected *_getIterator(): IterableIterator<[K, V]> {
for (const node of Object.values(this.store)) {
yield [node.key, node.value] as [K, V];
}
@ -537,7 +537,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
/**
* The `begin()` function in TypeScript iterates over a linked list and yields key-value pairs.
*/
* begin() {
*begin() {
let node = this.head;
while (node !== this._sentinel) {
yield [node.key, node.value];
@ -549,7 +549,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
* The function `reverseBegin()` iterates over a linked list in reverse order, yielding each node's
* key and value.
*/
* reverseBegin() {
*reverseBegin() {
let node = this.tail;
while (node !== this._sentinel) {
yield [node.key, node.value];
@ -942,7 +942,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
*
* The above function is an iterator that yields key-value pairs from a linked list.
*/
protected* _getIterator() {
protected *_getIterator() {
let node = this.head;
while (node !== this._sentinel) {
yield [node.key, node.value] as [K, V];

View file

@ -367,7 +367,7 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R, Heap<E, R>
/**
* The function `_getIterator` returns an iterable iterator for the elements in the class.
*/
protected* _getIterator(): IterableIterator<E> {
protected *_getIterator(): IterableIterator<E> {
for (const element of this.elements) {
yield element;
}

View file

@ -803,7 +803,7 @@ export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R
/**
* The function returns an iterator that iterates over the values of a linked list.
*/
protected* _getIterator(): IterableIterator<E> {
protected *_getIterator(): IterableIterator<E> {
let current = this.head;
while (current) {

View file

@ -751,7 +751,7 @@ export class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R
/**
* The function `_getIterator` returns an iterable iterator that yields the values of a linked list.
*/
protected* _getIterator(): IterableIterator<E> {
protected *_getIterator(): IterableIterator<E> {
let current = this.head;
while (current) {

View file

@ -344,7 +344,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
/**
* The below function is a generator that yields elements from a collection one by one.
*/
* begin(): Generator<E> {
*begin(): Generator<E> {
let index = 0;
while (index < this.size) {
yield this.at(index);
@ -356,7 +356,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
* The function `reverseBegin()` is a generator that yields elements in reverse order starting from
* the last element.
*/
* reverseBegin(): Generator<E> {
*reverseBegin(): Generator<E> {
let index = this.size - 1;
while (index >= 0) {
yield this.at(index);
@ -848,7 +848,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
* The above function is an implementation of the iterator protocol in TypeScript, allowing the
* object to be iterated over using a for...of loop.
*/
protected* _getIterator(): IterableIterator<E> {
protected *_getIterator(): IterableIterator<E> {
for (let i = 0; i < this.size; ++i) {
yield this.at(i);
}

View file

@ -274,7 +274,7 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R, Stack<E,
* Custom iterator for the Stack class.
* @returns An iterator object.
*/
protected* _getIterator(): IterableIterator<E> {
protected *_getIterator(): IterableIterator<E> {
for (let i = 0; i < this.elements.length; i++) {
yield this.elements[i];
}

View file

@ -560,7 +560,7 @@ export class Trie<R = any> extends IterableElementBase<string, R, Trie<R>> {
* The function `_getIterator` returns an iterable iterator that performs a depth-first search on a
* trie data structure and yields all the paths to the end nodes.
*/
protected* _getIterator(): IterableIterator<string> {
protected *_getIterator(): IterableIterator<string> {
function* _dfs(node: TrieNode, path: string): IterableIterator<string> {
if (node.isEnd) {
yield path;

View file

@ -2,12 +2,12 @@ export type VertexKey = string | number;
export type DijkstraResult<V> =
| {
distMap: Map<V, number>;
distPaths?: Map<V, V[]>;
preMap: Map<V, V | undefined>;
seen: Set<V>;
paths: V[][];
minDist: number;
minPath: V[];
}
distMap: Map<V, number>;
distPaths?: Map<V, V[]>;
preMap: Map<V, V | undefined>;
seen: Set<V>;
paths: V[][];
minDist: number;
minPath: V[];
}
| undefined;

View file

@ -1,6 +1,6 @@
import { IterableElementBaseOptions } from '../base';
export type DequeOptions<E, R> = {
bucketSize?: number,
maxLen?: number
bucketSize?: number;
maxLen?: number;
} & IterableElementBaseOptions<E, R>;

View file

@ -13,9 +13,9 @@ export type Comparable =
| bigint
| boolean
| ({ [key in string]: any } & {
valueOf(): Comparable;
})
valueOf(): Comparable;
})
| ({ [key in string]: any } & {
toString(): Comparable;
})
toString(): Comparable;
})
| (() => Comparable);

View file

@ -226,7 +226,10 @@ describe('Individual package BST operations test', () => {
expect(leftMost?.key).toBe(1);
const node15 = objBST.getNode(15);
expect(node15?.value).toEqual({ key: 15, keyA: 15 });
expect(node15?.value).toEqual({
key: 15,
keyA: 15
});
const minNodeBySpecificNode = node15 && objBST.getLeftMost(node15);
expect(minNodeBySpecificNode?.key).toBe(12);

View file

@ -30,7 +30,9 @@ suite
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
})
.add(`MJS PQ ${TEN_THOUSAND.toLocaleString()} add`, () => {
const pq = new MJSPriorityQueue<number>([], { comparator: (a, b) => b - a });
const pq = new MJSPriorityQueue<number>([], {
comparator: (a, b) => b - a
});
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
});
@ -43,19 +45,25 @@ if (isCompetitor) {
suite
.add(`SRC PQ ${TEN_THOUSAND.toLocaleString()} add & poll`, () => {
const pq = new SRCPriorityQueue<number>([], { comparator: (a, b) => b - a });
const pq = new SRCPriorityQueue<number>([], {
comparator: (a, b) => b - a
});
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
for (let i = 0; i < TEN_THOUSAND; i++) pq.poll();
})
.add(`CJS PQ ${TEN_THOUSAND.toLocaleString()} add & poll`, () => {
const pq = new CJSPriorityQueue<number>([], { comparator: (a, b) => b - a });
const pq = new CJSPriorityQueue<number>([], {
comparator: (a, b) => b - a
});
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
for (let i = 0; i < TEN_THOUSAND; i++) pq.poll();
})
.add(`MJS PQ ${TEN_THOUSAND.toLocaleString()} add & poll`, () => {
const pq = new MJSPriorityQueue<number>([], { comparator: (a, b) => b - a });
const pq = new MJSPriorityQueue<number>([], {
comparator: (a, b) => b - a
});
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
for (let i = 0; i < TEN_THOUSAND; i++) pq.poll();

View file

@ -9,11 +9,15 @@ const { HUNDRED_THOUSAND } = magnitude;
suite
.add(`${HUNDRED_THOUSAND.toLocaleString()} add`, () => {
const heap = new PriorityQueue<number>([], { comparator: (a, b) => b - a });
const heap = new PriorityQueue<number>([], {
comparator: (a, b) => b - a
});
for (let i = 0; i < HUNDRED_THOUSAND; i++) heap.add(i);
})
.add(`${HUNDRED_THOUSAND.toLocaleString()} add & poll`, () => {
const heap = new PriorityQueue<number>([], { comparator: (a, b) => b - a });
const heap = new PriorityQueue<number>([], {
comparator: (a, b) => b - a
});
for (let i = 0; i < HUNDRED_THOUSAND; i++) heap.add(i);
for (let i = 0; i < HUNDRED_THOUSAND; i++) heap.poll();

View file

@ -51,11 +51,19 @@ testFiles.forEach((file: string) => {
const testName = path.basename(file, '.test.ts');
const testFunction = require(file);
const { suite } = testFunction;
if (suite) performanceTests.push({ testName, suite, file });
if (suite)
performanceTests.push({
testName,
suite,
file
});
});
const composeReport = () => {
if (!fs.existsSync(reportDistPath)) fs.mkdirSync(reportDistPath, { recursive: true });
if (!fs.existsSync(reportDistPath))
fs.mkdirSync(reportDistPath, {
recursive: true
});
const filePath = path.join(reportDistPath, 'report.json');
const htmlFilePath = path.join(reportDistPath, 'report.html');
@ -114,9 +122,18 @@ const composeReport = () => {
{
'<>': 'tr',
html: [
{ '<>': 'td', html: '${name}' },
{ '<>': 'td', html: '${periodMS}' },
{ '<>': 'td', html: '${mean}' }
{
'<>': 'td',
html: '${name}'
},
{
'<>': 'td',
html: '${periodMS}'
},
{
'<>': 'td',
html: '${mean}'
}
]
}
]
@ -242,9 +259,7 @@ sortedPerformanceTests.forEach(item => {
console.log(
// `Files: ${GREEN}${testFileCount}${END} `,
// `Suites: ${GREEN}${performanceTests.length}${END} `,
`Suites Progress: ${isDone ? GREEN : YELLOW}${completedCount}${END}/${isDone ? GREEN : YELLOW}${
performanceTests.length
}${END}`,
`Suites Progress: ${isDone ? GREEN : YELLOW}${completedCount}${END}/${isDone ? GREEN : YELLOW}${performanceTests.length}${END}`,
`Time: ${isTimeWarn ? YELLOW : GREEN}${runTime}s${END}`
);
if (isDone) {

View file

@ -1,3 +1,7 @@
import * as Benchmark from 'benchmark';
export type PerformanceTest = { testName: string; suite: Benchmark.Suite; file: string };
export type PerformanceTest = {
testName: string;
suite: Benchmark.Suite;
file: string;
};

View file

@ -1 +1,5 @@
export type Json2htmlOptions = { plainHtml?: boolean } & Partial<{ [key: string]: any }>;
export type Json2htmlOptions = {
plainHtml?: boolean;
} & Partial<{
[key: string]: any;
}>;

View file

@ -291,7 +291,9 @@ describe('AVLTreeMultiMap operations test1', () => {
describe('AVLTreeMultiMap operations test recursively1', () => {
it('should perform various operations on a Binary Search Tree with numeric values1', () => {
const treeMultimap = new AVLTreeMultiMap<number>([], { iterationType: 'RECURSIVE' });
const treeMultimap = new AVLTreeMultiMap<number>([], {
iterationType: 'RECURSIVE'
});
expect(treeMultimap instanceof AVLTreeMultiMap);
treeMultimap.add([11, 11]);
@ -741,7 +743,9 @@ describe('AVLTree toEntryFn', () => {
it('should toEntryFn 3', () => {
const tree = new AVLTreeMultiMap<{ obj: { id: number } }, number>(
[{ obj: { id: 1 } }, { obj: { id: 2 } }, { obj: { id: 3 } }, { obj: { id: 4 } }, { obj: { id: 5 } }],
{ comparator: (a, b) => a.obj.id - b.obj.id }
{
comparator: (a, b) => a.obj.id - b.obj.id
}
);
const expected = [

View file

@ -228,7 +228,10 @@ describe('AVLTree APIs test', () => {
avl.add(1);
const node2 = new AVLTreeNode(2);
avl.add(node2);
const node3 = new AVLTreeNode(3, { id: 3, text: 'text3' });
const node3 = new AVLTreeNode(3, {
id: 3,
text: 'text3'
});
avl.add(node3);
avl.add([3, { id: 3, text: 'text33' }]);
@ -314,7 +317,10 @@ describe('AVLTree', () => {
avl.add(1);
const node2 = new AVLTreeNode(2);
avl.add(node2);
const node3 = new AVLTreeNode(3, { id: 3, text: 'text3' });
const node3 = new AVLTreeNode(3, {
id: 3,
text: 'text3'
});
avl.add(node3);
avl.add([3, { id: 3, text: 'text33' }]);

View file

@ -8,13 +8,18 @@ describe('BinaryIndexedTree simple', () => {
beforeEach(() => {
//Create a new BinaryIndexedTree instance before each test case
bit = new BinaryIndexedTree({ frequency: 0, max: 10 }); // Modify the value of max as needed
bit = new BinaryIndexedTree({
frequency: 0,
max: 10
}); // Modify the value of max as needed
});
it('should initialize correctly', () => {
expect(bit.freq).toBe(0);
expect(bit.max).toBe(10);
expect(bit.freqMap).toEqual({ 0: 0 }); // Modify the initialized record value according to the actual situation
expect(bit.freqMap).toEqual({
0: 0
}); // Modify the initialized record value according to the actual situation
// More initialization checks can be added
});
@ -54,7 +59,10 @@ describe('BinaryIndexedTree', () => {
let bit: BinaryIndexedTree;
beforeEach(function () {
bit = new BinaryIndexedTree({ frequency, max });
bit = new BinaryIndexedTree({
frequency,
max
});
});
it('should validate the index', function () {
expect(() => bit.readSingle(-1)).toThrow('Index out of range');
@ -73,7 +81,10 @@ describe('BinaryIndexedTree', () => {
it('should frequency and max', function () {
const frequency = 200;
const max = 1000;
const bit = new BinaryIndexedTree({ frequency, max });
const bit = new BinaryIndexedTree({
frequency,
max
});
expect(bit.freq).toBe(frequency);
expect(bit.max).toBe(max);
@ -123,7 +134,9 @@ describe('designated values', function () {
let bit: BinaryIndexedTree;
beforeEach(function () {
bit = new BinaryIndexedTree({ max: array.length });
bit = new BinaryIndexedTree({
max: array.length
});
array.forEach((value, i) => bit.writeSingle(i, value));
});
@ -182,7 +195,9 @@ describe('descending sequence', function () {
let bit: BinaryIndexedTree;
beforeEach(function () {
bit = new BinaryIndexedTree({ max: array.length });
bit = new BinaryIndexedTree({
max: array.length
});
array.forEach((value, i) => bit.writeSingle(i, value));
});
@ -219,7 +234,9 @@ describe('descending sequence', function () {
describe('BinaryIndexedTree additional tests', () => {
it('should handle read method correctly', () => {
const bit = new BinaryIndexedTree({ max: 10 });
const bit = new BinaryIndexedTree({
max: 10
});
bit.writeSingle(2, 10);
bit.writeSingle(5, 20);
bit.writeSingle(8, 30);
@ -227,7 +244,9 @@ describe('BinaryIndexedTree additional tests', () => {
});
it('should handle consecutive operations', () => {
const bit = new BinaryIndexedTree({ max: 10 });
const bit = new BinaryIndexedTree({
max: 10
});
bit.writeSingle(2, 10);
bit.update(2, 5);
expect(bit.readSingle(2)).toBe(15);
@ -237,7 +256,9 @@ describe('BinaryIndexedTree additional tests', () => {
});
it('should handle frequent increment updates', () => {
const bit = new BinaryIndexedTree({ max: 10 });
const bit = new BinaryIndexedTree({
max: 10
});
for (let i = 0; i < 10; i++) {
bit.update(2, 5);
}
@ -245,7 +266,9 @@ describe('BinaryIndexedTree additional tests', () => {
});
it('should handle edge cases', () => {
const bit = new BinaryIndexedTree({ max: 10 });
const bit = new BinaryIndexedTree({
max: 10
});
bit.writeSingle(9, 100);
expect(bit.readSingle(9)).toBe(100);
expect(bit.lowerBound(200)).toBe(10);
@ -291,7 +314,9 @@ describe('', () => {
constructor(nums: number[]) {
this._nums = nums;
this._tree = new BinaryIndexedTree({ max: nums.length + 1 });
this._tree = new BinaryIndexedTree({
max: nums.length + 1
});
for (let i = 0; i < nums.length; i++) {
this._tree.update(i + 1, nums[i]);
}

View file

@ -570,7 +570,9 @@ describe('BinaryTree', () => {
let tree: BinaryTree<number, string>;
beforeEach(() => {
tree = new BinaryTree<number, string>([], { iterationType: 'RECURSIVE' });
tree = new BinaryTree<number, string>([], {
iterationType: 'RECURSIVE'
});
});
afterEach(() => {

View file

@ -252,7 +252,10 @@ describe('BST operations test', () => {
expect(leftMost?.key).toBe(1);
const node15 = objBST.getNode(15);
expect(node15?.value).toEqual({ name: 'Alice', age: 15 });
expect(node15?.value).toEqual({
name: 'Alice',
age: 15
});
const minNodeBySpecificNode = node15 && objBST.getLeftMost(node15);
expect(minNodeBySpecificNode?.key).toBe(12);
@ -411,7 +414,9 @@ describe('BST operations test', () => {
describe('BST operations test recursively', () => {
it('should perform various operations on a Binary Search Tree with numeric values', () => {
const bst = new BST<number>([], { iterationType: 'RECURSIVE' });
const bst = new BST<number>([], {
iterationType: 'RECURSIVE'
});
expect(bst).toBeInstanceOf(BST);
bst.add([11, 11]);
bst.add([3, 3]);
@ -626,7 +631,10 @@ describe('BST operations test recursively', () => {
expect(objBST.has(6)).toBe(true);
const node6 = objBST.getNode(6);
expect(objBST.get(6)).toEqual({ key: 6, keyA: 6 });
expect(objBST.get(6)).toEqual({
key: 6,
keyA: 6
});
expect(node6 && objBST.getHeight(node6)).toBe(2);
expect(node6 && objBST.getDepth(node6)).toBe(3);
@ -640,7 +648,10 @@ describe('BST operations test recursively', () => {
expect(leftMost?.key).toBe(1);
const node15 = objBST.getNode(15);
expect(node15?.value).toEqual({ key: 15, keyA: 15 });
expect(node15?.value).toEqual({
key: 15,
keyA: 15
});
const minNodeBySpecificNode = node15 && objBST.getLeftMost(node15);
expect(minNodeBySpecificNode?.key).toBe(12);
@ -869,7 +880,9 @@ describe('BST isBST', function () {
});
test('isBST when variant is Max', () => {
const bst = new BST<number, number>([1, 2, 3, 9, 8, 5, 6, 7, 4], { comparator: (a, b) => b - a });
const bst = new BST<number, number>([1, 2, 3, 9, 8, 5, 6, 7, 4], {
comparator: (a, b) => b - a
});
bst.addMany([1, 2, 3, 9, 8, 5, 6, 7, 4]);
expect(bst.isBST()).toBe(true);
});

View file

@ -350,7 +350,9 @@ describe('TreeMultiMap operations test1', () => {
describe('TreeMultiMap operations test recursively1', () => {
it('should perform various operations on a Binary Search Tree with numeric values1', () => {
const tmm = new TreeMultiMap<number>([], { iterationType: 'RECURSIVE' });
const tmm = new TreeMultiMap<number>([], {
iterationType: 'RECURSIVE'
});
expect(tmm instanceof TreeMultiMap);
tmm.add([11, 11]);

View file

@ -81,8 +81,7 @@ class MyGraph<
return true;
}
clear(): void {
}
clear(): void {}
clone(): any {
return {};
@ -96,8 +95,7 @@ class MyGraph<
describe('AbstractGraph Operation Test', () => {
const myGraph: MyGraph<number, string> = new MyGraph<number, string>();
beforeEach(() => {
});
beforeEach(() => {});
it('should edge cases', function () {
myGraph.addVertex('A', 1);
myGraph.addVertex('B', 2);

View file

@ -998,7 +998,6 @@ describe('DirectedGraph tarjan', () => {
describe('delete', () => {
it(`deleteVertex deletes all of it's neighbors from the inEdge Map`, () => {
const graph = new DirectedGraph();
graph.addVertex('A');
graph.addVertex('B');
@ -1008,18 +1007,18 @@ describe('delete', () => {
graph.addEdge('C', 'A');
// 'Incoming to A should contain ['B','C']
expect(graph.incomingEdgesOf('A').map((e) => e.src)).toEqual(['B','C']); // ['B','C']
expect(graph.incomingEdgesOf('A').map(e => e.src)).toEqual(['B', 'C']); // ['B','C']
// Now delete B, which has no direct link to C, only that C -> A.
graph.deleteVertex('B');
// Now if we do the same call to incoming edges for we should get only ['C']
expect(graph.incomingEdgesOf('A').map((e) => e.src)).toEqual(['C']); // [];
expect(graph.incomingEdgesOf('A').map(e => e.src)).toEqual(['C']); // [];
// but it only shows an empty array, since we deleted all of `A's edges, not just the one to `B`.
// If we check C, it correctly shows A as an outgoing edge,
// even though A no longer has any knowledge of C linking to it.
expect(graph.outgoingEdgesOf('C').map((e) => e.dest)).toEqual(['A']);
expect(graph.outgoingEdgesOf('C').map(e => e.dest)).toEqual(['A']);
});
})
});

View file

@ -147,7 +147,9 @@ describe('HashMap', () => {
}
}
const eHM = new ExtendedHashMap<string, number>([], { someOtherParam: 'someOtherParam' });
const eHM = new ExtendedHashMap<string, number>([], {
someOtherParam: 'someOtherParam'
});
eHM.set('one', 1);
expect(eHM.get('one')).toBe(1);
});
@ -357,7 +359,9 @@ describe('LinkedHashMap', () => {
it('should handle number keys correctly', () => {
hashMap.set(999, { a: '999Value' });
expect(hashMap.get(999)).toEqual({ a: '999Value' });
expect(hashMap.get(999)).toEqual({
a: '999Value'
});
});
it('should update the value for an existing key', () => {

View file

@ -2,7 +2,6 @@ import { FibonacciHeap, Heap, MaxHeap, MinHeap } from '../../../../src';
import { logBigOMetricsWrap } from '../../../utils';
describe('Heap Operation Test', () => {
it('should heap add and delete work well', function () {
const hp = new MinHeap<number>();
@ -47,7 +46,9 @@ describe('Heap Operation Test', () => {
});
it('should clone', function () {
const minNumHeap = new Heap<string>([], { comparator: (a, b) => Number(a) - Number(b) });
const minNumHeap = new Heap<string>([], {
comparator: (a, b) => Number(a) - Number(b)
});
minNumHeap.add('1');
minNumHeap.add('6');
minNumHeap.add('2');
@ -64,13 +65,21 @@ describe('Heap Operation Test', () => {
});
it('should object heap work well', function () {
const minHeap = new MinHeap<{ a: string; key: number }>([], { comparator: (a, b) => a.key - b.key });
const minHeap = new MinHeap<{
a: string;
key: number;
}>([], {
comparator: (a, b) => a.key - b.key
});
minHeap.add({ key: 1, a: 'a1' });
minHeap.add({ key: 6, a: 'a6' });
minHeap.add({ key: 2, a: 'a2' });
minHeap.add({ key: 0, a: 'a0' });
expect(minHeap.peek()).toEqual({ a: 'a0', key: 0 });
expect(minHeap.peek()).toEqual({
a: 'a0',
key: 0
});
expect(minHeap.toArray().map(item => ({ a: item.a }))).toEqual([
{ a: 'a0' },
{ a: 'a1' },
@ -80,18 +89,28 @@ describe('Heap Operation Test', () => {
let i = 0;
const expectPolled = [{ a: 'a0' }, { a: 'a1' }, { a: 'a2' }, { a: 'a6' }];
while (minHeap.size > 0) {
expect({ a: minHeap.poll()?.a }).toEqual(expectPolled[i]);
expect({
a: minHeap.poll()?.a
}).toEqual(expectPolled[i]);
i++;
}
const maxHeap = new MaxHeap<{ key: number; a: string }>([], { comparator: (a, b) => b.key - a.key });
const maxHeap = new MaxHeap<{
key: number;
a: string;
}>([], {
comparator: (a, b) => b.key - a.key
});
maxHeap.add({ key: 1, a: 'a1' });
maxHeap.add({ key: 6, a: 'a6' });
maxHeap.add({ key: 5, a: 'a5' });
maxHeap.add({ key: 2, a: 'a2' });
maxHeap.add({ key: 0, a: 'a0' });
maxHeap.add({ key: 9, a: 'a9' });
expect(maxHeap.peek()).toEqual({ a: 'a9', key: 9 });
expect(maxHeap.peek()).toEqual({
a: 'a9',
key: 9
});
expect(maxHeap.toArray().map(item => ({ a: item.a }))).toEqual([
{ a: 'a9' },
{ a: 'a2' },
@ -103,13 +122,18 @@ describe('Heap Operation Test', () => {
const maxExpectPolled = [{ a: 'a9' }, { a: 'a6' }, { a: 'a5' }, { a: 'a2' }, { a: 'a1' }, { a: 'a0' }];
let maxI = 0;
while (maxHeap.size > 0) {
expect({ a: maxHeap.poll()?.a }).toEqual(maxExpectPolled[maxI]);
expect({
a: maxHeap.poll()?.a
}).toEqual(maxExpectPolled[maxI]);
maxI++;
}
});
it('should object heap map & filter', function () {
const minHeap = new MinHeap<{ a: string; key: number }>(
const minHeap = new MinHeap<{
a: string;
key: number;
}>(
[
{ key: 1, a: 'a1' },
{ key: 6, a: 'a6' },
@ -119,7 +143,9 @@ describe('Heap Operation Test', () => {
{ key: 4, a: 'a4' },
{ key: 0, a: 'a0' }
],
{ comparator: (a, b) => a.key - b.key }
{
comparator: (a, b) => a.key - b.key
}
);
const mappedMinHeap = minHeap.map(
@ -147,7 +173,9 @@ describe('Heap Operation Test', () => {
});
it('should object heap', () => {
const heap = new Heap<{ rawItem: { id: number } }>(
const heap = new Heap<{
rawItem: { id: number };
}>(
[
{ rawItem: { id: 4 } },
{ rawItem: { id: 8 } },
@ -157,7 +185,9 @@ describe('Heap Operation Test', () => {
{ rawItem: { id: 3 } },
{ rawItem: { id: 5 } }
],
{ comparator: (a, b) => a.rawItem.id - b.rawItem.id }
{
comparator: (a, b) => a.rawItem.id - b.rawItem.id
}
);
expect([...heap.sort()]).toEqual([
@ -182,7 +212,9 @@ describe('Heap Operation Test', () => {
{ rawItem: { id: 3 } },
{ rawItem: { id: 5 } }
],
{ toElementFn: rawElement => rawElement.rawItem.id }
{
toElementFn: rawElement => rawElement.rawItem.id
}
);
expect([...heap.sort()]).toEqual([1, 3, 4, 5, 6, 7, 8]);

View file

@ -5,7 +5,9 @@ describe('MaxHeap', () => {
let maxHeap: MaxHeap<number>;
beforeEach(() => {
maxHeap = new MaxHeap<number>([], { comparator: numberComparator });
maxHeap = new MaxHeap<number>([], {
comparator: numberComparator
});
});
it('add and poll elements in descending order', () => {
@ -51,7 +53,10 @@ describe('MaxHeap', () => {
});
it('should object heap map & filter', function () {
const maxHeap = new MaxHeap<{ a: string; key: number }>(
const maxHeap = new MaxHeap<{
a: string;
key: number;
}>(
[
{ key: 1, a: 'a1' },
{ key: 6, a: 'a6' },
@ -61,7 +66,9 @@ describe('MaxHeap', () => {
{ key: 4, a: 'a4' },
{ key: 0, a: 'a0' }
],
{ comparator: (a, b) => b.key - a.key }
{
comparator: (a, b) => b.key - a.key
}
);
const mappedMaxHeap = maxHeap.map(

View file

@ -5,7 +5,9 @@ describe('MinHeap', () => {
let minHeap: MinHeap<number>;
beforeEach(() => {
minHeap = new MinHeap<number>([], { comparator: numberComparator });
minHeap = new MinHeap<number>([], {
comparator: numberComparator
});
});
it('add and poll elements in ascending order', () => {

View file

@ -79,7 +79,9 @@ describe('DoublyLinkedList Operation Test', () => {
describe('DoublyLinkedList Operation Test', () => {
let list: DoublyLinkedList<number>;
let objectList: DoublyLinkedList<{ keyA: number }>;
let objectList: DoublyLinkedList<{
keyA: number;
}>;
beforeEach(() => {
list = new DoublyLinkedList();

View file

@ -11,10 +11,14 @@ describe('SinglyLinkedListNode', () => {
describe('SinglyLinkedList Operation Test', () => {
let list: SinglyLinkedList<number>;
let objectList: SinglyLinkedList<{ keyA: number }>;
let objectList: SinglyLinkedList<{
keyA: number;
}>;
beforeEach(() => {
list = new SinglyLinkedList<number>();
objectList = new SinglyLinkedList<{ keyA: number }>();
objectList = new SinglyLinkedList<{
keyA: number;
}>();
});
describe('push', () => {

View file

@ -16,7 +16,11 @@ describe('MaxPriorityQueue Operation Test', () => {
});
it('should add elements and maintain heap property in a object MaxPriorityQueue', () => {
const priorityQueue = new MaxPriorityQueue<{ keyA: number }>([], { comparator: (a, b) => b.keyA - a.keyA });
const priorityQueue = new MaxPriorityQueue<{
keyA: number;
}>([], {
comparator: (a, b) => b.keyA - a.keyA
});
priorityQueue.refill([{ keyA: 5 }, { keyA: 3 }, { keyA: 1 }]);
priorityQueue.add({ keyA: 7 });
@ -52,7 +56,9 @@ describe('MaxPriorityQueue Operation Test', () => {
it('should correctly heapify an array', () => {
const array = [5, 3, 7, 1];
const heap = MaxPriorityQueue.heapify<number>(array, { comparator: (a, b) => b - a });
const heap = MaxPriorityQueue.heapify<number>(array, {
comparator: (a, b) => b - a
});
heap.refill(array);
expect(heap.poll()).toBe(7);
@ -64,7 +70,11 @@ describe('MaxPriorityQueue Operation Test', () => {
it('should correctly heapify an object array', () => {
const elements = [{ keyA: 5 }, { keyA: 3 }, { keyA: 7 }, { keyA: 1 }];
debugger;
const maxPQ = MaxPriorityQueue.heapify<{ keyA: number }>(elements, { comparator: (a, b) => b.keyA - a.keyA });
const maxPQ = MaxPriorityQueue.heapify<{
keyA: number;
}>(elements, {
comparator: (a, b) => b.keyA - a.keyA
});
expect(maxPQ.poll()?.keyA).toBe(7);
expect(maxPQ.poll()?.keyA).toBe(5);
@ -73,7 +83,9 @@ describe('MaxPriorityQueue Operation Test', () => {
});
it('should object priority queue', () => {
const maxPQ = new MaxPriorityQueue<{ rawItem: { id: number } }>(
const maxPQ = new MaxPriorityQueue<{
rawItem: { id: number };
}>(
[
{ rawItem: { id: 4 } },
{ rawItem: { id: 8 } },
@ -83,7 +95,9 @@ describe('MaxPriorityQueue Operation Test', () => {
{ rawItem: { id: 3 } },
{ rawItem: { id: 5 } }
],
{ comparator: (a, b) => b.rawItem.id - a.rawItem.id }
{
comparator: (a, b) => b.rawItem.id - a.rawItem.id
}
);
expect([...maxPQ.sort()]).toEqual([
@ -108,7 +122,9 @@ describe('MaxPriorityQueue Operation Test', () => {
{ rawItem: { id: 3 } },
{ rawItem: { id: 5 } }
],
{ toElementFn: rawElement => rawElement.rawItem.id }
{
toElementFn: rawElement => rawElement.rawItem.id
}
);
expect([...maxPQ.sort()]).toEqual([8, 7, 6, 5, 4, 3, 1]);

View file

@ -5,7 +5,9 @@ import { isDebugTest } from '../../../config';
const isDebug = isDebugTest;
describe('PriorityQueue Operation Test', () => {
it('should PriorityQueue poll, pee, heapify, toArray work well', function () {
const minPQ = new PriorityQueue<number>([], { comparator: (a, b) => a - b });
const minPQ = new PriorityQueue<number>([], {
comparator: (a, b) => a - b
});
minPQ.refill([5, 2, 3, 4, 6, 1]);
expect(minPQ.toArray()).toEqual([1, 2, 3, 4, 6, 5]);
minPQ.poll();
@ -21,7 +23,9 @@ describe('PriorityQueue Operation Test', () => {
});
it('should Max PriorityQueue poll, peek, heapify, toArray work well', function () {
const maxPriorityQueue = new PriorityQueue<number>([], { comparator: (a, b) => b - a });
const maxPriorityQueue = new PriorityQueue<number>([], {
comparator: (a, b) => b - a
});
maxPriorityQueue.refill([5, 2, 3, 4, 6, 1]);
expect(maxPriorityQueue.toArray()).toEqual([6, 5, 3, 4, 2, 1]);
maxPriorityQueue.poll();
@ -37,7 +41,9 @@ describe('PriorityQueue Operation Test', () => {
});
it('should PriorityQueue clone, sort, getNodes, dfs work well', function () {
const minPQ1 = new PriorityQueue<number>([], { comparator: (a, b) => a - b });
const minPQ1 = new PriorityQueue<number>([], {
comparator: (a, b) => a - b
});
minPQ1.refill([2, 5, 8, 3, 1, 6, 7, 4]);
const clonedPriorityQueue = minPQ1.clone();
expect(clonedPriorityQueue.elements).toEqual(minPQ1.elements);
@ -50,7 +56,9 @@ describe('PriorityQueue Operation Test', () => {
describe('Priority Queue Performance Test', () => {
it('should numeric heap work well', function () {
const pq = new PriorityQueue<number>([], { comparator: (a, b) => b - a });
const pq = new PriorityQueue<number>([], {
comparator: (a, b) => b - a
});
const tS = performance.now();

View file

@ -204,8 +204,7 @@ describe('Deque - Complex Operations', () => {
expect([...deque]).toEqual([1, 2, 3]);
});
test('shrinkToFit should reduce the memory footprint', () => {
});
test('shrinkToFit should reduce the memory footprint', () => {});
});
describe('Deque - Utility Operations', () => {
let deque: Deque<number>;
@ -264,7 +263,7 @@ describe('Deque - Utility Operations', () => {
test('should maxLen work well', () => {
const dequeMaxLen = new Deque([3, 4, 5, 6, 7], { maxLen: 3 });
expect(dequeMaxLen.size).toBe(3);
expect(dequeMaxLen.toArray()).toEqual([5, 6 ,7]);
expect(dequeMaxLen.toArray()).toEqual([5, 6, 7]);
dequeMaxLen.unshift(4);
dequeMaxLen.unshift(3);
expect(dequeMaxLen.size).toBe(3);
@ -277,7 +276,6 @@ describe('Deque - Utility Operations', () => {
dequeNoMaxLen.unshift(3);
expect(dequeNoMaxLen.size).toBe(7);
expect(dequeNoMaxLen.toArray()).toEqual([3, 4, 3, 4, 5, 6, 7]);
});
});
@ -344,7 +342,9 @@ describe('Deque - push Method', () => {
const bucketSize = 10;
beforeEach(() => {
deque = new Deque<number>([], { bucketSize });
deque = new Deque<number>([], {
bucketSize
});
});
test('push should add an element when deque is empty', () => {
@ -386,7 +386,9 @@ describe('Deque - pop Method', () => {
const bucketSize = 10;
beforeEach(() => {
deque = new Deque<number>([], { bucketSize });
deque = new Deque<number>([], {
bucketSize
});
});
test('pop should remove and return the last element', () => {
@ -417,7 +419,9 @@ describe('Deque - unshift Method', () => {
const bucketSize = 10;
beforeEach(() => {
deque = new Deque<number>([], { bucketSize });
deque = new Deque<number>([], {
bucketSize
});
});
test('unshift should add an element to the beginning when deque is empty', () => {
@ -449,7 +453,9 @@ describe('Deque - shift Method', () => {
const bucketSize = 10;
beforeEach(() => {
deque = new Deque<number>([], { bucketSize });
deque = new Deque<number>([], {
bucketSize
});
});
test('shift should remove and return the first element', () => {

View file

@ -795,7 +795,9 @@ describe('Trie operations', () => {
});
it('Case Sensitivity', () => {
const caseInsensitiveTrie = new Trie(['apple', 'Banana'], { caseSensitive: false });
const caseInsensitiveTrie = new Trie(['apple', 'Banana'], {
caseSensitive: false
});
expect(caseInsensitiveTrie.has('APPLE')).toBe(true);
expect(caseInsensitiveTrie.has('banana')).toBe(true);
expect(caseInsensitiveTrie.has('Cherry')).toBe(false);

View file

@ -245,7 +245,9 @@ describe('conversions', () => {
const trie = new Trie(orgStrArr);
expect(trie.size).toBe(10);
isDebug && trie.print();
const heap = new Heap<string>(trie, { comparator: (a, b) => Number(a) - Number(b) });
const heap = new Heap<string>(trie, {
comparator: (a, b) => Number(a) - Number(b)
});
expect(heap.size).toBe(10);
isDebug && heap.print();
expect([...heap]).toEqual([

View file

@ -32,7 +32,9 @@ export const bigO = {
function findPotentialN(input: any): number {
let longestArray: any[] = [];
let mostProperties: { [key: string]: any } = {};
let mostProperties: {
[key: string]: any;
} = {};
function recurse(obj: any) {
if (Array.isArray(obj)) {

View file

@ -14,13 +14,9 @@ function makeLabelDiv(options: any, level: number, keyName: string | number, dat
return `<div class='index'><span class='json-to-html-label'>${keyName}&nbsp;</span></div>`;
} else if (typeof keyName === 'string') {
if (datatype === 'array') {
return `<div class='collapsible level${level}' ${toggleJS(
options
)}><span class='json-to-html-label'>${keyName}</span></div>`;
return `<div class='collapsible level${level}' ${toggleJS(options)}><span class='json-to-html-label'>${keyName}</span></div>`;
} else if (datatype === 'object') {
return `<div class='attribute collapsible level${level}' ${toggleJS(
options
)}><span class='json-to-html-label'>${keyName}:</span></div>`;
return `<div class='attribute collapsible level${level}' ${toggleJS(options)}><span class='json-to-html-label'>${keyName}:</span></div>`;
} else {
return `<div class='leaf level${level}'><span class='json-to-html-label'>${keyName}:</span></div>`;
}