data-structure-typed 2.5.0 → 2.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +12984 -0
  2. package/.vitepress/cache/deps_temp_51f5f1b0/package.json +3 -0
  3. package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +4505 -0
  4. package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +9731 -0
  5. package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +347 -0
  6. package/CHANGELOG.md +5 -1
  7. package/README.md +124 -29
  8. package/dist/cjs/binary-tree.cjs +26282 -0
  9. package/dist/cjs/graph.cjs +5422 -0
  10. package/dist/cjs/hash.cjs +1310 -0
  11. package/dist/cjs/heap.cjs +1602 -0
  12. package/dist/cjs/index.cjs +31257 -14673
  13. package/dist/cjs/linked-list.cjs +4576 -0
  14. package/dist/cjs/matrix.cjs +1080 -0
  15. package/dist/cjs/priority-queue.cjs +1376 -0
  16. package/dist/cjs/queue.cjs +4264 -0
  17. package/dist/cjs/stack.cjs +907 -0
  18. package/dist/cjs/trie.cjs +1223 -0
  19. package/dist/cjs-legacy/binary-tree.cjs +26319 -0
  20. package/dist/cjs-legacy/graph.cjs +5420 -0
  21. package/dist/cjs-legacy/hash.cjs +1310 -0
  22. package/dist/cjs-legacy/heap.cjs +1599 -0
  23. package/dist/cjs-legacy/index.cjs +31268 -14679
  24. package/dist/cjs-legacy/linked-list.cjs +4582 -0
  25. package/dist/cjs-legacy/matrix.cjs +1083 -0
  26. package/dist/cjs-legacy/priority-queue.cjs +1374 -0
  27. package/dist/cjs-legacy/queue.cjs +4262 -0
  28. package/dist/cjs-legacy/stack.cjs +907 -0
  29. package/dist/cjs-legacy/trie.cjs +1222 -0
  30. package/dist/esm/binary-tree.mjs +26267 -0
  31. package/dist/esm/graph.mjs +5409 -0
  32. package/dist/esm/hash.mjs +1307 -0
  33. package/dist/esm/heap.mjs +1596 -0
  34. package/dist/esm/index.mjs +31254 -14674
  35. package/dist/esm/linked-list.mjs +4569 -0
  36. package/dist/esm/matrix.mjs +1076 -0
  37. package/dist/esm/priority-queue.mjs +1372 -0
  38. package/dist/esm/queue.mjs +4260 -0
  39. package/dist/esm/stack.mjs +905 -0
  40. package/dist/esm/trie.mjs +1220 -0
  41. package/dist/esm-legacy/binary-tree.mjs +26304 -0
  42. package/dist/esm-legacy/graph.mjs +5407 -0
  43. package/dist/esm-legacy/hash.mjs +1307 -0
  44. package/dist/esm-legacy/heap.mjs +1593 -0
  45. package/dist/esm-legacy/index.mjs +31265 -14680
  46. package/dist/esm-legacy/linked-list.mjs +4575 -0
  47. package/dist/esm-legacy/matrix.mjs +1079 -0
  48. package/dist/esm-legacy/priority-queue.mjs +1370 -0
  49. package/dist/esm-legacy/queue.mjs +4258 -0
  50. package/dist/esm-legacy/stack.mjs +905 -0
  51. package/dist/esm-legacy/trie.mjs +1219 -0
  52. package/dist/types/common/error.d.ts +9 -0
  53. package/dist/types/common/index.d.ts +1 -1
  54. package/dist/types/data-structures/base/index.d.ts +1 -0
  55. package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
  56. package/dist/types/data-structures/base/linear-base.d.ts +3 -3
  57. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +288 -0
  58. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
  59. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
  60. package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
  61. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
  62. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
  63. package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
  64. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
  65. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
  66. package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
  67. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
  68. package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
  69. package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
  70. package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
  71. package/dist/types/data-structures/heap/heap.d.ts +336 -0
  72. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
  73. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
  74. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
  75. package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
  76. package/dist/types/data-structures/queue/deque.d.ts +364 -4
  77. package/dist/types/data-structures/queue/queue.d.ts +288 -0
  78. package/dist/types/data-structures/stack/stack.d.ts +240 -0
  79. package/dist/types/data-structures/trie/trie.d.ts +292 -4
  80. package/dist/types/interfaces/graph.d.ts +1 -1
  81. package/dist/types/types/common.d.ts +2 -2
  82. package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  83. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  84. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  85. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  86. package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
  87. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  88. package/dist/types/types/utils/validate-type.d.ts +4 -4
  89. package/dist/umd/data-structure-typed.js +31196 -14608
  90. package/dist/umd/data-structure-typed.min.js +11 -5
  91. package/docs-site-docusaurus/README.md +41 -0
  92. package/docs-site-docusaurus/docs/api/README.md +52 -0
  93. package/docs-site-docusaurus/docs/api/classes/AVLTree.md +6644 -0
  94. package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +282 -0
  95. package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +2266 -0
  96. package/docs-site-docusaurus/docs/api/classes/BST.md +6293 -0
  97. package/docs-site-docusaurus/docs/api/classes/BSTNode.md +333 -0
  98. package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +455 -0
  99. package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +4647 -0
  100. package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +331 -0
  101. package/docs-site-docusaurus/docs/api/classes/Deque.md +2767 -0
  102. package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +2999 -0
  103. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +2685 -0
  104. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +221 -0
  105. package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +253 -0
  106. package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +21 -0
  107. package/docs-site-docusaurus/docs/api/classes/HashMap.md +1333 -0
  108. package/docs-site-docusaurus/docs/api/classes/Heap.md +1881 -0
  109. package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +800 -0
  110. package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +644 -0
  111. package/docs-site-docusaurus/docs/api/classes/LinearBase.md +1632 -0
  112. package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +1853 -0
  113. package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +1108 -0
  114. package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +156 -0
  115. package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +2824 -0
  116. package/docs-site-docusaurus/docs/api/classes/MapGraph.md +2929 -0
  117. package/docs-site-docusaurus/docs/api/classes/Matrix.md +1026 -0
  118. package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +1866 -0
  119. package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +1883 -0
  120. package/docs-site-docusaurus/docs/api/classes/MinHeap.md +1879 -0
  121. package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +1882 -0
  122. package/docs-site-docusaurus/docs/api/classes/Navigator.md +109 -0
  123. package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +1839 -0
  124. package/docs-site-docusaurus/docs/api/classes/Queue.md +2244 -0
  125. package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +6888 -0
  126. package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +372 -0
  127. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +2897 -0
  128. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +169 -0
  129. package/docs-site-docusaurus/docs/api/classes/SkipList.md +1229 -0
  130. package/docs-site-docusaurus/docs/api/classes/Stack.md +1573 -0
  131. package/docs-site-docusaurus/docs/api/classes/TreeMap.md +1389 -0
  132. package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +1591 -0
  133. package/docs-site-docusaurus/docs/api/classes/TreeSet.md +1246 -0
  134. package/docs-site-docusaurus/docs/api/classes/Trie.md +1708 -0
  135. package/docs-site-docusaurus/docs/api/classes/TrieNode.md +199 -0
  136. package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +2979 -0
  137. package/docs-site-docusaurus/docs/guide/_category_.json +6 -0
  138. package/docs-site-docusaurus/docs/guide/architecture.md +615 -0
  139. package/docs-site-docusaurus/docs/guide/concepts.md +451 -0
  140. package/docs-site-docusaurus/docs/guide/faq.md +180 -0
  141. package/docs-site-docusaurus/docs/guide/guides.md +597 -0
  142. package/docs-site-docusaurus/docs/guide/installation.md +62 -0
  143. package/docs-site-docusaurus/docs/guide/integrations.md +825 -0
  144. package/docs-site-docusaurus/docs/guide/overview.md +645 -0
  145. package/docs-site-docusaurus/docs/guide/performance.md +835 -0
  146. package/docs-site-docusaurus/docs/guide/quick-start.md +104 -0
  147. package/docs-site-docusaurus/docs/guide/use-cases/_category_.json +6 -0
  148. package/docs-site-docusaurus/docs/guide/use-cases/array-sort-alternative.md +158 -0
  149. package/docs-site-docusaurus/docs/guide/use-cases/heap-vs-sorting.md +92 -0
  150. package/docs-site-docusaurus/docs/guide/use-cases/map-vs-treemap.md +151 -0
  151. package/docs-site-docusaurus/docs/guide/use-cases/priority-queue-typescript.md +113 -0
  152. package/docs-site-docusaurus/docs/guide/use-cases/treemap-javascript.md +151 -0
  153. package/docs-site-docusaurus/docusaurus.config.ts +159 -0
  154. package/docs-site-docusaurus/fix-mdx-generics.mjs +75 -0
  155. package/docs-site-docusaurus/package-lock.json +18667 -0
  156. package/docs-site-docusaurus/package.json +50 -0
  157. package/docs-site-docusaurus/prefix-class-to-methods.mjs +48 -0
  158. package/docs-site-docusaurus/sidebars.ts +23 -0
  159. package/docs-site-docusaurus/sort-protected.mjs +87 -0
  160. package/docs-site-docusaurus/src/css/custom.css +96 -0
  161. package/docs-site-docusaurus/src/pages/index.module.css +13 -0
  162. package/docs-site-docusaurus/src/pages/index.tsx +120 -0
  163. package/docs-site-docusaurus/src/pages/markdown-page.md +7 -0
  164. package/docs-site-docusaurus/src/theme/TOCItems/index.tsx +34 -0
  165. package/docs-site-docusaurus/static/.nojekyll +0 -0
  166. package/docs-site-docusaurus/static/img/docusaurus-social-card.jpg +0 -0
  167. package/docs-site-docusaurus/static/img/docusaurus.png +0 -0
  168. package/docs-site-docusaurus/static/img/favicon.ico +0 -0
  169. package/docs-site-docusaurus/static/img/favicon.png +0 -0
  170. package/docs-site-docusaurus/static/img/logo-180.png +0 -0
  171. package/docs-site-docusaurus/static/img/logo.jpg +0 -0
  172. package/docs-site-docusaurus/static/img/logo.png +0 -0
  173. package/docs-site-docusaurus/static/img/logo.svg +1 -0
  174. package/docs-site-docusaurus/static/img/og-image.png +0 -0
  175. package/docs-site-docusaurus/static/img/undraw_docusaurus_mountain.svg +171 -0
  176. package/docs-site-docusaurus/static/img/undraw_docusaurus_react.svg +170 -0
  177. package/docs-site-docusaurus/static/img/undraw_docusaurus_tree.svg +40 -0
  178. package/docs-site-docusaurus/static/llms.txt +37 -0
  179. package/docs-site-docusaurus/static/robots.txt +4 -0
  180. package/docs-site-docusaurus/typedoc.json +23 -0
  181. package/llms.txt +37 -0
  182. package/package.json +159 -55
  183. package/src/common/error.ts +19 -1
  184. package/src/common/index.ts +1 -1
  185. package/src/data-structures/base/index.ts +1 -0
  186. package/src/data-structures/base/iterable-element-base.ts +3 -2
  187. package/src/data-structures/base/iterable-entry-base.ts +8 -8
  188. package/src/data-structures/base/linear-base.ts +3 -3
  189. package/src/data-structures/binary-tree/avl-tree.ts +287 -0
  190. package/src/data-structures/binary-tree/binary-indexed-tree.ts +327 -5
  191. package/src/data-structures/binary-tree/binary-tree.ts +581 -6
  192. package/src/data-structures/binary-tree/bst.ts +922 -7
  193. package/src/data-structures/binary-tree/red-black-tree.ts +453 -0
  194. package/src/data-structures/binary-tree/segment-tree.ts +139 -2
  195. package/src/data-structures/binary-tree/tree-map.ts +3300 -495
  196. package/src/data-structures/binary-tree/tree-multi-map.ts +3384 -563
  197. package/src/data-structures/binary-tree/tree-multi-set.ts +2757 -493
  198. package/src/data-structures/binary-tree/tree-set.ts +3122 -440
  199. package/src/data-structures/graph/abstract-graph.ts +6 -6
  200. package/src/data-structures/graph/directed-graph.ts +230 -0
  201. package/src/data-structures/graph/undirected-graph.ts +207 -0
  202. package/src/data-structures/hash/hash-map.ts +270 -19
  203. package/src/data-structures/heap/heap.ts +326 -4
  204. package/src/data-structures/heap/max-heap.ts +2 -2
  205. package/src/data-structures/linked-list/doubly-linked-list.ts +394 -3
  206. package/src/data-structures/linked-list/singly-linked-list.ts +348 -3
  207. package/src/data-structures/linked-list/skip-linked-list.ts +421 -7
  208. package/src/data-structures/matrix/matrix.ts +194 -10
  209. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  210. package/src/data-structures/queue/deque.ts +350 -5
  211. package/src/data-structures/queue/queue.ts +276 -0
  212. package/src/data-structures/stack/stack.ts +230 -0
  213. package/src/data-structures/trie/trie.ts +283 -7
  214. package/src/interfaces/graph.ts +1 -1
  215. package/src/types/common.ts +2 -2
  216. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  217. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  218. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  219. package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
  220. package/src/types/data-structures/heap/heap.ts +1 -0
  221. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  222. package/src/types/utils/validate-type.ts +4 -4
  223. package/vercel.json +6 -0
  224. package/dist/leetcode/avl-tree-counter.mjs +0 -2957
  225. package/dist/leetcode/avl-tree-multi-map.mjs +0 -2889
  226. package/dist/leetcode/avl-tree.mjs +0 -2720
  227. package/dist/leetcode/binary-tree.mjs +0 -1594
  228. package/dist/leetcode/bst.mjs +0 -2398
  229. package/dist/leetcode/deque.mjs +0 -683
  230. package/dist/leetcode/directed-graph.mjs +0 -1733
  231. package/dist/leetcode/doubly-linked-list.mjs +0 -709
  232. package/dist/leetcode/hash-map.mjs +0 -493
  233. package/dist/leetcode/heap.mjs +0 -542
  234. package/dist/leetcode/max-heap.mjs +0 -375
  235. package/dist/leetcode/max-priority-queue.mjs +0 -383
  236. package/dist/leetcode/min-heap.mjs +0 -363
  237. package/dist/leetcode/min-priority-queue.mjs +0 -371
  238. package/dist/leetcode/priority-queue.mjs +0 -363
  239. package/dist/leetcode/queue.mjs +0 -943
  240. package/dist/leetcode/red-black-tree.mjs +0 -2765
  241. package/dist/leetcode/singly-linked-list.mjs +0 -754
  242. package/dist/leetcode/stack.mjs +0 -217
  243. package/dist/leetcode/tree-counter.mjs +0 -3039
  244. package/dist/leetcode/tree-multi-map.mjs +0 -2913
  245. package/dist/leetcode/trie.mjs +0 -413
  246. package/dist/leetcode/undirected-graph.mjs +0 -1650
@@ -0,0 +1,835 @@
1
+ ---
2
+ sidebar_label: "PERFORMANCE"
3
+ description: "Benchmarks comparing data-structure-typed vs native Arrays, Maps, and C++ implementations. Includes methodology."
4
+ title: "Performance Benchmarks"
5
+ keywords: [typescript data structures performance, red black tree benchmark, heap benchmark, priority queue performance, javascript vs cpp]
6
+ ---
7
+
8
+ # PERFORMANCE
9
+
10
+ Understand how data-structure-typed performs, and when to use each structure.
11
+
12
+ **[Back to README](/.md) • [Architecture Details](/guide/architecture.md) • [Code Examples](/guide/guides.md) • [📈 Interactive HTML Report](/guide/performance)**
13
+
14
+ ---
15
+
16
+ ## Table of Contents
17
+
18
+ 1. [Performance Summary](#performance-summary)
19
+ 2. [Real-World Scenarios](#real-world-scenarios)
20
+ 3. [Detailed Benchmarks](#detailed-benchmarks)
21
+ 4. [When to Use What](#when-to-use-what)
22
+ 5. [Optimization Tips](#optimization-tips)
23
+
24
+ ---
25
+
26
+ ## Performance Summary
27
+
28
+ > **Note on JS vs C++ gaps:** Many “C++ faster” results are primarily explained by **runtime / memory-model differences**, not a flaw in `data-structure-typed`.
29
+ > JavaScript runs on a GC’d VM with boxed numbers, dynamic dispatch, and different cache/memory behavior, while C++ can use tight value types and predictable memory layouts.
30
+ > When the benchmark mixes in baseline containers (Native JS / js-sdsl / C++), treat cross-language comparisons as **directional** and rely most on **within-JS** comparisons for practical decisions.
31
+
32
+ ### Key Numbers
33
+
34
+ - **484x faster** than Array.shift() with 100K elements (Deque vs Array)
35
+ - **40x–308x faster** in repeated “update + resort” workloads (RedBlackTree vs Array)
36
+ - **O(log n) guaranteed** on all balanced tree operations
37
+ - **O(1) guaranteed** on Deque head/tail operations
38
+ - Benchmarks include warm-up runs to reduce V8 JIT noise
39
+
40
+ ### Performance Tier Chart
41
+
42
+ | Structure | Access | Search | Insert | Delete | Best For |
43
+ |--------------|----------|----------|----------|----------|----------------------|
44
+ | Array | O(1) | O(n) | O(n) | O(n) | Random access |
45
+ | LinkedList | O(n) | O(n) | O(1)* | O(1)* | If you have pointer |
46
+ | Stack | - | - | O(1) | O(1) | LIFO, undo/redo |
47
+ | Queue | - | - | O(1) | O(1) | FIFO, message queues |
48
+ | Deque | - | - | O(1) | O(1) | Head/tail ops |
49
+ | BST | O(log n) | O(log n) | O(log n) | O(log n) | Sorted if balanced |
50
+ | RedBlackTree | O(log n) | O(log n) | O(log n) | O(log n) | Guaranteed sorted |
51
+ | AVL Tree | O(log n) | O(log n) | O(log n) | O(log n) | Max search speed |
52
+ | Heap | O(n) | O(n) | O(log n) | O(log n) | Priority queue |
53
+ | Trie | N/A | O(m) | O(m) | O(m) | Prefix search |
54
+
55
+ ---
56
+
57
+ ## Benchmark
58
+
59
+ [//]: # (No deletion!!! Start of Replace Section)
60
+
61
+ ### Queue
62
+ | Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
63
+ |-----------|----------|----------|----------|-----------|
64
+ | 1M push | 26.93 | 24.41 | 51.97 | ±4.28% |
65
+ | 100K push & shift | 3.45 | 2.72 | 15.26 | ±8.97% |
66
+
67
+ #### Queue (side-by-side)
68
+
69
+ > Comparison table. The main table above is Queue only.
70
+ > Native is `-` when there is no apples-to-apples equivalent in this benchmark.
71
+
72
+ | Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
73
+ | ----------- | ---------: | ---------: | ---------: | ---------: |
74
+ | 1M push | 26.93 | 23.83 | 1.70 | 27.59 |
75
+ | 100K push & shift | 3.45 | 1152.77 | 0.20 | 2.71 |
76
+
77
+
78
+ ### Deque
79
+ | Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
80
+ |-----------|----------|----------|----------|-----------|
81
+ | 1M push | 9.77 | 6.27 | 21.63 | ±9.28% |
82
+ | 1M push & pop | 14.75 | 11.80 | 31.16 | ±5.06% |
83
+ | 1M push & shift | 14.61 | 13.31 | 40.42 | ±5.25% |
84
+ | 100K push & shift | 1.29 | 1.19 | 3.37 | ±3.91% |
85
+ | 100K unshift & shift | 1.26 | 1.14 | 2.75 | ±3.59% |
86
+
87
+ #### Deque (side-by-side)
88
+
89
+ > Comparison table. The main table above is Deque only.
90
+ > Native is `-` when there is no apples-to-apples equivalent in this benchmark.
91
+
92
+ | Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
93
+ | ----------- | ---------: | ---------: | ---------: | ---------: |
94
+ | 1M push | 9.77 | 26.81 | 1.76 | 7.79 |
95
+ | 1M push & pop | 14.75 | 27.96 | 2.20 | 12.34 |
96
+ | 1M push & shift | 14.61 | - | 1.94 | - |
97
+ | 100K push & shift | 1.29 | 1243.77 | 0.19 | 1.17 |
98
+ | 100K unshift & shift | 1.26 | 1867.28 | 0.19 | 1.17 |
99
+
100
+
101
+ ### DoublyLinkedList
102
+ | Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
103
+ |-----------|----------|----------|----------|-----------|
104
+ | 100k push | 5.70 | 4.80 | 7.27 | ±1.57% |
105
+ | 100k unshift | 5.57 | 4.63 | 13.65 | ±5.7% |
106
+ | 100k unshift & shift | 4.04 | 3.87 | 5.34 | ±1.3% |
107
+ | 100k addAt(mid) | 1865.99 | 1778.94 | 1992.65 | ±5.43% |
108
+ | 100k addBefore (cursor) | 6.81 | 5.32 | 17.77 | ±4.44% |
109
+
110
+ #### DoublyLinkedList (side-by-side)
111
+
112
+ > Comparison table. The main table above is DoublyLinkedList only.
113
+ > Native is `-` when there is no apples-to-apples equivalent in this benchmark.
114
+
115
+ | Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
116
+ | ----------- | ---------: | ---------: | ---------: | ---------: |
117
+ | 100k push | 5.70 | 2.40 | 5.70 | 1.90 |
118
+ | 100k unshift | 5.57 | 884.06 | 5.85 | 1.52 |
119
+ | 100k unshift & shift | 4.04 | 2050.71 | 5.74 | 1.89 |
120
+ | 100k addAt(mid) | 1865.99 | - | 754.81 | - |
121
+ | 100k addBefore (cursor) | 6.81 | - | 6.18 | - |
122
+
123
+
124
+ ### SinglyLinkedList
125
+ | Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
126
+ |-----------|----------|----------|----------|-----------|
127
+ | 100K unshift & shift | 3.77 | 3.62 | 3.99 | ±0.41% |
128
+ | 10K unshift & shift | 0.37 | 0.36 | 0.44 | ±0.78% |
129
+ | 10K addAt(mid) | 18.61 | 17.61 | 25.55 | ±1.66% |
130
+ | 10K addBefore (cursor) | 17.56 | 16.67 | 20.17 | ±1.11% |
131
+
132
+ #### SinglyLinkedList (side-by-side)
133
+
134
+ > Comparison table. The main table above is SinglyLinkedList only.
135
+ > Native is `-` when there is no apples-to-apples equivalent in this benchmark.
136
+
137
+ | Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
138
+ | ----------- | ---------: | ---------: | ---------: | ---------: |
139
+ | 100K unshift & shift | 3.77 | 1958.39 | 4.80 | - |
140
+ | 10K unshift & shift | 0.37 | 6.26 | 0.47 | - |
141
+ | 10K addAt(mid) | 18.61 | - | 5.77 | - |
142
+ | 10K addBefore (cursor) | 17.56 | - | 0.53 | - |
143
+
144
+
145
+ ### PriorityQueue
146
+ | Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
147
+ |-----------|----------|----------|----------|-----------|
148
+ | 100K add | 4.00 | 3.80 | 4.41 | ±0.6% |
149
+ | 100K add & poll | 22.51 | 21.23 | 42.99 | ±3.19% |
150
+
151
+ #### PriorityQueue (side-by-side)
152
+
153
+ > Comparison table. The main table above is PriorityQueue only.
154
+ > Native is `-` when there is no apples-to-apples equivalent in this benchmark.
155
+
156
+ | Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
157
+ | ----------- | ---------: | ---------: | ---------: | ---------: |
158
+ | 100K add | 4.00 | - | 1.05 | 4.96 |
159
+ | 100K add & poll | 22.51 | - | 4.53 | 22.97 |
160
+
161
+
162
+ ### TreeSet
163
+ | Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
164
+ |-----------|----------|----------|----------|-----------|
165
+ | 1M add | 995.72 | 948.08 | 1124.92 | ±6.28% |
166
+ | 1M has | 67.80 | 64.53 | 86.26 | ±1.67% |
167
+ | 100K rangeSearch | 17.34 | 16.79 | 18.81 | ±0.46% |
168
+ | 100K navigable | 118.65 | 117.95 | 119.38 | ±0.14% |
169
+
170
+ #### TreeSet (side-by-side)
171
+
172
+ > Comparison table. The main table above is TreeSet only.
173
+ > Native is `-` when there is no apples-to-apples equivalent in this benchmark.
174
+
175
+ | Test Case | DST (ms) | DST classic (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
176
+ | ----------- | ---------: | ---------: | ---------: | ---------: | ---------: |
177
+ | 1M add | 995.72 | 807.88 | - | 462.00 | 677.58 |
178
+ | 1M has | 67.80 | 747.62 | - | 444.00 | 655.62 |
179
+ | 100K rangeSearch | 17.34 | 16.70 | - | - | - |
180
+ | 100K navigable | 118.65 | 123.91 | - | - | - |
181
+
182
+
183
+ ### TreeMap
184
+ | Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
185
+ |-----------|----------|----------|----------|-----------|
186
+ | 1M set | 978.72 | 934.59 | 1130.02 | ±6.39% |
187
+ | 1M get | 127.82 | 123.10 | 133.96 | ±1.2% |
188
+ | 100K rangeSearch | 38.17 | 34.80 | 100.14 | ±6.97% |
189
+ | 100K navigable | 160.66 | 151.89 | 307.88 | ±9.6% |
190
+
191
+ #### TreeMap (side-by-side)
192
+
193
+ > Comparison table. The main table above is TreeMap only.
194
+ > Native is `-` when there is no apples-to-apples equivalent in this benchmark.
195
+
196
+ | Test Case | DST (ms) | DST classic (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
197
+ | ----------- | ---------: | ---------: | ---------: | ---------: | ---------: |
198
+ | 1M set | 978.72 | 831.32 | - | 512.00 | 623.23 |
199
+ | 1M get | 127.82 | 719.05 | - | 322.00 | 626.87 |
200
+ | 100K rangeSearch | 38.17 | 34.42 | - | - | - |
201
+ | 100K navigable | 160.66 | 213.76 | - | - | - |
202
+
203
+
204
+ ### TreeMultiSet
205
+ | Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
206
+ |-----------|----------|----------|----------|-----------|
207
+ | 1M add (TreeMultiSet expanded iteration) | 217.73 | 191.17 | 319.78 | ±8.07% |
208
+ | 1M has-only (TreeMultiSet) | 67.67 | 66.08 | 72.83 | ±0.72% |
209
+ | 1M count-only (TreeMultiSet) | 55.74 | 53.94 | 57.60 | ±0.49% |
210
+ | 1M build+has (TreeMultiSet) | 260.84 | 248.30 | 300.22 | ±2.79% |
211
+ | 1M build+count (TreeMultiSet) | 267.81 | 242.77 | 339.53 | ±5.97% |
212
+ | 100K delete-one (TreeMultiSet) | 217.76 | 201.92 | 254.80 | ±2.97% |
213
+ | 100K setCount (TreeMultiSet) | 214.66 | 201.65 | 264.54 | ±3.65% |
214
+ | 1M expanded iteration (TreeMultiSet) | 54.41 | 53.14 | 62.22 | ±0.78% |
215
+ | 1M entries view (TreeMultiSet) | 15.67 | 14.81 | 17.19 | ±0.72% |
216
+ | 1M size property (TreeMultiSet) | 0.00 | 0.00 | 0.00 | ±3.47% |
217
+ | 1M distinctSize property (TreeMultiSet) | 0.00 | 0.00 | 0.00 | ±3.88% |
218
+
219
+ #### TreeMultiSet (side-by-side)
220
+
221
+ > Comparison table. The main table above is TreeMultiSet only.
222
+ > Native is `-` when there is no apples-to-apples equivalent in this benchmark.
223
+
224
+ | Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
225
+ | ----------- | ---------: | ---------: | ---------: | ---------: |
226
+ | 1M add (TreeMultiSet expanded iteration) | 217.73 | - | 752.00 | - |
227
+ | 1M has-only (TreeMultiSet) | 67.67 | - | 756.00 | - |
228
+ | 1M count-only (TreeMultiSet) | 55.74 | - | 1332.00 | - |
229
+ | 1M build+has (TreeMultiSet) | 260.84 | - | 1406.00 | - |
230
+ | 1M build+count (TreeMultiSet) | 267.81 | - | 1909.00 | - |
231
+ | 100K delete-one (TreeMultiSet) | 217.76 | - | - | - |
232
+ | 100K setCount (TreeMultiSet) | 214.66 | - | - | - |
233
+ | 1M expanded iteration (TreeMultiSet) | 54.41 | - | - | - |
234
+ | 1M entries view (TreeMultiSet) | 15.67 | - | - | - |
235
+ | 1M size property (TreeMultiSet) | 0.00 | - | - | - |
236
+ | 1M distinctSize property (TreeMultiSet) | 0.00 | - | - | - |
237
+
238
+
239
+ ### TreeMultiMap
240
+ | Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
241
+ |-----------|----------|----------|----------|-----------|
242
+ | 1M add (TreeMultiMap bucketed) | 366.19 | 346.31 | 454.65 | ±5.51% |
243
+ | 1M has-only (TreeMultiMap) | 35.37 | 34.94 | 36.94 | ±0.39% |
244
+ | 1M get-only (TreeMultiMap) | 58.37 | 56.05 | 73.86 | ±1.37% |
245
+ | 1M count-only (TreeMultiMap) | 105.34 | 94.16 | 124.54 | ±2.71% |
246
+ | 1M build+has (TreeMultiMap) | 396.87 | 373.62 | 538.68 | ±8.08% |
247
+ | 1M build+get (TreeMultiMap) | 416.59 | 412.46 | 424.84 | ±0.62% |
248
+ | 100K hasEntry (TreeMultiMap Object.is) | 375.85 | 346.85 | 396.95 | ±2.39% |
249
+ | 100K deleteValue (TreeMultiMap Object.is) | 411.69 | 388.10 | 577.77 | ±9.06% |
250
+ | 100K firstEntry/lastEntry (TreeMultiMap) | 0.00 | - | - | ±0% |
251
+ | 100K ceilingEntry/floorEntry (TreeMultiMap) | 0.00 | - | - | ±0% |
252
+ | 1M bucket iteration (TreeMultiMap) | 22.55 | 21.91 | 25.20 | ±0.68% |
253
+ | 1M flatEntries iteration (TreeMultiMap) | 106.47 | 104.33 | 110.52 | ±0.6% |
254
+ | 1M size property (TreeMultiMap) | 0.00 | 0.00 | 0.00 | ±4.08% |
255
+ | 1M totalSize property (TreeMultiMap) | 21.74 | 21.09 | 25.40 | ±0.8% |
256
+
257
+ #### TreeMultiMap (side-by-side)
258
+
259
+ > Comparison table. The main table above is TreeMultiMap only.
260
+ > Native is `-` when there is no apples-to-apples equivalent in this benchmark.
261
+
262
+ | Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
263
+ | ----------- | ---------: | ---------: | ---------: | ---------: |
264
+ | 1M add (TreeMultiMap bucketed) | 366.19 | - | 731.00 | - |
265
+ | 1M has-only (TreeMultiMap) | 35.37 | - | 833.00 | - |
266
+ | 1M get-only (TreeMultiMap) | 58.37 | - | 1553.00 | - |
267
+ | 1M count-only (TreeMultiMap) | 105.34 | - | 1548.00 | - |
268
+ | 1M build+has (TreeMultiMap) | 396.87 | - | 1519.00 | - |
269
+ | 1M build+get (TreeMultiMap) | 416.59 | - | 2263.00 | - |
270
+ | 100K hasEntry (TreeMultiMap Object.is) | 375.85 | - | - | - |
271
+ | 100K deleteValue (TreeMultiMap Object.is) | 411.69 | - | - | - |
272
+ | 100K firstEntry/lastEntry (TreeMultiMap) | 0.00 | - | - | - |
273
+ | 100K ceilingEntry/floorEntry (TreeMultiMap) | 0.00 | - | - | - |
274
+ | 1M bucket iteration (TreeMultiMap) | 22.55 | - | 109.00 | - |
275
+ | 1M flatEntries iteration (TreeMultiMap) | 106.47 | - | 109.00 | - |
276
+ | 1M size property (TreeMultiMap) | 0.00 | - | - | - |
277
+ | 1M totalSize property (TreeMultiMap) | 21.74 | - | - | - |
278
+
279
+
280
+ ### RedBlackTree
281
+ | Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
282
+ |-----------|----------|----------|----------|-----------|
283
+ | 1M get | 99.24 | 82.27 | 109.67 | ±16.59% |
284
+ | 200K rangeSearch SEQ | 1365.15 | 1251.75 | 1491.01 | ±9.18% |
285
+ | 200K rangeSearch RAND | 1565.26 | 1528.89 | 1613.47 | ±2.69% |
286
+ | 1M upd SEQ | 84.75 | 82.26 | 86.85 | ±3.10% |
287
+ | 1M upd RAND | 113.72 | 112.51 | 116.12 | ±1.70% |
288
+ | 1M ins SEQ | 535.64 | 459.83 | 795.68 | ±33.88% |
289
+ | 1M ins RAND | 989.88 | 973.81 | 1001.58 | ±1.43% |
290
+ | 1M keys-only | 4.22 | 2.71 | 5.81 | ±41.71% |
291
+
292
+ #### RedBlackTree (side-by-side)
293
+
294
+ > Comparison table. The main table above is RedBlackTree only.
295
+ > Native is `-` when there is no apples-to-apples equivalent in this benchmark.
296
+
297
+ | Test Case | DST (ms) | DST classic (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
298
+ | ----------- | ---------: | ---------: | ---------: | ---------: | ---------: |
299
+ | 1M get | 99.24 | 304.72 | - | 52.97 | - |
300
+ | 200K rangeSearch SEQ | 1365.15 | - | - | - | - |
301
+ | 200K rangeSearch RAND | 1565.26 | - | - | - | - |
302
+ | 1M upd SEQ | 84.75 | 302.03 | - | 68.43 | - |
303
+ | 1M upd RAND | 113.72 | 422.53 | - | 158.14 | - |
304
+ | 1M ins SEQ | 535.64 | 211.38 | - | 162.72 | - |
305
+ | 1M ins RAND | 989.88 | 882.76 | - | 483.56 | - |
306
+ | 1M keys-only | 4.22 | - | - | 0.09 | - |
307
+
308
+
309
+ ### BST
310
+ | Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
311
+ |-----------|----------|----------|----------|-----------|
312
+ | 10K add randomly | 5.50 | 5.11 | 5.93 | ±0.6% |
313
+ | 10K add & delete randomly | 10.01 | 9.75 | 10.79 | ±0.4% |
314
+ | 10K addMany | 11.62 | 10.00 | 68.37 | ±15.54% |
315
+ | 10K get | 10.65 | 10.35 | 11.67 | ±0.48% |
316
+
317
+ #### BST (side-by-side)
318
+
319
+ > Comparison table. The main table above is BST only.
320
+ > Native is `-` when there is no apples-to-apples equivalent in this benchmark.
321
+
322
+ | Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
323
+ | ----------- | ---------: | ---------: | ---------: | ---------: |
324
+ | 10K add randomly | 5.50 | - | - | - |
325
+ | 10K add & delete randomly | 10.01 | - | - | - |
326
+ | 10K addMany | 11.62 | - | - | - |
327
+ | 10K get | 10.65 | - | - | - |
328
+
329
+
330
+ ### BinaryTree
331
+ | Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
332
+ |-----------|----------|----------|----------|-----------|
333
+ | 1K add randomly | 9.77 | 9.52 | 10.28 | ±0.36% |
334
+ | 1K add & delete randomly | 10.05 | 9.67 | 11.34 | ±0.69% |
335
+ | 1K addMany | 10.79 | 9.20 | 84.26 | ±19.64% |
336
+ | 1K get | 9.64 | 9.15 | 12.52 | ±1.33% |
337
+ | 1K has | 9.50 | 9.20 | 11.91 | ±0.76% |
338
+ | 1K dfs | 92.87 | 90.46 | 96.24 | ±0.62% |
339
+ | 1K bfs | 37.34 | 36.18 | 42.30 | ±0.7% |
340
+ | 1K morris | 37.49 | 36.29 | 39.54 | ±0.51% |
341
+
342
+ #### BinaryTree (side-by-side)
343
+
344
+ > Comparison table. The main table above is BinaryTree only.
345
+ > Native is `-` when there is no apples-to-apples equivalent in this benchmark.
346
+
347
+ | Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
348
+ | ----------- | ---------: | ---------: | ---------: | ---------: |
349
+ | 1K add randomly | 9.77 | - | - | - |
350
+ | 1K add & delete randomly | 10.05 | - | - | - |
351
+ | 1K addMany | 10.79 | - | - | - |
352
+ | 1K get | 9.64 | - | - | - |
353
+ | 1K has | 9.50 | - | - | - |
354
+ | 1K dfs | 92.87 | - | - | - |
355
+ | 1K bfs | 37.34 | - | - | - |
356
+ | 1K morris | 37.49 | - | - | - |
357
+
358
+
359
+ ### HashMap
360
+ | Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
361
+ |-----------|----------|----------|----------|-----------|
362
+ | 1M set | 146.17 | 84.97 | 644.99 | ±33.94% |
363
+ | 1M set & get | 141.88 | 106.42 | 178.02 | ±6.1% |
364
+ | 1M ObjKey set & get | 223.16 | 210.45 | 300.73 | ±5.48% |
365
+
366
+ #### HashMap (side-by-side)
367
+
368
+ > Comparison table. The main table above is HashMap only.
369
+ > Native is `-` when there is no apples-to-apples equivalent in this benchmark.
370
+
371
+ | Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
372
+ | ----------- | ---------: | ---------: | ---------: | ---------: |
373
+ | 1M set | 146.17 | 144.83 | 76.26 | 94.16 |
374
+ | 1M set & get | 141.88 | 200.47 | 75.25 | 67.16 |
375
+ | 1M ObjKey set & get | 223.16 | 206.62 | 84.40 | 382.79 |
376
+
377
+
378
+ ### Trie
379
+ | Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
380
+ |-----------|----------|----------|----------|-----------|
381
+ | 100K add | 141.10 | 78.57 | 1348.32 | ±65.27% |
382
+ | 100K getWords | 57.16 | 52.58 | 63.12 | ±1.37% |
383
+
384
+ #### Trie (side-by-side)
385
+
386
+ > Comparison table. The main table above is Trie only.
387
+ > Native is `-` when there is no apples-to-apples equivalent in this benchmark.
388
+
389
+ | Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
390
+ | ----------- | ---------: | ---------: | ---------: | ---------: |
391
+ | 100K add | 141.10 | - | - | - |
392
+ | 100K getWords | 57.16 | - | - | - |
393
+
394
+
395
+ ### DirectedGraph
396
+ | Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
397
+ |-----------|----------|----------|----------|-----------|
398
+ | 1K addVertex | 0.05 | 0.05 | 0.05 | ±0.43% |
399
+ | 1K addEdge | 0.00 | - | - | ±0% |
400
+ | 1K getVertex | 37.54 | 36.05 | 38.86 | ±0.39% |
401
+ | 1K getEdge | 74.48 | 72.60 | 77.63 | ±0.44% |
402
+ | tarjan | 0.38 | 0.34 | 0.42 | ±0.93% |
403
+ | topologicalSort | 0.24 | 0.23 | 0.26 | ±0.51% |
404
+
405
+ #### DirectedGraph (side-by-side)
406
+
407
+ > Comparison table. The main table above is DirectedGraph only.
408
+ > Native is `-` when there is no apples-to-apples equivalent in this benchmark.
409
+
410
+ | Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
411
+ | ----------- | ---------: | ---------: | ---------: | ---------: |
412
+ | 1K addVertex | 0.05 | - | - | - |
413
+ | 1K addEdge | 0.00 | - | - | - |
414
+ | 1K getVertex | 37.54 | - | - | - |
415
+ | 1K getEdge | 74.48 | - | - | - |
416
+ | tarjan | 0.38 | - | - | - |
417
+ | topologicalSort | 0.24 | - | - | - |
418
+
419
+
420
+ ### Stack
421
+ | Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
422
+ |-----------|----------|----------|----------|-----------|
423
+ | 1M push | 46.38 | 31.28 | 258.38 | ±26.06% |
424
+ | 1M push & pop | 34.59 | 27.52 | 121.56 | ±14.83% |
425
+
426
+ #### Stack (side-by-side)
427
+
428
+ > Comparison table. The main table above is Stack only.
429
+ > Native is `-` when there is no apples-to-apples equivalent in this benchmark.
430
+
431
+ | Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
432
+ | ----------- | ---------: | ---------: | ---------: | ---------: |
433
+ | 1M push | 46.38 | 30.28 | 1.65 | 32.38 |
434
+ | 1M push & pop | 34.59 | 34.53 | 2.62 | 34.45 |
435
+
436
+
437
+ ### red-black-tree-cjs
438
+ | Test Case | Avg (ms) | Min (ms) | Max (ms) | Stability |
439
+ |-----------|----------|----------|----------|-----------|
440
+ | 1M get | 97.57 | 75.66 | 115.14 | ±22.94% |
441
+ | 1M upd SEQ | 85.76 | 78.96 | 92.92 | ±8.16% |
442
+ | 1M upd RAND | 113.48 | 101.84 | 120.90 | ±7.77% |
443
+ | 1M ins SEQ | 493.45 | 436.86 | 670.44 | ±25.42% |
444
+ | 1M ins RAND | 1023.19 | 976.56 | 1094.17 | ±5.36% |
445
+ | 1M keys-only | 4.22 | 2.71 | 5.90 | ±41.83% |
446
+
447
+ #### red-black-tree-cjs (side-by-side)
448
+
449
+ > Comparison table. The main table above is red-black-tree-cjs only.
450
+ > Native is `-` when there is no apples-to-apples equivalent in this benchmark.
451
+
452
+ | Test Case | DST (ms) | Native (ms) | C++ (ms) | js-sdsl (ms) |
453
+ | ----------- | ---------: | ---------: | ---------: | ---------: |
454
+ | 1M get | 97.57 | - | - | - |
455
+ | 1M upd SEQ | 85.76 | - | - | - |
456
+ | 1M upd RAND | 113.48 | - | - | - |
457
+ | 1M ins SEQ | 493.45 | - | - | - |
458
+ | 1M ins RAND | 1023.19 | - | - | - |
459
+ | 1M keys-only | 4.22 | - | - | - |
460
+
461
+
462
+
463
+ [//]: # (No deletion!!! End of Replace Section)
464
+
465
+ ## Real-World Scenarios
466
+
467
+ ### Scenario 1: Message Queue Processing
468
+
469
+ **Problem**: Process 100,000 messages in a queue.
470
+
471
+ ```javascript
472
+ // ❌ Array.shift() approach
473
+ const queue = [];
474
+ for (let msg of incomingMessages) queue.push(msg);
475
+ for (let i = 0; i < 100000; i++) {
476
+ const msg = queue.shift(); // O(n) each time!
477
+ processMessage(msg);
478
+ }
479
+ // Total: 100,000 * O(n) = O(n²)
480
+ // Time: ~2829ms for 100K items
481
+ ```
482
+
483
+ ```javascript
484
+ // ✅ Deque approach
485
+ import { Deque } from 'data-structure-typed';
486
+
487
+ const deque = new Deque();
488
+ for (let msg of incomingMessages) deque.push(msg);
489
+ for (let i = 0; i < 100000; i++) {
490
+ const msg = deque.shift(); // O(1)!
491
+ processMessage(msg);
492
+ }
493
+ // Total: 100,000 * O(1) = O(n)
494
+ // Time: ~5.83ms for 100K items
495
+
496
+ // 484x faster!
497
+ ```
498
+
499
+ **Real Impact**: In a system handling 10,000 requests/second, this saves 475ms per second of latency.
500
+
501
+ ### Scenario 2: Leaderboard Ranking
502
+
503
+ **Problem**: Maintain top 100 players with constantly changing scores.
504
+
505
+ ```javascript
506
+ // ❌ Array approach
507
+ const players = [];
508
+
509
+ function updateScore(playerId, newScore) {
510
+ const idx = players.findIndex(p => p.id === playerId);
511
+ players[idx].score = newScore;
512
+ players.sort((a, b) => b.score - a.score); // O(n log n) each time!
513
+ }
514
+
515
+ // After 1000 updates: 1000 * O(n log n) = O(n² log n)
516
+ // Time: ~2500ms for maintaining ranking of 100 players
517
+ ```
518
+
519
+ ```javascript
520
+ // ✅ RedBlackTree approach
521
+ import { RedBlackTree } from 'data-structure-typed';
522
+
523
+ const leaderboard = new RedBlackTree<number, number>();
524
+
525
+ function updateScore(playerId, newScore) {
526
+ // Keyed by playerId: updates are a single O(log n) set.
527
+ // (If you need to *rank by score*, use score as (part of) the key and maintain a playerId→score index.)
528
+ leaderboard.set(playerId, newScore);
529
+ }
530
+
531
+ // After 1000 updates: 1000 * O(log n) = O(n log n)
532
+ // Time: ~8ms for 1000 updates on 100 players (measured in PERFORMANCE.md)
533
+
534
+ // ~312x faster than sorting on every update
535
+ ```
536
+
537
+ **Real Impact**: Live leaderboards update instantly instead of lagging.
538
+
539
+ ### Scenario 3: Task Scheduling by Priority
540
+
541
+ **Problem**: Execute tasks in priority order with 10K pending tasks.
542
+
543
+ ```javascript
544
+ // ❌ Manual priority handling
545
+ const tasks = [];
546
+
547
+ function addTask(task) {
548
+ tasks.push(task);
549
+ tasks.sort((a, b) => b.priority - a.priority); // O(n log n)
550
+ }
551
+
552
+ function nextTask() {
553
+ return tasks.shift(); // O(n)
554
+ }
555
+
556
+ // Adding 10K tasks: 10K * O(n log n) = O(n² log n)
557
+ // Time: ~3200ms
558
+ ```
559
+
560
+ ```javascript
561
+ // ✅ PriorityQueue approach
562
+ import { MaxPriorityQueue } from 'data-structure-typed';
563
+
564
+ const pq = new MaxPriorityQueue();
565
+
566
+ function addTask(task) {
567
+ pq.add(task); // O(log n)
568
+ }
569
+
570
+ function nextTask() {
571
+ return pq.poll(); // O(log n)
572
+ }
573
+
574
+ // Adding 10K tasks: 10K * O(log n) = O(n log n)
575
+ // Time: ~45ms
576
+
577
+ // 71x faster!
578
+ ```
579
+
580
+ ---
581
+
582
+ ## Detailed Benchmarks
583
+
584
+ ### Deque vs Array Performance
585
+
586
+ | Operation | Array | Deque | Speed-up |
587
+ |-----------------|--------|--------|----------|
588
+ | 100K shifts | 2829ms | 5.83ms | **485x** |
589
+ | 100K unshifts | 2847ms | 6.12ms | **465x** |
590
+ | 100K operations | 2900ms | 7.45ms | **390x** |
591
+
592
+ ### Sorting Performance
593
+
594
+ | Data Size | Array.sort | RedBlackTree | Speed-up |
595
+ |------------|------------|--------------|---------------------|
596
+ | 1K items | 0.8ms | 3.2ms* | 0.25x (sort faster) |
597
+ | 10K items | 12ms | 18ms** | ~0.66x |
598
+ | 100K items | 150ms | 165ms** | ~0.9x |
599
+ | 1M items | 1800ms | 1950ms** | ~0.92x |
600
+
601
+ *First time - not repeated sorts
602
+ **Maintains sorted order throughout
603
+
604
+ **Key Insight**: For repeated operations (updates with resorts), RBTree is much faster:
605
+
606
+ | Scenario | Array | RBTree | Speed-up |
607
+ |---------------------------|---------|--------|----------|
608
+ | Insert 1K, sort once | 2ms | 5ms | 0.4x |
609
+ | Insert 1K, resort 100x | 200ms | 5ms | **40x** |
610
+ | Insert 100K, resort 1000x | 20000ms | 65ms | **308x** |
611
+
612
+ ### Search Performance
613
+
614
+ | Structure | 1K items | 10K items | 100K items |
615
+ |----------------|----------|-----------|------------|
616
+ | Array (linear) | 0.5ms | 5ms | 50ms |
617
+ | BST (balanced) | 0.01ms | 0.013ms | 0.015ms |
618
+ | RedBlackTree | 0.01ms | 0.013ms | 0.015ms |
619
+ | HashMap | 0.001ms | 0.001ms | 0.001ms |
620
+
621
+ ### Memory Usage
622
+
623
+ | Data Structure | 1K items | 10K items | 100K items | 1M items |
624
+ |------------------|----------|-----------|------------|------------|
625
+ | Array | 39 KB | 242 KB | 2,706 KB | 21,519 KB |
626
+ | Queue | 38 KB | 248 KB | 2,712 KB | 21,527 KB |
627
+ | Deque | 53 KB | 147 KB | 1,341 KB | 10,717 KB |
628
+ | SinglyLinkedList | 60 KB | 425 KB | 3,947 KB | 39,100 KB |
629
+ | DoublyLinkedList | 60 KB | 502 KB | 4,726 KB | 46,909 KB |
630
+ | Stack | 42 KB | 240 KB | 2,709 KB | 21,521 KB |
631
+ | Heap | 35 KB | 250 KB | 2,716 KB | 21,530 KB |
632
+ | PriorityQueue | 39 KB | 245 KB | 2,711 KB | 21,524 KB |
633
+ | Trie | 526 KB | 3,040 KB | 29,160 KB | 270,733 KB |
634
+ | RedBlackTree | 570 KB | 1,069 KB | 8,765 KB | 86,035 KB |
635
+ | TreeCounter | 553 KB | 1,134 KB | 11,099 KB | 91,415 KB |
636
+ | TreeMultiMap | 2,069 KB | 4,836 KB | 32,828 KB | 208,619 KB |
637
+
638
+ ### C++ vs JavaScript Data Structure Memory Usage Comparison (1M Elements)
639
+
640
+ | Data Structure | C++ | JavaScript | Multiple | Evaluation |
641
+ |------------------|-----------|------------|-------------|------------------------------------------------------------------------------------------|
642
+ | Array | 4–8 MB | 21.01 MB | 2.75×–5.51× | JavaScript uses significantly more memory due to object model and GC overhead |
643
+ | Queue | 8–24 MB | 21.02 MB | 0.92×–2.76× | Memory usage depends heavily on the C++ implementation strategy |
644
+ | Deque | 8–24 MB | 10.47 MB | 0.46×–1.37× | JavaScript implementation is relatively memory-efficient in this case |
645
+ | SinglyLinkedList | 24–40 MB | 38.18 MB | 1.00×–1.67× | Similar memory footprint; both suffer from per-node allocation overhead |
646
+ | DoublyLinkedList | 32–56 MB | 45.81 MB | 0.86×–1.50× | Comparable memory usage; allocator overhead dominates in both languages |
647
+ | Stack | 4–8 MB | 21.02 MB | 2.75×–5.51× | JavaScript stacks are much heavier than C++ vector-based stacks |
648
+ | Heap | 4–8 MB | 21.03 MB | 2.76×–5.51× | JavaScript heap implementations incur substantial runtime overhead |
649
+ | PriorityQueue | 4–8 MB | 21.02 MB | 2.76×–5.51× | Similar to Heap; JavaScript pays extra metadata and GC costs |
650
+ | Trie | 32–160 MB | 264.39 MB | 1.73×–8.66× | Highly implementation-dependent; JavaScript object-based tries are very memory-intensive |
651
+ | RedBlackTree | 48–80 MB | 84.02 MB | 1.10×–1.84× | JavaScript trees are larger, but the gap is moderate compared to arrays |
652
+ | TreeCounter | 56–88 MB | 89.27 MB | 1.06×–1.67× | Additional per-node bookkeeping increases JavaScript memory usage |
653
+ | TreeMultiMap | 56–96 MB | 203.73 MB | 2.23×–3.81× | Deep object nesting significantly amplifies memory consumption in JavaScript |
654
+
655
+ ---
656
+
657
+ ## When to Use What
658
+
659
+ ### Decision Matrix
660
+
661
+ | Need... | Use... | Complexity | Notes |
662
+ |---------------------------|---------------|---------------------|--------------------|
663
+ | Random access by index | Array | O(1) access | Standard choice |
664
+ | Sorted order with updates | RedBlackTree | O(log n) all ops | Auto-maintained |
665
+ | Priority queue | PriorityQueue | O(log n) add/remove | Keeps order |
666
+ | Fast head/tail ops | Deque | O(1) all ops | Best for queues |
667
+ | Prefix search | Trie | O(m+k) | m=prefix length |
668
+ | Undo/redo stack | Stack | O(1) all ops | LIFO order |
669
+ | Message queue | Queue/Deque | O(1) all ops | FIFO order |
670
+ | Graph algorithms | DirectedGraph | Varies | DFS, BFS, Dijkstra |
671
+ | Key-value lookup | Map | O(1) avg | When unsorted OK |
672
+ | Just sorting once | Array.sort() | O(n log n) | One-time cost OK |
673
+
674
+ ### Quick Decision Guide
675
+
676
+ ```
677
+ Need frequent head/tail operations?
678
+ YES → Deque (O(1) shift/unshift/push/pop)
679
+ NO → Next
680
+
681
+ Need sorted + fast lookup?
682
+ YES → RedBlackTree (O(log n) guaranteed)
683
+ NO → Next
684
+
685
+ Need highest/lowest priority?
686
+ YES → Heap/PriorityQueue (O(log n) add/remove)
687
+ NO → Next
688
+
689
+ Need prefix/text matching?
690
+ YES → Trie (O(m+k) where m=prefix)
691
+ NO → Next
692
+
693
+ Need graph operations?
694
+ YES → DirectedGraph/UndirectedGraph
695
+ NO → Use Array (simplest case)
696
+ ```
697
+
698
+ ---
699
+
700
+ ## Optimization Tips
701
+
702
+ ### Tip 1: Batch Operations
703
+
704
+ ```javascript
705
+ // ❌ Slow: Sorting after each insert
706
+ const tree = new RedBlackTree();
707
+ for (const item of items) {
708
+ tree.set(item.id, item); // Tree rebalances each time
709
+ }
710
+ ```
711
+
712
+ ```javascript
713
+ // ✅ Fast: Build in bulk
714
+ const tree = new RedBlackTree(items);
715
+ // Single rebalancing pass
716
+
717
+ // Often faster for large datasets (fewer per-insert balancing steps). Measure on your workload.
718
+ ```
719
+
720
+ ### Tip 2: Use Right Structure Early
721
+
722
+ ```javascript
723
+ // ❌ Wrong: Start with Array, convert later
724
+ const data = [];
725
+ for (const item of input) data.push(item);
726
+ const sorted = [...new RedBlackTree(data).keys()];
727
+ ```
728
+
729
+ ```javascript
730
+ // ✅ Right: Use correct structure immediately
731
+ const tree = new RedBlackTree(input);
732
+ const sorted = [...tree.keys()];
733
+
734
+ // Benefit: No conversion overhead
735
+ ```
736
+
737
+ ### Tip 3: Chain Operations
738
+
739
+ ```javascript
740
+ // ❌ Slow: Converting to Array loses benefits
741
+ const tree = new RedBlackTree(data);
742
+ const result = tree.toArray()
743
+ .filter(x => x > 5)
744
+ .map(x => x * 2);
745
+ ```
746
+
747
+ ```javascript
748
+ // ✅ Fast: Stay on tree
749
+ const result = tree
750
+ .filter((v => (v ?? 0) > 5)
751
+ .map(((v, k) => [k, (x ?? 0) * 2]);
752
+
753
+ // Benefit: Maintains structure type throughout
754
+ ```
755
+
756
+ ### Tip 4: V8 JIT Warm-up
757
+
758
+ ```javascript
759
+ // First calls are interpreted (slow)
760
+ // Subsequent calls are JIT-compiled (fast)
761
+
762
+ const tree = new RedBlackTree();
763
+
764
+ // First 100 inserts: Interpreted, slower
765
+ // Next 900 inserts: JIT-compiled (typically faster)
766
+
767
+ // Strategy: Do warm-up before timing
768
+ for (let i = 0; i < 1000; i++) tree.set(i, i);
769
+ // Now tree is warm and fast for benchmarks
770
+ ```
771
+
772
+ ### Tip 5: Choose Right Comparator
773
+
774
+ ```javascript
775
+ // ❌ Slow: Complex comparator
776
+ const tree = new RedBlackTree((a, b) => {
777
+ if (a.category !== b.category) {
778
+ return a.category.localeCompare(b.category);
779
+ }
780
+ return a.priority - b.priority;
781
+ });
782
+ ```
783
+
784
+ ```javascript
785
+ // ✅ Fast: Simple comparator
786
+ const tree = new RedBlackTree([], { comparator: (a, b) => a - b)
787
+ }
788
+ ;
789
+
790
+ // Why: V8 can inline simple comparators
791
+ ```
792
+
793
+ ---
794
+
795
+ ## Benchmark Summary Table
796
+
797
+ ### Operations per Second
798
+
799
+ | Operation | Array | Deque | Tree | Heap |
800
+ |-------------|---------|----------|-----------|--------|
801
+ | 1K shifts | 353/sec | 171K/sec | - | - |
802
+ | 1K inserts | 625/sec | 625/sec | 10K/sec | 8K/sec |
803
+ | 1K searches | 2K/sec | - | 100K/sec | 1K/sec |
804
+ | 1K sorts | 1/sec | - | 1000/sec* | - |
805
+
806
+ *Maintains sorted order
807
+
808
+ ---
809
+
810
+ ## Conclusion
811
+
812
+ ### When to Optimize
813
+
814
+ 1. **Profile first**: Don't optimize without data
815
+ 2. **Hot paths only**: Focus on frequently-called code
816
+ 3. **Right structure matters**: large speedups are possible (see the measured scenarios above)
817
+ 4. **Small datasets**: Array usually fine
818
+ 5. **Large datasets**: Structure choice critical
819
+
820
+ ### Performance Hierarchy
821
+
822
+ ```
823
+ Array.sort() ← Simple, once per session
824
+ RedBlackTree ← Sorted + frequent updates
825
+ Deque ← Frequent head/tail ops
826
+ Heap ← Priority matters
827
+ Trie ← Prefix search
828
+ HashMap/Map ← Unsorted key-value lookup
829
+ ```
830
+
831
+ ---
832
+
833
+ **Need examples?** See [GUIDES.md](/guide/guides.md).
834
+
835
+ **Understand why?** Read [ARCHITECTURE.md](/guide/architecture.md).