data-structure-typed 2.4.5 → 2.5.1

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 (240) 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 +3 -1
  7. package/README.md +78 -31
  8. package/dist/cjs/binary-tree.cjs +23698 -0
  9. package/dist/cjs/graph.cjs +5236 -0
  10. package/dist/cjs/hash.cjs +1262 -0
  11. package/dist/cjs/heap.cjs +1540 -0
  12. package/dist/cjs/index.cjs +24509 -2899
  13. package/dist/cjs/linked-list.cjs +4370 -0
  14. package/dist/cjs/matrix.cjs +1042 -0
  15. package/dist/cjs/priority-queue.cjs +1314 -0
  16. package/dist/cjs/queue.cjs +4090 -0
  17. package/dist/cjs/stack.cjs +861 -0
  18. package/dist/cjs/trie.cjs +1173 -0
  19. package/dist/cjs-legacy/binary-tree.cjs +23730 -0
  20. package/dist/cjs-legacy/graph.cjs +5234 -0
  21. package/dist/cjs-legacy/hash.cjs +1262 -0
  22. package/dist/cjs-legacy/heap.cjs +1537 -0
  23. package/dist/cjs-legacy/index.cjs +32555 -10936
  24. package/dist/cjs-legacy/linked-list.cjs +4376 -0
  25. package/dist/cjs-legacy/matrix.cjs +1045 -0
  26. package/dist/cjs-legacy/priority-queue.cjs +1312 -0
  27. package/dist/cjs-legacy/queue.cjs +4088 -0
  28. package/dist/cjs-legacy/stack.cjs +861 -0
  29. package/dist/cjs-legacy/trie.cjs +1172 -0
  30. package/dist/esm/binary-tree.mjs +23683 -0
  31. package/dist/esm/graph.mjs +5223 -0
  32. package/dist/esm/hash.mjs +1259 -0
  33. package/dist/esm/heap.mjs +1534 -0
  34. package/dist/esm/index.mjs +24507 -2898
  35. package/dist/esm/linked-list.mjs +4363 -0
  36. package/dist/esm/matrix.mjs +1038 -0
  37. package/dist/esm/priority-queue.mjs +1310 -0
  38. package/dist/esm/queue.mjs +4086 -0
  39. package/dist/esm/stack.mjs +859 -0
  40. package/dist/esm/trie.mjs +1170 -0
  41. package/dist/esm-legacy/binary-tree.mjs +23715 -0
  42. package/dist/esm-legacy/graph.mjs +5221 -0
  43. package/dist/esm-legacy/hash.mjs +1259 -0
  44. package/dist/esm-legacy/heap.mjs +1531 -0
  45. package/dist/esm-legacy/index.mjs +32553 -10935
  46. package/dist/esm-legacy/linked-list.mjs +4369 -0
  47. package/dist/esm-legacy/matrix.mjs +1041 -0
  48. package/dist/esm-legacy/priority-queue.mjs +1308 -0
  49. package/dist/esm-legacy/queue.mjs +4084 -0
  50. package/dist/esm-legacy/stack.mjs +859 -0
  51. package/dist/esm-legacy/trie.mjs +1169 -0
  52. package/dist/types/data-structures/base/index.d.ts +1 -0
  53. package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
  54. package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
  55. package/dist/types/data-structures/base/linear-base.d.ts +3 -3
  56. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +368 -51
  57. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +473 -147
  58. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +931 -80
  59. package/dist/types/data-structures/binary-tree/bst.d.ts +792 -29
  60. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +592 -32
  61. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +320 -135
  62. package/dist/types/data-structures/binary-tree/tree-map.d.ts +3662 -6
  63. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3487 -201
  64. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2778 -65
  65. package/dist/types/data-structures/binary-tree/tree-set.d.ts +3414 -6
  66. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
  67. package/dist/types/data-structures/graph/directed-graph.d.ts +419 -47
  68. package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
  69. package/dist/types/data-structures/graph/undirected-graph.d.ts +384 -59
  70. package/dist/types/data-structures/hash/hash-map.d.ts +462 -89
  71. package/dist/types/data-structures/heap/heap.d.ts +567 -99
  72. package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
  73. package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
  74. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +631 -49
  75. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +581 -68
  76. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +775 -12
  77. package/dist/types/data-structures/matrix/matrix.d.ts +491 -0
  78. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
  79. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
  80. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
  81. package/dist/types/data-structures/queue/deque.d.ts +578 -71
  82. package/dist/types/data-structures/queue/queue.d.ts +451 -42
  83. package/dist/types/data-structures/stack/stack.d.ts +374 -32
  84. package/dist/types/data-structures/trie/trie.d.ts +458 -48
  85. package/dist/types/interfaces/graph.d.ts +1 -1
  86. package/dist/types/types/common.d.ts +2 -2
  87. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
  88. package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
  89. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
  90. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  91. package/dist/types/types/utils/validate-type.d.ts +4 -4
  92. package/dist/umd/data-structure-typed.js +32432 -10808
  93. package/dist/umd/data-structure-typed.min.js +10 -4
  94. package/docs-site-docusaurus/README.md +41 -0
  95. package/docs-site-docusaurus/docs/api/README.md +52 -0
  96. package/docs-site-docusaurus/docs/api/classes/AVLTree.md +6130 -0
  97. package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +282 -0
  98. package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +2266 -0
  99. package/docs-site-docusaurus/docs/api/classes/BST.md +5831 -0
  100. package/docs-site-docusaurus/docs/api/classes/BSTNode.md +333 -0
  101. package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +455 -0
  102. package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +4647 -0
  103. package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +331 -0
  104. package/docs-site-docusaurus/docs/api/classes/Deque.md +2767 -0
  105. package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +2999 -0
  106. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +2685 -0
  107. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +221 -0
  108. package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +253 -0
  109. package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +21 -0
  110. package/docs-site-docusaurus/docs/api/classes/HashMap.md +1333 -0
  111. package/docs-site-docusaurus/docs/api/classes/Heap.md +1881 -0
  112. package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +800 -0
  113. package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +644 -0
  114. package/docs-site-docusaurus/docs/api/classes/LinearBase.md +1632 -0
  115. package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +1853 -0
  116. package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +1108 -0
  117. package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +156 -0
  118. package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +2824 -0
  119. package/docs-site-docusaurus/docs/api/classes/MapGraph.md +2929 -0
  120. package/docs-site-docusaurus/docs/api/classes/Matrix.md +1026 -0
  121. package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +1866 -0
  122. package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +1883 -0
  123. package/docs-site-docusaurus/docs/api/classes/MinHeap.md +1879 -0
  124. package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +1882 -0
  125. package/docs-site-docusaurus/docs/api/classes/Navigator.md +109 -0
  126. package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +1839 -0
  127. package/docs-site-docusaurus/docs/api/classes/Queue.md +2244 -0
  128. package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +6374 -0
  129. package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +372 -0
  130. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +2897 -0
  131. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +169 -0
  132. package/docs-site-docusaurus/docs/api/classes/SkipList.md +1229 -0
  133. package/docs-site-docusaurus/docs/api/classes/Stack.md +1573 -0
  134. package/docs-site-docusaurus/docs/api/classes/TreeMap.md +1257 -0
  135. package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +1475 -0
  136. package/docs-site-docusaurus/docs/api/classes/TreeSet.md +1117 -0
  137. package/docs-site-docusaurus/docs/api/classes/Trie.md +1708 -0
  138. package/docs-site-docusaurus/docs/api/classes/TrieNode.md +199 -0
  139. package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +2979 -0
  140. package/docs-site-docusaurus/docs/guide/_category_.json +6 -0
  141. package/docs-site-docusaurus/docs/guide/architecture.md +613 -0
  142. package/docs-site-docusaurus/docs/guide/concepts.md +420 -0
  143. package/docs-site-docusaurus/docs/guide/guides.md +611 -0
  144. package/docs-site-docusaurus/docs/guide/installation.md +60 -0
  145. package/docs-site-docusaurus/docs/guide/integrations.md +823 -0
  146. package/docs-site-docusaurus/docs/guide/overview.md +638 -0
  147. package/docs-site-docusaurus/docs/guide/performance.md +833 -0
  148. package/docs-site-docusaurus/docs/guide/quick-start.md +73 -0
  149. package/docs-site-docusaurus/docusaurus.config.ts +159 -0
  150. package/docs-site-docusaurus/fix-mdx-generics.mjs +75 -0
  151. package/docs-site-docusaurus/package-lock.json +18667 -0
  152. package/docs-site-docusaurus/package.json +50 -0
  153. package/docs-site-docusaurus/prefix-class-to-methods.mjs +48 -0
  154. package/docs-site-docusaurus/sidebars.ts +23 -0
  155. package/docs-site-docusaurus/sort-protected.mjs +87 -0
  156. package/docs-site-docusaurus/src/css/custom.css +96 -0
  157. package/docs-site-docusaurus/src/pages/index.module.css +13 -0
  158. package/docs-site-docusaurus/src/pages/index.tsx +71 -0
  159. package/docs-site-docusaurus/src/pages/markdown-page.md +7 -0
  160. package/docs-site-docusaurus/src/theme/TOCItems/index.tsx +34 -0
  161. package/docs-site-docusaurus/static/.nojekyll +0 -0
  162. package/docs-site-docusaurus/static/img/docusaurus-social-card.jpg +0 -0
  163. package/docs-site-docusaurus/static/img/docusaurus.png +0 -0
  164. package/docs-site-docusaurus/static/img/favicon.ico +0 -0
  165. package/docs-site-docusaurus/static/img/favicon.png +0 -0
  166. package/docs-site-docusaurus/static/img/logo-180.png +0 -0
  167. package/docs-site-docusaurus/static/img/logo.jpg +0 -0
  168. package/docs-site-docusaurus/static/img/logo.png +0 -0
  169. package/docs-site-docusaurus/static/img/logo.svg +1 -0
  170. package/docs-site-docusaurus/static/img/og-image.png +0 -0
  171. package/docs-site-docusaurus/static/img/undraw_docusaurus_mountain.svg +171 -0
  172. package/docs-site-docusaurus/static/img/undraw_docusaurus_react.svg +170 -0
  173. package/docs-site-docusaurus/static/img/undraw_docusaurus_tree.svg +40 -0
  174. package/docs-site-docusaurus/static/robots.txt +4 -0
  175. package/docs-site-docusaurus/typedoc.json +23 -0
  176. package/package.json +109 -12
  177. package/src/data-structures/base/index.ts +1 -0
  178. package/src/data-structures/base/iterable-element-base.ts +4 -5
  179. package/src/data-structures/base/iterable-entry-base.ts +8 -8
  180. package/src/data-structures/base/linear-base.ts +3 -3
  181. package/src/data-structures/binary-tree/avl-tree.ts +386 -51
  182. package/src/data-structures/binary-tree/binary-indexed-tree.ts +596 -247
  183. package/src/data-structures/binary-tree/binary-tree.ts +956 -81
  184. package/src/data-structures/binary-tree/bst.ts +840 -35
  185. package/src/data-structures/binary-tree/red-black-tree.ts +689 -97
  186. package/src/data-structures/binary-tree/segment-tree.ts +498 -249
  187. package/src/data-structures/binary-tree/tree-map.ts +3784 -7
  188. package/src/data-structures/binary-tree/tree-multi-map.ts +3614 -211
  189. package/src/data-structures/binary-tree/tree-multi-set.ts +2874 -65
  190. package/src/data-structures/binary-tree/tree-set.ts +3531 -10
  191. package/src/data-structures/graph/abstract-graph.ts +4 -4
  192. package/src/data-structures/graph/directed-graph.ts +429 -47
  193. package/src/data-structures/graph/map-graph.ts +59 -1
  194. package/src/data-structures/graph/undirected-graph.ts +393 -59
  195. package/src/data-structures/hash/hash-map.ts +476 -92
  196. package/src/data-structures/heap/heap.ts +581 -99
  197. package/src/data-structures/heap/max-heap.ts +46 -0
  198. package/src/data-structures/heap/min-heap.ts +59 -0
  199. package/src/data-structures/linked-list/doubly-linked-list.ts +646 -47
  200. package/src/data-structures/linked-list/singly-linked-list.ts +596 -68
  201. package/src/data-structures/linked-list/skip-linked-list.ts +1067 -90
  202. package/src/data-structures/matrix/matrix.ts +584 -12
  203. package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
  204. package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
  205. package/src/data-structures/priority-queue/priority-queue.ts +60 -0
  206. package/src/data-structures/queue/deque.ts +592 -70
  207. package/src/data-structures/queue/queue.ts +463 -42
  208. package/src/data-structures/stack/stack.ts +384 -32
  209. package/src/data-structures/trie/trie.ts +470 -48
  210. package/src/interfaces/graph.ts +1 -1
  211. package/src/types/common.ts +2 -2
  212. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
  213. package/src/types/data-structures/heap/heap.ts +1 -0
  214. package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
  215. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  216. package/src/types/utils/validate-type.ts +4 -4
  217. package/vercel.json +6 -0
  218. package/dist/leetcode/avl-tree-counter.mjs +0 -2957
  219. package/dist/leetcode/avl-tree-multi-map.mjs +0 -2889
  220. package/dist/leetcode/avl-tree.mjs +0 -2720
  221. package/dist/leetcode/binary-tree.mjs +0 -1594
  222. package/dist/leetcode/bst.mjs +0 -2398
  223. package/dist/leetcode/deque.mjs +0 -683
  224. package/dist/leetcode/directed-graph.mjs +0 -1733
  225. package/dist/leetcode/doubly-linked-list.mjs +0 -709
  226. package/dist/leetcode/hash-map.mjs +0 -493
  227. package/dist/leetcode/heap.mjs +0 -542
  228. package/dist/leetcode/max-heap.mjs +0 -375
  229. package/dist/leetcode/max-priority-queue.mjs +0 -383
  230. package/dist/leetcode/min-heap.mjs +0 -363
  231. package/dist/leetcode/min-priority-queue.mjs +0 -371
  232. package/dist/leetcode/priority-queue.mjs +0 -363
  233. package/dist/leetcode/queue.mjs +0 -943
  234. package/dist/leetcode/red-black-tree.mjs +0 -2765
  235. package/dist/leetcode/singly-linked-list.mjs +0 -754
  236. package/dist/leetcode/stack.mjs +0 -217
  237. package/dist/leetcode/tree-counter.mjs +0 -3039
  238. package/dist/leetcode/tree-multi-map.mjs +0 -2913
  239. package/dist/leetcode/trie.mjs +0 -413
  240. package/dist/leetcode/undirected-graph.mjs +0 -1650
@@ -9,6 +9,89 @@ import type { MatrixOptions } from '../../types';
9
9
  /**
10
10
  *
11
11
  */
12
+ /**
13
+ * Matrix — a numeric matrix with standard linear algebra operations.
14
+ *
15
+ * @example
16
+ * // Basic matrix arithmetic
17
+ * const a = new Matrix([
18
+ * [1, 2],
19
+ * [3, 4]
20
+ * ]);
21
+ * const b = new Matrix([
22
+ * [5, 6],
23
+ * [7, 8]
24
+ * ]);
25
+ *
26
+ * const sum = a.add(b);
27
+ * console.log(sum?.data); // [
28
+ * // [6, 8],
29
+ * // [10, 12]
30
+ * // ];
31
+ *
32
+ * const diff = b.subtract(a);
33
+ * console.log(diff?.data); // [
34
+ * // [4, 4],
35
+ * // [4, 4]
36
+ * // ];
37
+ * @example
38
+ * // Matrix multiplication for transformations
39
+ * // 2x3 matrix * 3x2 matrix = 2x2 matrix
40
+ * const a = new Matrix([
41
+ * [1, 2, 3],
42
+ * [4, 5, 6]
43
+ * ]);
44
+ * const b = new Matrix([
45
+ * [7, 8],
46
+ * [9, 10],
47
+ * [11, 12]
48
+ * ]);
49
+ *
50
+ * const product = a.multiply(b);
51
+ * console.log(product?.rows); // 2;
52
+ * console.log(product?.cols); // 2;
53
+ * // Row 0: 1*7+2*9+3*11=58, 1*8+2*10+3*12=64
54
+ * // Row 1: 4*7+5*9+6*11=139, 4*8+5*10+6*12=154
55
+ * console.log(product?.data); // [
56
+ * // [58, 64],
57
+ * // [139, 154]
58
+ * // ];
59
+ * @example
60
+ * // Matrix transpose (square matrix)
61
+ * const m = new Matrix([
62
+ * [1, 2, 3],
63
+ * [4, 5, 6],
64
+ * [7, 8, 9]
65
+ * ]);
66
+ *
67
+ * const transposed = m.transpose();
68
+ * console.log(transposed.rows); // 3;
69
+ * console.log(transposed.cols); // 3;
70
+ * console.log(transposed.data); // [
71
+ * // [1, 4, 7],
72
+ * // [2, 5, 8],
73
+ * // [3, 6, 9]
74
+ * // ];
75
+ *
76
+ * // Transpose of transpose = original
77
+ * console.log(transposed.transpose().data); // m.data;
78
+ * @example
79
+ * // Get and set individual cells
80
+ * const m = new Matrix([
81
+ * [0, 0, 0],
82
+ * [0, 0, 0]
83
+ * ]);
84
+ *
85
+ * m.set(0, 1, 42);
86
+ * m.set(1, 2, 99);
87
+ *
88
+ * console.log(m.get(0, 1)); // 42;
89
+ * console.log(m.get(1, 2)); // 99;
90
+ * console.log(m.get(0, 0)); // 0;
91
+ *
92
+ * // Out of bounds returns undefined
93
+ * console.log(m.get(5, 5)); // undefined;
94
+ */
12
95
  export declare class Matrix {
13
96
  /**
14
97
  * The constructor function initializes a matrix object with the provided data and options, or with
@@ -59,6 +142,53 @@ export declare class Matrix {
59
142
  * retrieve from the data array.
60
143
  * @returns The `get` function returns a number if the provided row and column indices are valid.
61
144
  * Otherwise, it returns `undefined`.
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+ * @example
177
+ * // Get and set individual cells
178
+ * const m = new Matrix([
179
+ * [0, 0, 0],
180
+ * [0, 0, 0]
181
+ * ]);
182
+ *
183
+ * m.set(0, 1, 42);
184
+ * m.set(1, 2, 99);
185
+ *
186
+ * console.log(m.get(0, 1)); // 42;
187
+ * console.log(m.get(1, 2)); // 99;
188
+ * console.log(m.get(0, 0)); // 0;
189
+ *
190
+ * // Out of bounds returns undefined
191
+ * console.log(m.get(5, 5)); // undefined;
62
192
  */
63
193
  get(row: number, col: number): number | undefined;
64
194
  /**
@@ -72,6 +202,44 @@ export declare class Matrix {
72
202
  * @returns a boolean value. It returns true if the index (row, col) is valid and the value is
73
203
  * successfully set in the data array. It returns false if the index is invalid and the value is not
74
204
  * set.
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+
234
+
235
+
236
+ * @example
237
+ * // Modify individual cells
238
+ * const m = Matrix.zeros(2, 2);
239
+ * console.log(m.set(0, 0, 5)); // true;
240
+ * console.log(m.set(1, 1, 10)); // true;
241
+ * console.log(m.get(0, 0)); // 5;
242
+ * console.log(m.get(1, 1)); // 10;
75
243
  */
76
244
  set(row: number, col: number, value: number): boolean;
77
245
  /**
@@ -86,6 +254,59 @@ export declare class Matrix {
86
254
  * @param {Matrix} matrix - The `matrix` parameter is an instance of the `Matrix` class.
87
255
  * @returns The `add` method returns a new `Matrix` object that represents the result of adding the
88
256
  * current matrix with the provided `matrix` parameter.
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+
288
+ * @example
289
+ * // Basic matrix arithmetic
290
+ * const a = new Matrix([
291
+ * [1, 2],
292
+ * [3, 4]
293
+ * ]);
294
+ * const b = new Matrix([
295
+ * [5, 6],
296
+ * [7, 8]
297
+ * ]);
298
+ *
299
+ * const sum = a.add(b);
300
+ * console.log(sum?.data); // [
301
+ * // [6, 8],
302
+ * // [10, 12]
303
+ * // ];
304
+ *
305
+ * const diff = b.subtract(a);
306
+ * console.log(diff?.data); // [
307
+ * // [4, 4],
308
+ * // [4, 4]
309
+ * // ];
89
310
  */
90
311
  add(matrix: Matrix): Matrix | undefined;
91
312
  /**
@@ -94,6 +315,43 @@ export declare class Matrix {
94
315
  * @param {Matrix} matrix - The `matrix` parameter is an instance of the `Matrix` class. It
95
316
  * represents the matrix that you want to subtract from the current matrix.
96
317
  * @returns a new Matrix object with the result of the subtraction operation.
318
+
319
+
320
+
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+
344
+
345
+
346
+
347
+
348
+
349
+ * @example
350
+ * // Element-wise subtraction
351
+ * const a = Matrix.from([[5, 6], [7, 8]]);
352
+ * const b = Matrix.from([[1, 2], [3, 4]]);
353
+ * const result = a.subtract(b);
354
+ * console.log(result?.toArray()); // [[4, 4], [4, 4]];
97
355
  */
98
356
  subtract(matrix: Matrix): Matrix | undefined;
99
357
  /**
@@ -101,23 +359,205 @@ export declare class Matrix {
101
359
  * as a new matrix.
102
360
  * @param {Matrix} matrix - The `matrix` parameter is an instance of the `Matrix` class.
103
361
  * @returns a new Matrix object.
362
+
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+
371
+
372
+
373
+
374
+
375
+
376
+
377
+
378
+
379
+
380
+
381
+
382
+
383
+
384
+
385
+
386
+
387
+
388
+
389
+
390
+
391
+
392
+
393
+ * @example
394
+ * // Matrix multiplication for transformations
395
+ * // 2x3 matrix * 3x2 matrix = 2x2 matrix
396
+ * const a = new Matrix([
397
+ * [1, 2, 3],
398
+ * [4, 5, 6]
399
+ * ]);
400
+ * const b = new Matrix([
401
+ * [7, 8],
402
+ * [9, 10],
403
+ * [11, 12]
404
+ * ]);
405
+ *
406
+ * const product = a.multiply(b);
407
+ * console.log(product?.rows); // 2;
408
+ * console.log(product?.cols); // 2;
409
+ * // Row 0: 1*7+2*9+3*11=58, 1*8+2*10+3*12=64
410
+ * // Row 1: 4*7+5*9+6*11=139, 4*8+5*10+6*12=154
411
+ * console.log(product?.data); // [
412
+ * // [58, 64],
413
+ * // [139, 154]
414
+ * // ];
104
415
  */
105
416
  multiply(matrix: Matrix): Matrix | undefined;
106
417
  /**
107
418
  * The transpose function takes a matrix and returns a new matrix that is the transpose of the
108
419
  * original matrix.
109
420
  * @returns The transpose() function returns a new Matrix object with the transposed data.
421
+
422
+
423
+
424
+
425
+
426
+
427
+
428
+
429
+
430
+
431
+
432
+
433
+
434
+
435
+
436
+
437
+
438
+
439
+
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+
448
+
449
+
450
+
451
+
452
+ * @example
453
+ * // Matrix transpose (square matrix)
454
+ * const m = new Matrix([
455
+ * [1, 2, 3],
456
+ * [4, 5, 6],
457
+ * [7, 8, 9]
458
+ * ]);
459
+ *
460
+ * const transposed = m.transpose();
461
+ * console.log(transposed.rows); // 3;
462
+ * console.log(transposed.cols); // 3;
463
+ * console.log(transposed.data); // [
464
+ * // [1, 4, 7],
465
+ * // [2, 5, 8],
466
+ * // [3, 6, 9]
467
+ * // ];
468
+ *
469
+ * // Transpose of transpose = original
470
+ * console.log(transposed.transpose().data); // m.data;
110
471
  */
111
472
  transpose(): Matrix;
112
473
  /**
113
474
  * The `inverse` function calculates the inverse of a square matrix using Gaussian elimination.
114
475
  * @returns a Matrix object, which represents the inverse of the original matrix.
476
+
477
+
478
+
479
+
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+ * @example
508
+ * // Compute the inverse of a 2x2 matrix
509
+ * const m = Matrix.from([[4, 7], [2, 6]]);
510
+ * const inv = m.inverse();
511
+ * console.log(inv); // defined;
512
+ * // A * A^-1 should ≈ Identity
513
+ * const product = m.multiply(inv!);
514
+ * console.log(product?.get(0, 0)); // toBeCloseTo;
515
+ * console.log(product?.get(0, 1)); // toBeCloseTo;
516
+ * console.log(product?.get(1, 0)); // toBeCloseTo;
517
+ * console.log(product?.get(1, 1)); // toBeCloseTo;
115
518
  */
116
519
  inverse(): Matrix | undefined;
117
520
  /**
118
521
  * The dot function calculates the dot product of two matrices and returns a new matrix.
119
522
  * @param {Matrix} matrix - The `matrix` parameter is an instance of the `Matrix` class.
120
523
  * @returns a new Matrix object.
524
+
525
+
526
+
527
+
528
+
529
+
530
+
531
+
532
+
533
+
534
+
535
+
536
+
537
+
538
+
539
+
540
+
541
+
542
+
543
+
544
+
545
+
546
+
547
+
548
+
549
+
550
+
551
+
552
+
553
+
554
+
555
+ * @example
556
+ * // Dot product of two matrices
557
+ * const a = Matrix.from([[1, 2], [3, 4]]);
558
+ * const b = Matrix.from([[5, 6], [7, 8]]);
559
+ * const result = a.dot(b);
560
+ * console.log(result?.toArray()); // [[19, 22], [43, 50]];
121
561
  */
122
562
  dot(matrix: Matrix): Matrix | undefined;
123
563
  /**
@@ -136,6 +576,57 @@ export declare class Matrix {
136
576
  * and properties as the current instance.
137
577
  */
138
578
  clone(): Matrix;
579
+ /**
580
+ * Returns [rows, cols] dimensions tuple.
581
+ */
582
+ get size(): [number, number];
583
+ isEmpty(): boolean;
584
+ /**
585
+ * Returns a deep copy of the data as a plain 2D array.
586
+ */
587
+ toArray(): number[][];
588
+ /**
589
+ * Returns a flat row-major array.
590
+ */
591
+ flatten(): number[];
592
+ /**
593
+ * Iterates over rows.
594
+ */
595
+ [Symbol.iterator](): IterableIterator<number[]>;
596
+ /**
597
+ * Visits each element with its row and column index.
598
+ */
599
+ forEach(callback: (value: number, row: number, col: number) => void): void;
600
+ /**
601
+ * Maps each element (number → number) and returns a new Matrix.
602
+ */
603
+ map(callback: (value: number, row: number, col: number) => number): Matrix;
604
+ print(): void;
605
+ /**
606
+ * Creates a rows×cols zero matrix.
607
+ * @example
608
+ * ```ts
609
+ * const z = Matrix.zeros(2, 3); // [[0,0,0],[0,0,0]]
610
+ * ```
611
+ */
612
+ static zeros(rows: number, cols: number): Matrix;
613
+ /**
614
+ * Creates an n×n identity matrix.
615
+ * @example
616
+ * ```ts
617
+ * const I = Matrix.identity(3); // [[1,0,0],[0,1,0],[0,0,1]]
618
+ * ```
619
+ */
620
+ static identity(n: number): Matrix;
621
+ /**
622
+ * Creates a Matrix from a plain 2D array (deep copy).
623
+ * @example
624
+ * ```ts
625
+ * const m = Matrix.from([[1, 2], [3, 4]]);
626
+ * m.get(0, 1); // 2
627
+ * ```
628
+ */
629
+ static from(data: number[][]): Matrix;
139
630
  protected _addFn(a: number | undefined, b: number): number | undefined;
140
631
  protected _subtractFn(a: number, b: number): number;
141
632
  protected _multiplyFn(a: number, b: number): number;
@@ -14,6 +14,63 @@ import { PriorityQueue } from './priority-queue';
14
14
  * @template E Element type stored in the queue.
15
15
  * @template R Extra record/metadata associated with each element.
16
16
  * @example
17
+ * // Job scheduling by priority
18
+ * const jobs = new MaxPriorityQueue<number>();
19
+ *
20
+ * jobs.add(3); // low priority
21
+ * jobs.add(7); // high priority
22
+ * jobs.add(5); // medium priority
23
+ * jobs.add(10); // critical
24
+ *
25
+ * // Highest priority job first
26
+ * console.log(jobs.poll()); // 10;
27
+ * console.log(jobs.poll()); // 7;
28
+ * console.log(jobs.poll()); // 5;
29
+ * console.log(jobs.poll()); // 3;
30
+ * @example
31
+ * // Auction system with highest bid tracking
32
+ * interface Bid {
33
+ * bidder: string;
34
+ * amount: number;
35
+ * }
36
+ *
37
+ * const auction = new MaxPriorityQueue<Bid>([], {
38
+ * comparator: (a, b) => b.amount - a.amount
39
+ * });
40
+ *
41
+ * auction.add({ bidder: 'Alice', amount: 100 });
42
+ * auction.add({ bidder: 'Bob', amount: 250 });
43
+ * auction.add({ bidder: 'Charlie', amount: 175 });
44
+ *
45
+ * // Current highest bid
46
+ * console.log(auction.peek()?.bidder); // 'Bob';
47
+ * console.log(auction.peek()?.amount); // 250;
48
+ *
49
+ * // Process winning bid
50
+ * const winner = auction.poll()!;
51
+ * console.log(winner.bidder); // 'Bob';
52
+ * console.log(auction.peek()?.bidder); // 'Charlie';
53
+ * @example
54
+ * // CPU process scheduling
55
+ * const cpuQueue = new MaxPriorityQueue<[number, string]>([], {
56
+ * comparator: (a, b) => b[0] - a[0]
57
+ * });
58
+ *
59
+ * cpuQueue.add([5, 'System process']);
60
+ * cpuQueue.add([1, 'Background task']);
61
+ * cpuQueue.add([8, 'User interaction']);
62
+ * cpuQueue.add([3, 'Network sync']);
63
+ *
64
+ * const order = [];
65
+ * while (cpuQueue.size > 0) {
66
+ * order.push(cpuQueue.poll()![1]);
67
+ * }
68
+ * console.log(order); // [
69
+ * // 'User interaction',
70
+ * // 'System process',
71
+ * // 'Network sync',
72
+ * // 'Background task'
73
+ * // ];
17
74
  */
18
75
  export declare class MaxPriorityQueue<E = any, R = any> extends PriorityQueue<E, R> {
19
76
  /**
@@ -14,6 +14,66 @@ import { PriorityQueue } from './priority-queue';
14
14
  * @template E Element type stored in the queue.
15
15
  * @template R Extra record/metadata associated with each element.
16
16
  * @example
17
+ * // Shortest job first scheduling
18
+ * const jobs = new MinPriorityQueue<number>();
19
+ *
20
+ * jobs.add(8); // 8 seconds
21
+ * jobs.add(2); // 2 seconds
22
+ * jobs.add(5); // 5 seconds
23
+ * jobs.add(1); // 1 second
24
+ *
25
+ * // Shortest job first
26
+ * console.log(jobs.poll()); // 1;
27
+ * console.log(jobs.poll()); // 2;
28
+ * console.log(jobs.poll()); // 5;
29
+ * console.log(jobs.poll()); // 8;
30
+ * @example
31
+ * // Event-driven simulation with timestamps
32
+ * interface Event {
33
+ * time: number;
34
+ * action: string;
35
+ * }
36
+ *
37
+ * const timeline = new MinPriorityQueue<Event>([], {
38
+ * comparator: (a, b) => a.time - b.time
39
+ * });
40
+ *
41
+ * timeline.add({ time: 300, action: 'Timeout' });
42
+ * timeline.add({ time: 100, action: 'Request received' });
43
+ * timeline.add({ time: 200, action: 'Processing done' });
44
+ * timeline.add({ time: 150, action: 'Cache hit' });
45
+ *
46
+ * const order = [];
47
+ * while (timeline.size > 0) {
48
+ * order.push(timeline.poll()!.action);
49
+ * }
50
+ * console.log(order); // [
51
+ * // 'Request received',
52
+ * // 'Cache hit',
53
+ * // 'Processing done',
54
+ * // 'Timeout'
55
+ * // ];
56
+ * @example
57
+ * // Huffman coding frequency selection
58
+ * // Character frequencies for Huffman tree building
59
+ * const freq = new MinPriorityQueue<[number, string]>([], {
60
+ * comparator: (a, b) => a[0] - b[0]
61
+ * });
62
+ *
63
+ * freq.add([5, 'a']);
64
+ * freq.add([9, 'b']);
65
+ * freq.add([12, 'c']);
66
+ * freq.add([2, 'd']);
67
+ *
68
+ * // Always pick two lowest frequencies
69
+ * const first = freq.poll()!;
70
+ * const second = freq.poll()!;
71
+ * console.log(first[1]); // 'd'; // freq 2
72
+ * console.log(second[1]); // 'a'; // freq 5
73
+ *
74
+ * // Combined node goes back
75
+ * freq.add([first[0] + second[0], first[1] + second[1]]);
76
+ * console.log(freq.peek()![0]); // 7;
17
77
  */
18
78
  export declare class MinPriorityQueue<E = any, R = any> extends PriorityQueue<E, R> {
19
79
  /**