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,126 @@
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, IterationType } from '../../types';
10
+ import { IBinaryTree } from '../../interfaces';
11
+ import { AVLTree, AVLTreeNode } from './avl-tree';
12
+ export declare class TreeMultimapNode<V = any, N extends TreeMultimapNode<V, N> = TreeMultimapNodeNested<V>> extends AVLTreeNode<V, N> {
13
+ count: number;
14
+ /**
15
+ * The constructor function initializes a BinaryTreeNode object with a key, value, and count.
16
+ * @param {BTNKey} key - The `key` parameter is of type `BTNKey` and represents the unique identifier
17
+ * of the binary tree node.
18
+ * @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the value of the binary
19
+ * tree node. If no value is provided, it will be `undefined`.
20
+ * @param {number} [count=1] - The `count` parameter is a number that represents the number of times a particular value
21
+ * occurs in a binary tree node. It has a default value of 1, which means that if no value is provided for the `count`
22
+ * parameter when creating a new instance of the `BinaryTreeNode` class.
23
+ */
24
+ constructor(key: BTNKey, value?: V, count?: number);
25
+ }
26
+ /**
27
+ * 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.
28
+ */
29
+ export declare class TreeMultimap<V = any, N extends TreeMultimapNode<V, N> = TreeMultimapNode<V, TreeMultimapNodeNested<V>>> extends AVLTree<V, N> implements IBinaryTree<V, N> {
30
+ /**
31
+ * The constructor function for a TreeMultimap class in TypeScript, which extends another class and sets an option to
32
+ * merge duplicated values.
33
+ * @param {TreeMultimapOptions} [options] - An optional object that contains additional configuration options for the
34
+ * TreeMultimap.
35
+ */
36
+ constructor(options?: TreeMultimapOptions);
37
+ private _count;
38
+ get count(): number;
39
+ /**
40
+ * The function creates a new BSTNode with the given key, value, and count.
41
+ * @param {BTNKey} key - The key parameter is the unique identifier for the binary tree node. It is used to
42
+ * distinguish one node from another in the tree.
43
+ * @param {N} value - The `value` parameter represents the value that will be stored in the binary search tree node.
44
+ * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
45
+ * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
46
+ * @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
47
+ */
48
+ createNode(key: BTNKey, value?: V, count?: number): N;
49
+ /**
50
+ * The `add` function adds a new node to a binary search tree, updating the count if the key already
51
+ * exists, and balancing the tree if necessary.
52
+ * @param {BTNKey | N | undefined} keyOrNode - The `keyOrNode` parameter can be either a
53
+ * `BTNKey` (which represents the key of the node to be added), a `N` (which represents a
54
+ * node to be added), or `undefined` (which represents a undefined node).
55
+ * @param [value] - The `value` parameter represents the value associated with the key that is being
56
+ * added to the binary tree.
57
+ * @param [count=1] - The `count` parameter represents the number of occurrences of the key/value
58
+ * pair that will be added to the binary tree. It has a default value of 1, which means that if no
59
+ * count is specified, the default count will be 1.
60
+ * @returns The function `add` returns a value of type `N | undefined | undefined`.
61
+ */
62
+ add(keyOrNode: BTNKey | N | null | undefined, value?: V, count?: number): N | undefined;
63
+ /**
64
+ * The function adds a new node to a binary tree if there is an available slot in the parent node.
65
+ * @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be added to
66
+ * the tree. It can be either a node object (`N`) or `undefined`.
67
+ * @param {N} parent - The `parent` parameter represents the parent node to which the new node will
68
+ * be added as a child.
69
+ * @returns The method `_addTo` returns either the `parent.left`, `parent.right`, or `undefined`.
70
+ */
71
+ _addTo(newNode: N | undefined, parent: N): N | undefined;
72
+ /**
73
+ * The `addMany` function adds multiple keys or nodes to a TreeMultimap and returns an array of the
74
+ * inserted nodes.
75
+ * @param {(BTNKey | undefined)[] | (N | undefined)[]} keysOrNodes - An array of keys or nodes to be
76
+ * added to the multiset. Each element can be either a BTNKey or a TreeMultimapNode.
77
+ * @param {V[]} [data] - The `data` parameter is an optional array of values that correspond
78
+ * to the keys or nodes being added to the multiset. It is used to associate additional data with
79
+ * each key or node.
80
+ * @returns The function `addMany` returns an array of `N`, `undefined`, or `undefined` values.
81
+ */
82
+ addMany(keysOrNodes: (BTNKey | undefined)[] | (N | undefined)[], data?: V[]): (N | undefined)[];
83
+ /**
84
+ * The `perfectlyBalance` function in TypeScript takes a sorted array of nodes and builds a balanced
85
+ * binary search tree using either a recursive or iterative approach.
86
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
87
+ * type of iteration to use when building a balanced binary search tree. It can have two possible
88
+ * values:
89
+ * @returns a boolean value.
90
+ */
91
+ perfectlyBalance(iterationType?: IterationType): boolean;
92
+ /**
93
+ * The `delete` function in a binary search tree deletes a node from the tree and returns the deleted
94
+ * node along with the parent node that needs to be balanced.
95
+ * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
96
+ * `BTNKey` or a generic type `N`. It represents the property of the node that we are
97
+ * searching for. It can be a specific key value or any other property of the node.
98
+ * @param callback - The `callback` parameter is a function that takes a node as input and returns a
99
+ * value. This value is compared with the `identifier` parameter to determine if the node should be
100
+ * included in the result. The `callback` parameter has a default value of
101
+ * `this.defaultOneParamCallback`
102
+ * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
103
+ * being deleted. If set to true, the count of the node will not be considered and the node will be
104
+ * deleted regardless of its count. If set to false (default), the count of the node will be
105
+ * decremented by 1 and
106
+ * @returns The method `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
107
+ */
108
+ delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
109
+ /**
110
+ * The clear() function clears the contents of a data structure and sets the count to zero.
111
+ */
112
+ clear(): void;
113
+ /**
114
+ * The function swaps the values of two nodes in a binary tree.
115
+ * @param {N} srcNode - The source node that needs to be swapped with the destination node.
116
+ * @param {N} destNode - The `destNode` parameter represents the destination node where the values
117
+ * from `srcNode` will be swapped into.
118
+ * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
119
+ */
120
+ protected _swap(srcNode: N, destNode: N): N;
121
+ /**
122
+ * The function sets the value of the "_count" property.
123
+ * @param {number} v - number
124
+ */
125
+ protected _setCount(v: number): void;
126
+ }
@@ -0,0 +1,358 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TreeMultimap = exports.TreeMultimapNode = void 0;
4
+ const types_1 = require("../../types");
5
+ const avl_tree_1 = require("./avl-tree");
6
+ class TreeMultimapNode extends avl_tree_1.AVLTreeNode {
7
+ /**
8
+ * The constructor function initializes a BinaryTreeNode object with a key, value, and count.
9
+ * @param {BTNKey} key - The `key` parameter is of type `BTNKey` and represents the unique identifier
10
+ * of the binary tree node.
11
+ * @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the value of the binary
12
+ * tree node. If no value is provided, it will be `undefined`.
13
+ * @param {number} [count=1] - The `count` parameter is a number that represents the number of times a particular value
14
+ * occurs in a binary tree node. It has a default value of 1, which means that if no value is provided for the `count`
15
+ * parameter when creating a new instance of the `BinaryTreeNode` class.
16
+ */
17
+ constructor(key, value, count = 1) {
18
+ super(key, value);
19
+ this.count = count;
20
+ }
21
+ }
22
+ exports.TreeMultimapNode = TreeMultimapNode;
23
+ /**
24
+ * 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.
25
+ */
26
+ class TreeMultimap extends avl_tree_1.AVLTree {
27
+ /**
28
+ * The constructor function for a TreeMultimap class in TypeScript, which extends another class and sets an option to
29
+ * merge duplicated values.
30
+ * @param {TreeMultimapOptions} [options] - An optional object that contains additional configuration options for the
31
+ * TreeMultimap.
32
+ */
33
+ constructor(options) {
34
+ super(options);
35
+ this._count = 0;
36
+ }
37
+ get count() {
38
+ return this._count;
39
+ }
40
+ /**
41
+ * The function creates a new BSTNode with the given key, value, and count.
42
+ * @param {BTNKey} key - The key parameter is the unique identifier for the binary tree node. It is used to
43
+ * distinguish one node from another in the tree.
44
+ * @param {N} value - The `value` parameter represents the value that will be stored in the binary search tree node.
45
+ * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
46
+ * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
47
+ * @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
48
+ */
49
+ createNode(key, value, count) {
50
+ return new TreeMultimapNode(key, value, count);
51
+ }
52
+ /**
53
+ * The `add` function adds a new node to a binary search tree, updating the count if the key already
54
+ * exists, and balancing the tree if necessary.
55
+ * @param {BTNKey | N | undefined} keyOrNode - The `keyOrNode` parameter can be either a
56
+ * `BTNKey` (which represents the key of the node to be added), a `N` (which represents a
57
+ * node to be added), or `undefined` (which represents a undefined node).
58
+ * @param [value] - The `value` parameter represents the value associated with the key that is being
59
+ * added to the binary tree.
60
+ * @param [count=1] - The `count` parameter represents the number of occurrences of the key/value
61
+ * pair that will be added to the binary tree. It has a default value of 1, which means that if no
62
+ * count is specified, the default count will be 1.
63
+ * @returns The function `add` returns a value of type `N | undefined | undefined`.
64
+ */
65
+ add(keyOrNode, value, count = 1) {
66
+ if (keyOrNode === null)
67
+ return undefined;
68
+ let inserted = undefined, newNode;
69
+ if (keyOrNode instanceof TreeMultimapNode) {
70
+ newNode = this.createNode(keyOrNode.key, keyOrNode.value, keyOrNode.count);
71
+ }
72
+ else if (keyOrNode === undefined) {
73
+ newNode = undefined;
74
+ }
75
+ else {
76
+ newNode = this.createNode(keyOrNode, value, count);
77
+ }
78
+ if (!this.root) {
79
+ this._setRoot(newNode);
80
+ this._size = this.size + 1;
81
+ newNode && this._setCount(this.count + newNode.count);
82
+ inserted = this.root;
83
+ }
84
+ else {
85
+ let cur = this.root;
86
+ let traversing = true;
87
+ while (traversing) {
88
+ if (cur) {
89
+ if (newNode) {
90
+ if (this._compare(cur.key, newNode.key) === types_1.CP.eq) {
91
+ cur.value = newNode.value;
92
+ cur.count += newNode.count;
93
+ this._setCount(this.count + newNode.count);
94
+ traversing = false;
95
+ inserted = cur;
96
+ }
97
+ else if (this._compare(cur.key, newNode.key) === types_1.CP.gt) {
98
+ // Traverse left of the node
99
+ if (cur.left === undefined) {
100
+ //Add to the left of the current node
101
+ cur.left = newNode;
102
+ this._size = this.size + 1;
103
+ this._setCount(this.count + newNode.count);
104
+ traversing = false;
105
+ inserted = cur.left;
106
+ }
107
+ else {
108
+ //Traverse the left of the current node
109
+ if (cur.left)
110
+ cur = cur.left;
111
+ }
112
+ }
113
+ else if (this._compare(cur.key, newNode.key) === types_1.CP.lt) {
114
+ // Traverse right of the node
115
+ if (cur.right === undefined) {
116
+ //Add to the right of the current node
117
+ cur.right = newNode;
118
+ this._size = this.size + 1;
119
+ this._setCount(this.count + newNode.count);
120
+ traversing = false;
121
+ inserted = cur.right;
122
+ }
123
+ else {
124
+ //Traverse the left of the current node
125
+ if (cur.right)
126
+ cur = cur.right;
127
+ }
128
+ }
129
+ }
130
+ else {
131
+ // TODO may need to support undefined inserted
132
+ }
133
+ }
134
+ else {
135
+ traversing = false;
136
+ }
137
+ }
138
+ }
139
+ if (inserted)
140
+ this._balancePath(inserted);
141
+ return inserted;
142
+ }
143
+ /**
144
+ * The function adds a new node to a binary tree if there is an available slot in the parent node.
145
+ * @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be added to
146
+ * the tree. It can be either a node object (`N`) or `undefined`.
147
+ * @param {N} parent - The `parent` parameter represents the parent node to which the new node will
148
+ * be added as a child.
149
+ * @returns The method `_addTo` returns either the `parent.left`, `parent.right`, or `undefined`.
150
+ */
151
+ _addTo(newNode, parent) {
152
+ if (parent) {
153
+ if (parent.left === undefined) {
154
+ parent.left = newNode;
155
+ if (newNode !== undefined) {
156
+ this._size = this.size + 1;
157
+ this._setCount(this.count + newNode.count);
158
+ }
159
+ return parent.left;
160
+ }
161
+ else if (parent.right === undefined) {
162
+ parent.right = newNode;
163
+ if (newNode !== undefined) {
164
+ this._size = this.size + 1;
165
+ this._setCount(this.count + newNode.count);
166
+ }
167
+ return parent.right;
168
+ }
169
+ else {
170
+ return;
171
+ }
172
+ }
173
+ else {
174
+ return;
175
+ }
176
+ }
177
+ /**
178
+ * The `addMany` function adds multiple keys or nodes to a TreeMultimap and returns an array of the
179
+ * inserted nodes.
180
+ * @param {(BTNKey | undefined)[] | (N | undefined)[]} keysOrNodes - An array of keys or nodes to be
181
+ * added to the multiset. Each element can be either a BTNKey or a TreeMultimapNode.
182
+ * @param {V[]} [data] - The `data` parameter is an optional array of values that correspond
183
+ * to the keys or nodes being added to the multiset. It is used to associate additional data with
184
+ * each key or node.
185
+ * @returns The function `addMany` returns an array of `N`, `undefined`, or `undefined` values.
186
+ */
187
+ addMany(keysOrNodes, data) {
188
+ const inserted = [];
189
+ for (let i = 0; i < keysOrNodes.length; i++) {
190
+ const keyOrNode = keysOrNodes[i];
191
+ if (keyOrNode instanceof TreeMultimapNode) {
192
+ inserted.push(this.add(keyOrNode.key, keyOrNode.value, keyOrNode.count));
193
+ continue;
194
+ }
195
+ if (keyOrNode === undefined) {
196
+ inserted.push(this.add(NaN, undefined, 0));
197
+ continue;
198
+ }
199
+ inserted.push(this.add(keyOrNode, data === null || data === void 0 ? void 0 : data[i], 1));
200
+ }
201
+ return inserted;
202
+ }
203
+ /**
204
+ * The `perfectlyBalance` function in TypeScript takes a sorted array of nodes and builds a balanced
205
+ * binary search tree using either a recursive or iterative approach.
206
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
207
+ * type of iteration to use when building a balanced binary search tree. It can have two possible
208
+ * values:
209
+ * @returns a boolean value.
210
+ */
211
+ perfectlyBalance(iterationType = this.iterationType) {
212
+ const sorted = this.dfs(node => node, 'in'), n = sorted.length;
213
+ if (sorted.length < 1)
214
+ return false;
215
+ this.clear();
216
+ if (iterationType === types_1.IterationType.RECURSIVE) {
217
+ const buildBalanceBST = (l, r) => {
218
+ if (l > r)
219
+ return;
220
+ const m = l + Math.floor((r - l) / 2);
221
+ const midNode = sorted[m];
222
+ this.add(midNode.key, midNode.value, midNode.count);
223
+ buildBalanceBST(l, m - 1);
224
+ buildBalanceBST(m + 1, r);
225
+ };
226
+ buildBalanceBST(0, n - 1);
227
+ return true;
228
+ }
229
+ else {
230
+ const stack = [[0, n - 1]];
231
+ while (stack.length > 0) {
232
+ const popped = stack.pop();
233
+ if (popped) {
234
+ const [l, r] = popped;
235
+ if (l <= r) {
236
+ const m = l + Math.floor((r - l) / 2);
237
+ const midNode = sorted[m];
238
+ this.add(midNode.key, midNode.value, midNode.count);
239
+ stack.push([m + 1, r]);
240
+ stack.push([l, m - 1]);
241
+ }
242
+ }
243
+ }
244
+ return true;
245
+ }
246
+ }
247
+ /**
248
+ * The `delete` function in a binary search tree deletes a node from the tree and returns the deleted
249
+ * node along with the parent node that needs to be balanced.
250
+ * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
251
+ * `BTNKey` or a generic type `N`. It represents the property of the node that we are
252
+ * searching for. It can be a specific key value or any other property of the node.
253
+ * @param callback - The `callback` parameter is a function that takes a node as input and returns a
254
+ * value. This value is compared with the `identifier` parameter to determine if the node should be
255
+ * included in the result. The `callback` parameter has a default value of
256
+ * `this.defaultOneParamCallback`
257
+ * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
258
+ * being deleted. If set to true, the count of the node will not be considered and the node will be
259
+ * deleted regardless of its count. If set to false (default), the count of the node will be
260
+ * decremented by 1 and
261
+ * @returns The method `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
262
+ */
263
+ delete(identifier, callback = this.defaultOneParamCallback, ignoreCount = false) {
264
+ var _a;
265
+ const bstDeletedResult = [];
266
+ if (!this.root)
267
+ return bstDeletedResult;
268
+ const curr = (_a = this.getNode(identifier, callback)) !== null && _a !== void 0 ? _a : undefined;
269
+ if (!curr)
270
+ return bstDeletedResult;
271
+ const parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : undefined;
272
+ let needBalanced = undefined, orgCurrent = curr;
273
+ if (curr.count > 1 && !ignoreCount) {
274
+ curr.count--;
275
+ this._setCount(this.count - 1);
276
+ }
277
+ else {
278
+ if (!curr.left) {
279
+ if (!parent) {
280
+ if (curr.right !== undefined)
281
+ this._setRoot(curr.right);
282
+ }
283
+ else {
284
+ const { familyPosition: fp } = curr;
285
+ if (fp === types_1.FamilyPosition.LEFT || fp === types_1.FamilyPosition.ROOT_LEFT) {
286
+ parent.left = curr.right;
287
+ }
288
+ else if (fp === types_1.FamilyPosition.RIGHT || fp === types_1.FamilyPosition.ROOT_RIGHT) {
289
+ parent.right = curr.right;
290
+ }
291
+ needBalanced = parent;
292
+ }
293
+ }
294
+ else {
295
+ const leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : undefined;
296
+ if (leftSubTreeRightMost) {
297
+ const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
298
+ orgCurrent = this._swap(curr, leftSubTreeRightMost);
299
+ if (parentOfLeftSubTreeMax) {
300
+ if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) {
301
+ parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
302
+ }
303
+ else {
304
+ parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
305
+ }
306
+ needBalanced = parentOfLeftSubTreeMax;
307
+ }
308
+ }
309
+ }
310
+ this._size = this.size - 1;
311
+ // TODO How to handle when the count of target node is lesser than current node's count
312
+ this._setCount(this.count - orgCurrent.count);
313
+ }
314
+ bstDeletedResult.push({ deleted: orgCurrent, needBalanced });
315
+ if (needBalanced) {
316
+ this._balancePath(needBalanced);
317
+ }
318
+ return bstDeletedResult;
319
+ }
320
+ /**
321
+ * The clear() function clears the contents of a data structure and sets the count to zero.
322
+ */
323
+ clear() {
324
+ super.clear();
325
+ this._setCount(0);
326
+ }
327
+ /**
328
+ * The function swaps the values of two nodes in a binary tree.
329
+ * @param {N} srcNode - The source node that needs to be swapped with the destination node.
330
+ * @param {N} destNode - The `destNode` parameter represents the destination node where the values
331
+ * from `srcNode` will be swapped into.
332
+ * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
333
+ */
334
+ _swap(srcNode, destNode) {
335
+ const { key, value, count, height } = destNode;
336
+ const tempNode = this.createNode(key, value, count);
337
+ if (tempNode) {
338
+ tempNode.height = height;
339
+ destNode.key = srcNode.key;
340
+ destNode.value = srcNode.value;
341
+ destNode.count = srcNode.count;
342
+ destNode.height = srcNode.height;
343
+ srcNode.key = tempNode.key;
344
+ srcNode.value = tempNode.value;
345
+ srcNode.count = tempNode.count;
346
+ srcNode.height = tempNode.height;
347
+ }
348
+ return destNode;
349
+ }
350
+ /**
351
+ * The function sets the value of the "_count" property.
352
+ * @param {number} v - number
353
+ */
354
+ _setCount(v) {
355
+ this._count = v;
356
+ }
357
+ }
358
+ exports.TreeMultimap = TreeMultimap;