tree-multimap-typed 1.42.5

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 (366) hide show
  1. package/.dependency-cruiser.js +449 -0
  2. package/.eslintrc.js +65 -0
  3. package/.prettierignore +6 -0
  4. package/.prettierrc.js +16 -0
  5. package/LICENSE +21 -0
  6. package/README.md +527 -0
  7. package/coverage/clover.xml +14 -0
  8. package/coverage/coverage-final.json +96 -0
  9. package/coverage/coverage-summary.json +60 -0
  10. package/coverage/lcov-report/base.css +403 -0
  11. package/coverage/lcov-report/block-navigation.js +87 -0
  12. package/coverage/lcov-report/favicon.png +0 -0
  13. package/coverage/lcov-report/index.html +120 -0
  14. package/coverage/lcov-report/index.ts.html +110 -0
  15. package/coverage/lcov-report/prettify.css +1 -0
  16. package/coverage/lcov-report/prettify.js +2 -0
  17. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  18. package/coverage/lcov-report/sorter.js +206 -0
  19. package/coverage/lcov.info +14 -0
  20. package/dist/data-structures/binary-tree/avl-tree.d.ts +106 -0
  21. package/dist/data-structures/binary-tree/avl-tree.js +349 -0
  22. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +149 -0
  23. package/dist/data-structures/binary-tree/binary-indexed-tree.js +269 -0
  24. package/dist/data-structures/binary-tree/binary-tree.d.ts +322 -0
  25. package/dist/data-structures/binary-tree/binary-tree.js +1305 -0
  26. package/dist/data-structures/binary-tree/bst.d.ts +175 -0
  27. package/dist/data-structures/binary-tree/bst.js +546 -0
  28. package/dist/data-structures/binary-tree/index.d.ts +7 -0
  29. package/dist/data-structures/binary-tree/index.js +23 -0
  30. package/dist/data-structures/binary-tree/rb-tree.d.ts +93 -0
  31. package/dist/data-structures/binary-tree/rb-tree.js +434 -0
  32. package/dist/data-structures/binary-tree/segment-tree.d.ts +67 -0
  33. package/dist/data-structures/binary-tree/segment-tree.js +180 -0
  34. package/dist/data-structures/binary-tree/tree-multimap.d.ts +126 -0
  35. package/dist/data-structures/binary-tree/tree-multimap.js +358 -0
  36. package/dist/data-structures/graph/abstract-graph.d.ts +347 -0
  37. package/dist/data-structures/graph/abstract-graph.js +936 -0
  38. package/dist/data-structures/graph/directed-graph.d.ts +194 -0
  39. package/dist/data-structures/graph/directed-graph.js +404 -0
  40. package/dist/data-structures/graph/index.d.ts +4 -0
  41. package/dist/data-structures/graph/index.js +20 -0
  42. package/dist/data-structures/graph/map-graph.d.ts +73 -0
  43. package/dist/data-structures/graph/map-graph.js +93 -0
  44. package/dist/data-structures/graph/undirected-graph.d.ts +120 -0
  45. package/dist/data-structures/graph/undirected-graph.js +239 -0
  46. package/dist/data-structures/hash/coordinate-map.d.ts +44 -0
  47. package/dist/data-structures/hash/coordinate-map.js +62 -0
  48. package/dist/data-structures/hash/coordinate-set.d.ts +36 -0
  49. package/dist/data-structures/hash/coordinate-set.js +52 -0
  50. package/dist/data-structures/hash/hash-map.d.ts +50 -0
  51. package/dist/data-structures/hash/hash-map.js +153 -0
  52. package/dist/data-structures/hash/hash-table.d.ts +103 -0
  53. package/dist/data-structures/hash/hash-table.js +236 -0
  54. package/dist/data-structures/hash/index.d.ts +6 -0
  55. package/dist/data-structures/hash/index.js +22 -0
  56. package/dist/data-structures/hash/tree-map.d.ts +2 -0
  57. package/dist/data-structures/hash/tree-map.js +6 -0
  58. package/dist/data-structures/hash/tree-set.d.ts +2 -0
  59. package/dist/data-structures/hash/tree-set.js +6 -0
  60. package/dist/data-structures/heap/heap.d.ts +235 -0
  61. package/dist/data-structures/heap/heap.js +515 -0
  62. package/dist/data-structures/heap/index.d.ts +3 -0
  63. package/dist/data-structures/heap/index.js +19 -0
  64. package/dist/data-structures/heap/max-heap.d.ts +15 -0
  65. package/dist/data-structures/heap/max-heap.js +26 -0
  66. package/dist/data-structures/heap/min-heap.d.ts +15 -0
  67. package/dist/data-structures/heap/min-heap.js +26 -0
  68. package/dist/data-structures/index.d.ts +11 -0
  69. package/dist/data-structures/index.js +27 -0
  70. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +253 -0
  71. package/dist/data-structures/linked-list/doubly-linked-list.js +569 -0
  72. package/dist/data-structures/linked-list/index.d.ts +3 -0
  73. package/dist/data-structures/linked-list/index.js +19 -0
  74. package/dist/data-structures/linked-list/singly-linked-list.d.ts +232 -0
  75. package/dist/data-structures/linked-list/singly-linked-list.js +533 -0
  76. package/dist/data-structures/linked-list/skip-linked-list.d.ts +80 -0
  77. package/dist/data-structures/linked-list/skip-linked-list.js +187 -0
  78. package/dist/data-structures/matrix/index.d.ts +4 -0
  79. package/dist/data-structures/matrix/index.js +20 -0
  80. package/dist/data-structures/matrix/matrix.d.ts +21 -0
  81. package/dist/data-structures/matrix/matrix.js +28 -0
  82. package/dist/data-structures/matrix/matrix2d.d.ts +107 -0
  83. package/dist/data-structures/matrix/matrix2d.js +199 -0
  84. package/dist/data-structures/matrix/navigator.d.ts +52 -0
  85. package/dist/data-structures/matrix/navigator.js +106 -0
  86. package/dist/data-structures/matrix/vector2d.d.ts +200 -0
  87. package/dist/data-structures/matrix/vector2d.js +290 -0
  88. package/dist/data-structures/priority-queue/index.d.ts +3 -0
  89. package/dist/data-structures/priority-queue/index.js +19 -0
  90. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
  91. package/dist/data-structures/priority-queue/max-priority-queue.js +26 -0
  92. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
  93. package/dist/data-structures/priority-queue/min-priority-queue.js +26 -0
  94. package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -0
  95. package/dist/data-structures/priority-queue/priority-queue.js +17 -0
  96. package/dist/data-structures/queue/deque.d.ts +161 -0
  97. package/dist/data-structures/queue/deque.js +264 -0
  98. package/dist/data-structures/queue/index.d.ts +2 -0
  99. package/dist/data-structures/queue/index.js +18 -0
  100. package/dist/data-structures/queue/queue.d.ts +122 -0
  101. package/dist/data-structures/queue/queue.js +187 -0
  102. package/dist/data-structures/stack/index.d.ts +1 -0
  103. package/dist/data-structures/stack/index.js +17 -0
  104. package/dist/data-structures/stack/stack.d.ts +64 -0
  105. package/dist/data-structures/stack/stack.js +94 -0
  106. package/dist/data-structures/tree/index.d.ts +1 -0
  107. package/dist/data-structures/tree/index.js +17 -0
  108. package/dist/data-structures/tree/tree.d.ts +8 -0
  109. package/dist/data-structures/tree/tree.js +40 -0
  110. package/dist/data-structures/trie/index.d.ts +1 -0
  111. package/dist/data-structures/trie/index.js +17 -0
  112. package/dist/data-structures/trie/trie.d.ts +79 -0
  113. package/dist/data-structures/trie/trie.js +251 -0
  114. package/dist/index.d.ts +10 -0
  115. package/dist/index.js +27 -0
  116. package/dist/interfaces/binary-tree.d.ts +7 -0
  117. package/dist/interfaces/binary-tree.js +2 -0
  118. package/dist/interfaces/doubly-linked-list.d.ts +1 -0
  119. package/dist/interfaces/doubly-linked-list.js +2 -0
  120. package/dist/interfaces/graph.d.ts +5 -0
  121. package/dist/interfaces/graph.js +2 -0
  122. package/dist/interfaces/heap.d.ts +1 -0
  123. package/dist/interfaces/heap.js +2 -0
  124. package/dist/interfaces/index.d.ts +8 -0
  125. package/dist/interfaces/index.js +24 -0
  126. package/dist/interfaces/navigator.d.ts +1 -0
  127. package/dist/interfaces/navigator.js +2 -0
  128. package/dist/interfaces/priority-queue.d.ts +1 -0
  129. package/dist/interfaces/priority-queue.js +2 -0
  130. package/dist/interfaces/segment-tree.d.ts +1 -0
  131. package/dist/interfaces/segment-tree.js +2 -0
  132. package/dist/interfaces/singly-linked-list.d.ts +1 -0
  133. package/dist/interfaces/singly-linked-list.js +2 -0
  134. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +4 -0
  135. package/dist/types/data-structures/binary-tree/avl-tree.js +2 -0
  136. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  137. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +2 -0
  138. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  139. package/dist/types/data-structures/binary-tree/binary-tree.js +24 -0
  140. package/dist/types/data-structures/binary-tree/bst.d.ts +7 -0
  141. package/dist/types/data-structures/binary-tree/bst.js +2 -0
  142. package/dist/types/data-structures/binary-tree/index.d.ts +6 -0
  143. package/dist/types/data-structures/binary-tree/index.js +22 -0
  144. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +8 -0
  145. package/dist/types/data-structures/binary-tree/rb-tree.js +8 -0
  146. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  147. package/dist/types/data-structures/binary-tree/segment-tree.js +2 -0
  148. package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +4 -0
  149. package/dist/types/data-structures/binary-tree/tree-multimap.js +2 -0
  150. package/dist/types/data-structures/graph/abstract-graph.d.ts +10 -0
  151. package/dist/types/data-structures/graph/abstract-graph.js +2 -0
  152. package/dist/types/data-structures/graph/directed-graph.d.ts +6 -0
  153. package/dist/types/data-structures/graph/directed-graph.js +9 -0
  154. package/dist/types/data-structures/graph/index.d.ts +3 -0
  155. package/dist/types/data-structures/graph/index.js +19 -0
  156. package/dist/types/data-structures/graph/map-graph.d.ts +1 -0
  157. package/dist/types/data-structures/graph/map-graph.js +2 -0
  158. package/dist/types/data-structures/graph/undirected-graph.d.ts +1 -0
  159. package/dist/types/data-structures/graph/undirected-graph.js +2 -0
  160. package/dist/types/data-structures/hash/coordinate-map.d.ts +1 -0
  161. package/dist/types/data-structures/hash/coordinate-map.js +2 -0
  162. package/dist/types/data-structures/hash/coordinate-set.d.ts +1 -0
  163. package/dist/types/data-structures/hash/coordinate-set.js +2 -0
  164. package/dist/types/data-structures/hash/hash-map.d.ts +1 -0
  165. package/dist/types/data-structures/hash/hash-map.js +2 -0
  166. package/dist/types/data-structures/hash/hash-table.d.ts +1 -0
  167. package/dist/types/data-structures/hash/hash-table.js +2 -0
  168. package/dist/types/data-structures/hash/index.d.ts +1 -0
  169. package/dist/types/data-structures/hash/index.js +2 -0
  170. package/dist/types/data-structures/hash/tree-map.d.ts +1 -0
  171. package/dist/types/data-structures/hash/tree-map.js +2 -0
  172. package/dist/types/data-structures/hash/tree-set.d.ts +1 -0
  173. package/dist/types/data-structures/hash/tree-set.js +2 -0
  174. package/dist/types/data-structures/heap/heap.d.ts +1 -0
  175. package/dist/types/data-structures/heap/heap.js +2 -0
  176. package/dist/types/data-structures/heap/index.d.ts +1 -0
  177. package/dist/types/data-structures/heap/index.js +17 -0
  178. package/dist/types/data-structures/heap/max-heap.d.ts +1 -0
  179. package/dist/types/data-structures/heap/max-heap.js +2 -0
  180. package/dist/types/data-structures/heap/min-heap.d.ts +1 -0
  181. package/dist/types/data-structures/heap/min-heap.js +2 -0
  182. package/dist/types/data-structures/index.d.ts +11 -0
  183. package/dist/types/data-structures/index.js +27 -0
  184. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -0
  185. package/dist/types/data-structures/linked-list/doubly-linked-list.js +2 -0
  186. package/dist/types/data-structures/linked-list/index.d.ts +2 -0
  187. package/dist/types/data-structures/linked-list/index.js +18 -0
  188. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +1 -0
  189. package/dist/types/data-structures/linked-list/singly-linked-list.js +2 -0
  190. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +1 -0
  191. package/dist/types/data-structures/linked-list/skip-linked-list.js +2 -0
  192. package/dist/types/data-structures/matrix/index.d.ts +1 -0
  193. package/dist/types/data-structures/matrix/index.js +17 -0
  194. package/dist/types/data-structures/matrix/matrix.d.ts +1 -0
  195. package/dist/types/data-structures/matrix/matrix.js +2 -0
  196. package/dist/types/data-structures/matrix/matrix2d.d.ts +1 -0
  197. package/dist/types/data-structures/matrix/matrix2d.js +2 -0
  198. package/dist/types/data-structures/matrix/navigator.d.ts +14 -0
  199. package/dist/types/data-structures/matrix/navigator.js +2 -0
  200. package/dist/types/data-structures/matrix/vector2d.d.ts +1 -0
  201. package/dist/types/data-structures/matrix/vector2d.js +2 -0
  202. package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
  203. package/dist/types/data-structures/priority-queue/index.js +19 -0
  204. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  205. package/dist/types/data-structures/priority-queue/max-priority-queue.js +2 -0
  206. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  207. package/dist/types/data-structures/priority-queue/min-priority-queue.js +2 -0
  208. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  209. package/dist/types/data-structures/priority-queue/priority-queue.js +2 -0
  210. package/dist/types/data-structures/queue/deque.d.ts +1 -0
  211. package/dist/types/data-structures/queue/deque.js +2 -0
  212. package/dist/types/data-structures/queue/index.d.ts +2 -0
  213. package/dist/types/data-structures/queue/index.js +18 -0
  214. package/dist/types/data-structures/queue/queue.d.ts +1 -0
  215. package/dist/types/data-structures/queue/queue.js +2 -0
  216. package/dist/types/data-structures/stack/index.d.ts +1 -0
  217. package/dist/types/data-structures/stack/index.js +17 -0
  218. package/dist/types/data-structures/stack/stack.d.ts +1 -0
  219. package/dist/types/data-structures/stack/stack.js +2 -0
  220. package/dist/types/data-structures/tree/index.d.ts +1 -0
  221. package/dist/types/data-structures/tree/index.js +17 -0
  222. package/dist/types/data-structures/tree/tree.d.ts +1 -0
  223. package/dist/types/data-structures/tree/tree.js +2 -0
  224. package/dist/types/data-structures/trie/index.d.ts +1 -0
  225. package/dist/types/data-structures/trie/index.js +17 -0
  226. package/dist/types/data-structures/trie/trie.d.ts +1 -0
  227. package/dist/types/data-structures/trie/trie.js +2 -0
  228. package/dist/types/helpers.d.ts +8 -0
  229. package/dist/types/helpers.js +9 -0
  230. package/dist/types/index.d.ts +3 -0
  231. package/dist/types/index.js +19 -0
  232. package/dist/types/utils/index.d.ts +2 -0
  233. package/dist/types/utils/index.js +18 -0
  234. package/dist/types/utils/utils.d.ts +7 -0
  235. package/dist/types/utils/utils.js +2 -0
  236. package/dist/types/utils/validate-type.d.ts +19 -0
  237. package/dist/types/utils/validate-type.js +2 -0
  238. package/dist/utils/index.d.ts +1 -0
  239. package/dist/utils/index.js +17 -0
  240. package/dist/utils/utils.d.ts +20 -0
  241. package/dist/utils/utils.js +73 -0
  242. package/docs/.nojekyll +1 -0
  243. package/docs/assets/highlight.css +50 -0
  244. package/docs/assets/main.js +59 -0
  245. package/docs/assets/navigation.js +1 -0
  246. package/docs/assets/search.js +1 -0
  247. package/docs/assets/style.css +1383 -0
  248. package/docs/classes/TreeMultiset.html +2376 -0
  249. package/docs/classes/TreeMultisetNode.html +313 -0
  250. package/docs/index.html +523 -0
  251. package/docs/modules.html +45 -0
  252. package/jest.config.js +8 -0
  253. package/package.json +184 -0
  254. package/src/data-structures/binary-tree/avl-tree.ts +352 -0
  255. package/src/data-structures/binary-tree/binary-indexed-tree.ts +306 -0
  256. package/src/data-structures/binary-tree/binary-tree.ts +1558 -0
  257. package/src/data-structures/binary-tree/bst.ts +564 -0
  258. package/src/data-structures/binary-tree/index.ts +7 -0
  259. package/src/data-structures/binary-tree/rb-tree.ts +486 -0
  260. package/src/data-structures/binary-tree/segment-tree.ts +190 -0
  261. package/src/data-structures/binary-tree/tree-multimap.ts +381 -0
  262. package/src/data-structures/graph/abstract-graph.ts +1056 -0
  263. package/src/data-structures/graph/directed-graph.ts +450 -0
  264. package/src/data-structures/graph/index.ts +4 -0
  265. package/src/data-structures/graph/map-graph.ts +106 -0
  266. package/src/data-structures/graph/undirected-graph.ts +260 -0
  267. package/src/data-structures/hash/coordinate-map.ts +63 -0
  268. package/src/data-structures/hash/coordinate-set.ts +52 -0
  269. package/src/data-structures/hash/hash-map.ts +185 -0
  270. package/src/data-structures/hash/hash-table.ts +268 -0
  271. package/src/data-structures/hash/index.ts +6 -0
  272. package/src/data-structures/hash/tree-map.ts +1 -0
  273. package/src/data-structures/hash/tree-set.ts +1 -0
  274. package/src/data-structures/heap/heap.ts +589 -0
  275. package/src/data-structures/heap/index.ts +3 -0
  276. package/src/data-structures/heap/max-heap.ts +26 -0
  277. package/src/data-structures/heap/min-heap.ts +26 -0
  278. package/src/data-structures/index.ts +11 -0
  279. package/src/data-structures/linked-list/doubly-linked-list.ts +605 -0
  280. package/src/data-structures/linked-list/index.ts +3 -0
  281. package/src/data-structures/linked-list/singly-linked-list.ts +576 -0
  282. package/src/data-structures/linked-list/skip-linked-list.ts +221 -0
  283. package/src/data-structures/matrix/index.ts +4 -0
  284. package/src/data-structures/matrix/matrix.ts +27 -0
  285. package/src/data-structures/matrix/matrix2d.ts +211 -0
  286. package/src/data-structures/matrix/navigator.ts +121 -0
  287. package/src/data-structures/matrix/vector2d.ts +314 -0
  288. package/src/data-structures/priority-queue/index.ts +3 -0
  289. package/src/data-structures/priority-queue/max-priority-queue.ts +25 -0
  290. package/src/data-structures/priority-queue/min-priority-queue.ts +25 -0
  291. package/src/data-structures/priority-queue/priority-queue.ts +16 -0
  292. package/src/data-structures/queue/deque.ts +281 -0
  293. package/src/data-structures/queue/index.ts +2 -0
  294. package/src/data-structures/queue/queue.ts +209 -0
  295. package/src/data-structures/stack/index.ts +1 -0
  296. package/src/data-structures/stack/stack.ts +102 -0
  297. package/src/data-structures/tree/index.ts +1 -0
  298. package/src/data-structures/tree/tree.ts +41 -0
  299. package/src/data-structures/trie/index.ts +1 -0
  300. package/src/data-structures/trie/trie.ts +262 -0
  301. package/src/index.ts +11 -0
  302. package/src/interfaces/binary-tree.ts +10 -0
  303. package/src/interfaces/doubly-linked-list.ts +1 -0
  304. package/src/interfaces/graph.ts +7 -0
  305. package/src/interfaces/heap.ts +1 -0
  306. package/src/interfaces/index.ts +8 -0
  307. package/src/interfaces/navigator.ts +1 -0
  308. package/src/interfaces/priority-queue.ts +1 -0
  309. package/src/interfaces/segment-tree.ts +1 -0
  310. package/src/interfaces/singly-linked-list.ts +1 -0
  311. package/src/types/data-structures/binary-tree/avl-tree.ts +5 -0
  312. package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
  313. package/src/types/data-structures/binary-tree/binary-tree.ts +31 -0
  314. package/src/types/data-structures/binary-tree/bst.ts +11 -0
  315. package/src/types/data-structures/binary-tree/index.ts +6 -0
  316. package/src/types/data-structures/binary-tree/rb-tree.ts +8 -0
  317. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -0
  318. package/src/types/data-structures/binary-tree/tree-multimap.ts +6 -0
  319. package/src/types/data-structures/graph/abstract-graph.ts +11 -0
  320. package/src/types/data-structures/graph/directed-graph.ts +8 -0
  321. package/src/types/data-structures/graph/index.ts +3 -0
  322. package/src/types/data-structures/graph/map-graph.ts +1 -0
  323. package/src/types/data-structures/graph/undirected-graph.ts +1 -0
  324. package/src/types/data-structures/hash/coordinate-map.ts +1 -0
  325. package/src/types/data-structures/hash/coordinate-set.ts +1 -0
  326. package/src/types/data-structures/hash/hash-map.ts +1 -0
  327. package/src/types/data-structures/hash/hash-table.ts +1 -0
  328. package/src/types/data-structures/hash/index.ts +1 -0
  329. package/src/types/data-structures/hash/tree-map.ts +1 -0
  330. package/src/types/data-structures/hash/tree-set.ts +1 -0
  331. package/src/types/data-structures/heap/heap.ts +1 -0
  332. package/src/types/data-structures/heap/index.ts +1 -0
  333. package/src/types/data-structures/heap/max-heap.ts +1 -0
  334. package/src/types/data-structures/heap/min-heap.ts +1 -0
  335. package/src/types/data-structures/index.ts +11 -0
  336. package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -0
  337. package/src/types/data-structures/linked-list/index.ts +2 -0
  338. package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -0
  339. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
  340. package/src/types/data-structures/matrix/index.ts +1 -0
  341. package/src/types/data-structures/matrix/matrix.ts +1 -0
  342. package/src/types/data-structures/matrix/matrix2d.ts +1 -0
  343. package/src/types/data-structures/matrix/navigator.ts +14 -0
  344. package/src/types/data-structures/matrix/vector2d.ts +1 -0
  345. package/src/types/data-structures/priority-queue/index.ts +3 -0
  346. package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
  347. package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
  348. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  349. package/src/types/data-structures/queue/deque.ts +1 -0
  350. package/src/types/data-structures/queue/index.ts +2 -0
  351. package/src/types/data-structures/queue/queue.ts +1 -0
  352. package/src/types/data-structures/stack/index.ts +1 -0
  353. package/src/types/data-structures/stack/stack.ts +1 -0
  354. package/src/types/data-structures/tree/index.ts +1 -0
  355. package/src/types/data-structures/tree/tree.ts +1 -0
  356. package/src/types/data-structures/trie/index.ts +1 -0
  357. package/src/types/data-structures/trie/trie.ts +1 -0
  358. package/src/types/helpers.ts +11 -0
  359. package/src/types/index.ts +3 -0
  360. package/src/types/utils/index.ts +2 -0
  361. package/src/types/utils/utils.ts +6 -0
  362. package/src/types/utils/validate-type.ts +35 -0
  363. package/src/utils/index.ts +1 -0
  364. package/src/utils/utils.ts +86 -0
  365. package/test/index.test.ts +461 -0
  366. package/tsconfig.json +38 -0
@@ -0,0 +1,381 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type {BTNKey, TreeMultimapNodeNested, TreeMultimapOptions} from '../../types';
9
+ import {BinaryTreeDeletedResult, BTNCallback, CP, FamilyPosition, IterationType} from '../../types';
10
+ import {IBinaryTree} from '../../interfaces';
11
+ import {AVLTree, AVLTreeNode} from './avl-tree';
12
+
13
+ export class TreeMultimapNode<
14
+ V = any,
15
+ N extends TreeMultimapNode<V, N> = TreeMultimapNodeNested<V>
16
+ > extends AVLTreeNode<V, N> {
17
+ count: number;
18
+
19
+ /**
20
+ * The constructor function initializes a BinaryTreeNode object with a key, value, and count.
21
+ * @param {BTNKey} key - The `key` parameter is of type `BTNKey` and represents the unique identifier
22
+ * of the binary tree node.
23
+ * @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the value of the binary
24
+ * tree node. If no value is provided, it will be `undefined`.
25
+ * @param {number} [count=1] - The `count` parameter is a number that represents the number of times a particular value
26
+ * occurs in a binary tree node. It has a default value of 1, which means that if no value is provided for the `count`
27
+ * parameter when creating a new instance of the `BinaryTreeNode` class.
28
+ */
29
+ constructor(key: BTNKey, value?: V, count = 1) {
30
+ super(key, value);
31
+ this.count = count;
32
+ }
33
+ }
34
+
35
+ /**
36
+ * The only distinction between a TreeMultimap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
37
+ */
38
+ export class TreeMultimap<V = any, N extends TreeMultimapNode<V, N> = TreeMultimapNode<V, TreeMultimapNodeNested<V>>>
39
+ extends AVLTree<V, N>
40
+ implements IBinaryTree<V, N>
41
+ {
42
+ /**
43
+ * The constructor function for a TreeMultimap class in TypeScript, which extends another class and sets an option to
44
+ * merge duplicated values.
45
+ * @param {TreeMultimapOptions} [options] - An optional object that contains additional configuration options for the
46
+ * TreeMultimap.
47
+ */
48
+ constructor(options?: TreeMultimapOptions) {
49
+ super(options);
50
+ }
51
+
52
+ private _count = 0;
53
+
54
+ get count(): number {
55
+ return this._count;
56
+ }
57
+
58
+ /**
59
+ * The function creates a new BSTNode with the given key, value, and count.
60
+ * @param {BTNKey} key - The key parameter is the unique identifier for the binary tree node. It is used to
61
+ * distinguish one node from another in the tree.
62
+ * @param {N} value - The `value` parameter represents the value that will be stored in the binary search tree node.
63
+ * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
64
+ * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
65
+ * @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
66
+ */
67
+ override createNode(key: BTNKey, value?: V, count?: number): N {
68
+ return new TreeMultimapNode(key, value, count) as N;
69
+ }
70
+
71
+ /**
72
+ * The `add` function adds a new node to a binary search tree, updating the count if the key already
73
+ * exists, and balancing the tree if necessary.
74
+ * @param {BTNKey | N | undefined} keyOrNode - The `keyOrNode` parameter can be either a
75
+ * `BTNKey` (which represents the key of the node to be added), a `N` (which represents a
76
+ * node to be added), or `undefined` (which represents a undefined node).
77
+ * @param [value] - The `value` parameter represents the value associated with the key that is being
78
+ * added to the binary tree.
79
+ * @param [count=1] - The `count` parameter represents the number of occurrences of the key/value
80
+ * pair that will be added to the binary tree. It has a default value of 1, which means that if no
81
+ * count is specified, the default count will be 1.
82
+ * @returns The function `add` returns a value of type `N | undefined | undefined`.
83
+ */
84
+ override add(keyOrNode: BTNKey | N | null | undefined, value?: V, count = 1): N | undefined {
85
+ if(keyOrNode === null) return undefined;
86
+ let inserted: N | undefined = undefined,
87
+ newNode: N | undefined;
88
+ if (keyOrNode instanceof TreeMultimapNode) {
89
+ newNode = this.createNode(keyOrNode.key, keyOrNode.value, keyOrNode.count);
90
+ } else if (keyOrNode === undefined) {
91
+ newNode = undefined;
92
+ } else {
93
+ newNode = this.createNode(keyOrNode, value, count);
94
+ }
95
+ if (!this.root) {
96
+ this._setRoot(newNode);
97
+ this._size = this.size + 1;
98
+ newNode && this._setCount(this.count + newNode.count);
99
+ inserted = this.root;
100
+ } else {
101
+ let cur = this.root;
102
+ let traversing = true;
103
+ while (traversing) {
104
+ if (cur) {
105
+ if (newNode) {
106
+ if (this._compare(cur.key, newNode.key) === CP.eq) {
107
+ cur.value = newNode.value;
108
+ cur.count += newNode.count;
109
+ this._setCount(this.count + newNode.count);
110
+ traversing = false;
111
+ inserted = cur;
112
+ } else if (this._compare(cur.key, newNode.key) === CP.gt) {
113
+ // Traverse left of the node
114
+ if (cur.left === undefined) {
115
+ //Add to the left of the current node
116
+ cur.left = newNode;
117
+ this._size = this.size + 1;
118
+ this._setCount(this.count + newNode.count);
119
+
120
+ traversing = false;
121
+ inserted = cur.left;
122
+ } else {
123
+ //Traverse the left of the current node
124
+ if (cur.left) cur = cur.left;
125
+ }
126
+ } else if (this._compare(cur.key, newNode.key) === CP.lt) {
127
+ // Traverse right of the node
128
+ if (cur.right === undefined) {
129
+ //Add to the right of the current node
130
+ cur.right = newNode;
131
+ this._size = this.size + 1;
132
+ this._setCount(this.count + newNode.count);
133
+
134
+ traversing = false;
135
+ inserted = cur.right;
136
+ } else {
137
+ //Traverse the left of the current node
138
+ if (cur.right) cur = cur.right;
139
+ }
140
+ }
141
+ } else {
142
+ // TODO may need to support undefined inserted
143
+ }
144
+ } else {
145
+ traversing = false;
146
+ }
147
+ }
148
+ }
149
+ if (inserted) this._balancePath(inserted);
150
+ return inserted;
151
+ }
152
+
153
+ /**
154
+ * The function adds a new node to a binary tree if there is an available slot in the parent node.
155
+ * @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be added to
156
+ * the tree. It can be either a node object (`N`) or `undefined`.
157
+ * @param {N} parent - The `parent` parameter represents the parent node to which the new node will
158
+ * be added as a child.
159
+ * @returns The method `_addTo` returns either the `parent.left`, `parent.right`, or `undefined`.
160
+ */
161
+ override _addTo(newNode: N | undefined, parent: N): N | undefined {
162
+ if (parent) {
163
+ if (parent.left === undefined) {
164
+ parent.left = newNode;
165
+ if (newNode !== undefined) {
166
+ this._size = this.size + 1;
167
+ this._setCount(this.count + newNode.count);
168
+ }
169
+
170
+ return parent.left;
171
+ } else if (parent.right === undefined) {
172
+ parent.right = newNode;
173
+ if (newNode !== undefined) {
174
+ this._size = this.size + 1;
175
+ this._setCount(this.count + newNode.count);
176
+ }
177
+ return parent.right;
178
+ } else {
179
+ return;
180
+ }
181
+ } else {
182
+ return;
183
+ }
184
+ }
185
+
186
+ /**
187
+ * The `addMany` function adds multiple keys or nodes to a TreeMultimap and returns an array of the
188
+ * inserted nodes.
189
+ * @param {(BTNKey | undefined)[] | (N | undefined)[]} keysOrNodes - An array of keys or nodes to be
190
+ * added to the multiset. Each element can be either a BTNKey or a TreeMultimapNode.
191
+ * @param {V[]} [data] - The `data` parameter is an optional array of values that correspond
192
+ * to the keys or nodes being added to the multiset. It is used to associate additional data with
193
+ * each key or node.
194
+ * @returns The function `addMany` returns an array of `N`, `undefined`, or `undefined` values.
195
+ */
196
+ override addMany(keysOrNodes: (BTNKey | undefined)[] | (N | undefined)[], data?: V[]): (N | undefined)[] {
197
+ const inserted: (N | undefined | undefined)[] = [];
198
+
199
+ for (let i = 0; i < keysOrNodes.length; i++) {
200
+ const keyOrNode = keysOrNodes[i];
201
+
202
+ if (keyOrNode instanceof TreeMultimapNode) {
203
+ inserted.push(this.add(keyOrNode.key, keyOrNode.value, keyOrNode.count));
204
+ continue;
205
+ }
206
+
207
+ if (keyOrNode === undefined) {
208
+ inserted.push(this.add(NaN, undefined, 0));
209
+ continue;
210
+ }
211
+
212
+ inserted.push(this.add(keyOrNode, data?.[i], 1));
213
+ }
214
+ return inserted;
215
+ }
216
+
217
+ /**
218
+ * The `perfectlyBalance` function in TypeScript takes a sorted array of nodes and builds a balanced
219
+ * binary search tree using either a recursive or iterative approach.
220
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
221
+ * type of iteration to use when building a balanced binary search tree. It can have two possible
222
+ * values:
223
+ * @returns a boolean value.
224
+ */
225
+ override perfectlyBalance(iterationType = this.iterationType): boolean {
226
+ const sorted = this.dfs(node => node, 'in'),
227
+ n = sorted.length;
228
+ if (sorted.length < 1) return false;
229
+
230
+ this.clear();
231
+
232
+ if (iterationType === IterationType.RECURSIVE) {
233
+ const buildBalanceBST = (l: number, r: number) => {
234
+ if (l > r) return;
235
+ const m = l + Math.floor((r - l) / 2);
236
+ const midNode = sorted[m];
237
+ this.add(midNode.key, midNode.value, midNode.count);
238
+ buildBalanceBST(l, m - 1);
239
+ buildBalanceBST(m + 1, r);
240
+ };
241
+
242
+ buildBalanceBST(0, n - 1);
243
+ return true;
244
+ } else {
245
+ const stack: [[number, number]] = [[0, n - 1]];
246
+ while (stack.length > 0) {
247
+ const popped = stack.pop();
248
+ if (popped) {
249
+ const [l, r] = popped;
250
+ if (l <= r) {
251
+ const m = l + Math.floor((r - l) / 2);
252
+ const midNode = sorted[m];
253
+ this.add(midNode.key, midNode.value, midNode.count);
254
+ stack.push([m + 1, r]);
255
+ stack.push([l, m - 1]);
256
+ }
257
+ }
258
+ }
259
+ return true;
260
+ }
261
+ }
262
+
263
+ /**
264
+ * The `delete` function in a binary search tree deletes a node from the tree and returns the deleted
265
+ * node along with the parent node that needs to be balanced.
266
+ * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
267
+ * `BTNKey` or a generic type `N`. It represents the property of the node that we are
268
+ * searching for. It can be a specific key value or any other property of the node.
269
+ * @param callback - The `callback` parameter is a function that takes a node as input and returns a
270
+ * value. This value is compared with the `identifier` parameter to determine if the node should be
271
+ * included in the result. The `callback` parameter has a default value of
272
+ * `this.defaultOneParamCallback`
273
+ * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
274
+ * being deleted. If set to true, the count of the node will not be considered and the node will be
275
+ * deleted regardless of its count. If set to false (default), the count of the node will be
276
+ * decremented by 1 and
277
+ * @returns The method `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
278
+ */
279
+ override delete<C extends BTNCallback<N>>(
280
+ identifier: ReturnType<C>,
281
+ callback: C = this.defaultOneParamCallback as C,
282
+ ignoreCount = false
283
+ ): BinaryTreeDeletedResult<N>[] {
284
+ const bstDeletedResult: BinaryTreeDeletedResult<N>[] = [];
285
+ if (!this.root) return bstDeletedResult;
286
+
287
+ const curr: N | undefined = this.getNode(identifier, callback) ?? undefined;
288
+ if (!curr) return bstDeletedResult;
289
+
290
+ const parent: N | undefined = curr?.parent ? curr.parent : undefined;
291
+ let needBalanced: N | undefined = undefined,
292
+ orgCurrent = curr;
293
+
294
+ if (curr.count > 1 && !ignoreCount) {
295
+ curr.count--;
296
+ this._setCount(this.count - 1);
297
+ } else {
298
+ if (!curr.left) {
299
+ if (!parent) {
300
+ if (curr.right !== undefined) this._setRoot(curr.right);
301
+ } else {
302
+ const {familyPosition: fp} = curr;
303
+ if (fp === FamilyPosition.LEFT || fp === FamilyPosition.ROOT_LEFT) {
304
+ parent.left = curr.right;
305
+ } else if (fp === FamilyPosition.RIGHT || fp === FamilyPosition.ROOT_RIGHT) {
306
+ parent.right = curr.right;
307
+ }
308
+ needBalanced = parent;
309
+ }
310
+ } else {
311
+ const leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : undefined;
312
+ if (leftSubTreeRightMost) {
313
+ const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
314
+ orgCurrent = this._swap(curr, leftSubTreeRightMost);
315
+ if (parentOfLeftSubTreeMax) {
316
+ if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) {
317
+ parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
318
+ } else {
319
+ parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
320
+ }
321
+ needBalanced = parentOfLeftSubTreeMax;
322
+ }
323
+ }
324
+ }
325
+ this._size = this.size - 1;
326
+ // TODO How to handle when the count of target node is lesser than current node's count
327
+ this._setCount(this.count - orgCurrent.count);
328
+ }
329
+
330
+ bstDeletedResult.push({deleted: orgCurrent, needBalanced});
331
+
332
+ if (needBalanced) {
333
+ this._balancePath(needBalanced);
334
+ }
335
+
336
+ return bstDeletedResult;
337
+ }
338
+
339
+ /**
340
+ * The clear() function clears the contents of a data structure and sets the count to zero.
341
+ */
342
+ clear() {
343
+ super.clear();
344
+ this._setCount(0);
345
+ }
346
+
347
+ /**
348
+ * The function swaps the values of two nodes in a binary tree.
349
+ * @param {N} srcNode - The source node that needs to be swapped with the destination node.
350
+ * @param {N} destNode - The `destNode` parameter represents the destination node where the values
351
+ * from `srcNode` will be swapped into.
352
+ * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
353
+ */
354
+ protected override _swap(srcNode: N, destNode: N): N {
355
+ const {key, value, count, height} = destNode;
356
+ const tempNode = this.createNode(key, value, count);
357
+ if (tempNode) {
358
+ tempNode.height = height;
359
+
360
+ destNode.key = srcNode.key;
361
+ destNode.value = srcNode.value;
362
+ destNode.count = srcNode.count;
363
+ destNode.height = srcNode.height;
364
+
365
+ srcNode.key = tempNode.key;
366
+ srcNode.value = tempNode.value;
367
+ srcNode.count = tempNode.count;
368
+ srcNode.height = tempNode.height;
369
+ }
370
+
371
+ return destNode;
372
+ }
373
+
374
+ /**
375
+ * The function sets the value of the "_count" property.
376
+ * @param {number} v - number
377
+ */
378
+ protected _setCount(v: number) {
379
+ this._count = v;
380
+ }
381
+ }