data-structure-typed 0.8.18 → 1.3.0

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 (272) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +690 -2
  3. package/dist/bundle.js +2 -0
  4. package/dist/bundle.js.LICENSE.txt +13 -0
  5. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +364 -0
  6. package/dist/data-structures/binary-tree/abstract-binary-tree.js +1308 -0
  7. package/dist/data-structures/binary-tree/avl-tree.d.ts +85 -18
  8. package/dist/data-structures/binary-tree/avl-tree.js +110 -37
  9. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +40 -2
  10. package/dist/data-structures/binary-tree/binary-indexed-tree.js +44 -2
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +29 -138
  12. package/dist/data-structures/binary-tree/binary-tree.js +27 -979
  13. package/dist/data-structures/binary-tree/bst.d.ts +118 -28
  14. package/dist/data-structures/binary-tree/bst.js +162 -124
  15. package/dist/data-structures/binary-tree/index.d.ts +1 -0
  16. package/dist/data-structures/binary-tree/index.js +1 -0
  17. package/dist/data-structures/binary-tree/rb-tree.d.ts +18 -1
  18. package/dist/data-structures/binary-tree/rb-tree.js +40 -2
  19. package/dist/data-structures/binary-tree/segment-tree.d.ts +63 -13
  20. package/dist/data-structures/binary-tree/segment-tree.js +80 -17
  21. package/dist/data-structures/binary-tree/tree-multiset.d.ts +213 -10
  22. package/dist/data-structures/binary-tree/tree-multiset.js +682 -9
  23. package/dist/data-structures/graph/abstract-graph.d.ts +270 -64
  24. package/dist/data-structures/graph/abstract-graph.js +365 -92
  25. package/dist/data-structures/graph/directed-graph.d.ts +175 -26
  26. package/dist/data-structures/graph/directed-graph.js +249 -95
  27. package/dist/data-structures/graph/index.d.ts +1 -0
  28. package/dist/data-structures/graph/index.js +1 -0
  29. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  30. package/dist/data-structures/graph/map-graph.js +111 -0
  31. package/dist/data-structures/graph/undirected-graph.d.ts +111 -8
  32. package/dist/data-structures/graph/undirected-graph.js +154 -44
  33. package/dist/data-structures/hash/coordinate-map.d.ts +39 -2
  34. package/dist/data-structures/hash/coordinate-map.js +44 -3
  35. package/dist/data-structures/hash/coordinate-set.d.ts +32 -2
  36. package/dist/data-structures/hash/coordinate-set.js +34 -0
  37. package/dist/data-structures/hash/hash-table.d.ts +2 -1
  38. package/dist/data-structures/hash/hash-table.js +4 -0
  39. package/dist/data-structures/hash/index.d.ts +5 -0
  40. package/dist/data-structures/hash/index.js +5 -0
  41. package/dist/data-structures/hash/pair.d.ts +2 -1
  42. package/dist/data-structures/hash/pair.js +4 -0
  43. package/dist/data-structures/hash/tree-map.d.ts +2 -1
  44. package/dist/data-structures/hash/tree-map.js +4 -0
  45. package/dist/data-structures/hash/tree-set.d.ts +2 -1
  46. package/dist/data-structures/hash/tree-set.js +4 -0
  47. package/dist/data-structures/heap/heap.d.ts +62 -51
  48. package/dist/data-structures/heap/heap.js +106 -63
  49. package/dist/data-structures/heap/max-heap.d.ts +13 -4
  50. package/dist/data-structures/heap/max-heap.js +10 -2
  51. package/dist/data-structures/heap/min-heap.d.ts +14 -4
  52. package/dist/data-structures/heap/min-heap.js +11 -2
  53. package/dist/data-structures/index.d.ts +1 -0
  54. package/dist/data-structures/index.js +1 -0
  55. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +193 -57
  56. package/dist/data-structures/linked-list/doubly-linked-list.js +461 -194
  57. package/dist/data-structures/linked-list/index.d.ts +1 -0
  58. package/dist/data-structures/linked-list/index.js +1 -0
  59. package/dist/data-structures/linked-list/singly-linked-list.d.ts +117 -319
  60. package/dist/data-structures/linked-list/singly-linked-list.js +338 -557
  61. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -1
  62. package/dist/data-structures/linked-list/skip-linked-list.js +4 -0
  63. package/dist/data-structures/matrix/matrix.d.ts +12 -0
  64. package/dist/data-structures/matrix/matrix.js +14 -0
  65. package/dist/data-structures/matrix/matrix2d.d.ts +87 -4
  66. package/dist/data-structures/matrix/matrix2d.js +91 -8
  67. package/dist/data-structures/matrix/navigator.d.ts +37 -16
  68. package/dist/data-structures/matrix/navigator.js +28 -0
  69. package/dist/data-structures/matrix/vector2d.d.ts +156 -29
  70. package/dist/data-structures/matrix/vector2d.js +184 -55
  71. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -1
  72. package/dist/data-structures/priority-queue/max-priority-queue.js +28 -4
  73. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -1
  74. package/dist/data-structures/priority-queue/min-priority-queue.js +29 -4
  75. package/dist/data-structures/priority-queue/priority-queue.d.ts +166 -22
  76. package/dist/data-structures/priority-queue/priority-queue.js +219 -75
  77. package/dist/data-structures/queue/deque.d.ts +141 -13
  78. package/dist/data-structures/queue/deque.js +151 -7
  79. package/dist/data-structures/queue/queue.d.ts +68 -42
  80. package/dist/data-structures/queue/queue.js +95 -51
  81. package/dist/data-structures/stack/stack.d.ts +30 -36
  82. package/dist/data-structures/stack/stack.js +31 -37
  83. package/dist/data-structures/tree/index.d.ts +1 -0
  84. package/dist/data-structures/tree/index.js +17 -0
  85. package/dist/data-structures/tree/tree.d.ts +14 -0
  86. package/dist/{types/utils.js → data-structures/tree/tree.js} +26 -19
  87. package/dist/data-structures/trie/trie.d.ts +39 -6
  88. package/dist/data-structures/trie/trie.js +81 -12
  89. package/dist/index.d.ts +3 -0
  90. package/dist/index.js +3 -0
  91. package/dist/interfaces/abstract-binary-tree.d.ts +90 -0
  92. package/dist/interfaces/abstract-binary-tree.js +2 -0
  93. package/dist/interfaces/abstract-graph.d.ts +17 -0
  94. package/dist/interfaces/abstract-graph.js +2 -0
  95. package/dist/interfaces/avl-tree.d.ts +9 -0
  96. package/dist/interfaces/avl-tree.js +2 -0
  97. package/dist/interfaces/binary-tree.d.ts +6 -0
  98. package/dist/interfaces/binary-tree.js +2 -0
  99. package/dist/interfaces/bst.d.ts +17 -0
  100. package/dist/interfaces/bst.js +2 -0
  101. package/dist/interfaces/directed-graph.d.ts +12 -0
  102. package/dist/interfaces/directed-graph.js +2 -0
  103. package/dist/interfaces/doubly-linked-list.js +2 -0
  104. package/dist/interfaces/heap.js +2 -0
  105. package/dist/interfaces/index.d.ts +15 -0
  106. package/dist/interfaces/index.js +31 -0
  107. package/dist/interfaces/navigator.js +2 -0
  108. package/dist/interfaces/priority-queue.js +2 -0
  109. package/dist/interfaces/rb-tree.d.ts +8 -0
  110. package/dist/interfaces/rb-tree.js +2 -0
  111. package/dist/interfaces/segment-tree.js +2 -0
  112. package/dist/interfaces/singly-linked-list.js +2 -0
  113. package/dist/interfaces/tree-multiset.d.ts +7 -0
  114. package/dist/interfaces/tree-multiset.js +2 -0
  115. package/dist/interfaces/undirected-graph.d.ts +5 -0
  116. package/dist/interfaces/undirected-graph.js +2 -0
  117. package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
  118. package/dist/types/data-structures/abstract-binary-tree.js +25 -0
  119. package/dist/types/data-structures/abstract-graph.d.ts +11 -0
  120. package/dist/types/data-structures/abstract-graph.js +2 -0
  121. package/dist/types/data-structures/avl-tree.d.ts +4 -0
  122. package/dist/types/data-structures/avl-tree.js +2 -0
  123. package/dist/types/data-structures/binary-tree.d.ts +4 -0
  124. package/dist/types/data-structures/binary-tree.js +2 -0
  125. package/dist/types/data-structures/bst.d.ts +13 -0
  126. package/dist/types/data-structures/bst.js +9 -0
  127. package/dist/types/data-structures/directed-graph.d.ts +6 -0
  128. package/dist/types/data-structures/directed-graph.js +9 -0
  129. package/dist/types/data-structures/doubly-linked-list.js +2 -0
  130. package/dist/types/data-structures/heap.d.ts +3 -0
  131. package/dist/types/data-structures/heap.js +2 -0
  132. package/dist/types/data-structures/index.d.ts +13 -7
  133. package/dist/types/data-structures/index.js +31 -0
  134. package/dist/types/data-structures/map-graph.d.ts +1 -0
  135. package/dist/types/data-structures/map-graph.js +2 -0
  136. package/dist/types/data-structures/navigator.d.ts +14 -0
  137. package/dist/types/data-structures/navigator.js +2 -0
  138. package/dist/types/data-structures/priority-queue.d.ts +7 -0
  139. package/dist/types/data-structures/priority-queue.js +2 -0
  140. package/dist/types/data-structures/rb-tree.d.ts +8 -0
  141. package/dist/types/data-structures/rb-tree.js +8 -0
  142. package/dist/types/data-structures/segment-tree.d.ts +1 -0
  143. package/dist/types/data-structures/segment-tree.js +2 -0
  144. package/dist/types/data-structures/singly-linked-list.js +2 -0
  145. package/dist/types/data-structures/tree-multiset.d.ts +4 -0
  146. package/dist/types/data-structures/tree-multiset.js +2 -0
  147. package/dist/types/helpers.d.ts +1 -0
  148. package/dist/types/helpers.js +2 -0
  149. package/dist/types/index.d.ts +2 -0
  150. package/dist/types/index.js +2 -0
  151. package/dist/types/utils/index.d.ts +2 -0
  152. package/dist/types/utils/index.js +18 -0
  153. package/dist/types/utils/utils.d.ts +7 -0
  154. package/dist/types/utils/utils.js +2 -0
  155. package/dist/types/utils/validate-type.d.ts +19 -0
  156. package/dist/types/utils/validate-type.js +2 -0
  157. package/dist/utils/index.js +17 -0
  158. package/dist/utils/utils.d.ts +19 -0
  159. package/dist/{data-structures/trampoline.js → utils/utils.js} +26 -12
  160. package/package.json +106 -55
  161. package/.idea/data-structure-typed.iml +0 -12
  162. package/.idea/modules.xml +0 -8
  163. package/.idea/vcs.xml +0 -6
  164. package/dist/data-structures/trampoline.d.ts +0 -25
  165. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  166. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  167. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  168. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  169. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  170. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  171. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  172. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  173. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  174. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  175. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  176. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  177. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  178. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  179. package/dist/types/data-structures/graph/index.d.ts +0 -3
  180. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  181. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  182. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  183. package/dist/types/data-structures/hash/index.d.ts +0 -1
  184. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  185. package/dist/types/data-structures/heap/index.d.ts +0 -3
  186. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  187. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  188. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  189. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  190. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  191. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  192. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  193. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  194. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  195. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  196. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  197. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  198. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  199. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  200. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  201. package/dist/types/data-structures/queue/index.d.ts +0 -1
  202. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  203. package/dist/types/data-structures/stack/index.d.ts +0 -1
  204. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  205. package/dist/types/data-structures/trampoline.d.ts +0 -25
  206. package/dist/types/data-structures/trie/index.d.ts +0 -1
  207. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  208. package/dist/types/types/utils.d.ts +0 -46
  209. package/dist/types/utils.d.ts +0 -46
  210. package/dist/utils.d.ts +0 -122
  211. package/dist/utils.js +0 -569
  212. package/src/data-structures/binary-tree/aa-tree.ts +0 -3
  213. package/src/data-structures/binary-tree/avl-tree.ts +0 -232
  214. package/src/data-structures/binary-tree/b-tree.ts +0 -3
  215. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -33
  216. package/src/data-structures/binary-tree/binary-tree.ts +0 -1088
  217. package/src/data-structures/binary-tree/bst.ts +0 -404
  218. package/src/data-structures/binary-tree/index.ts +0 -11
  219. package/src/data-structures/binary-tree/rb-tree.ts +0 -3
  220. package/src/data-structures/binary-tree/segment-tree.ts +0 -164
  221. package/src/data-structures/binary-tree/splay-tree.ts +0 -3
  222. package/src/data-structures/binary-tree/tree-multiset.ts +0 -21
  223. package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  224. package/src/data-structures/graph/abstract-graph.ts +0 -789
  225. package/src/data-structures/graph/directed-graph.ts +0 -322
  226. package/src/data-structures/graph/index.ts +0 -3
  227. package/src/data-structures/graph/undirected-graph.ts +0 -154
  228. package/src/data-structures/hash/coordinate-map.ts +0 -24
  229. package/src/data-structures/hash/coordinate-set.ts +0 -20
  230. package/src/data-structures/hash/hash-table.ts +0 -1
  231. package/src/data-structures/hash/index.ts +0 -1
  232. package/src/data-structures/heap/heap.ts +0 -136
  233. package/src/data-structures/heap/index.ts +0 -3
  234. package/src/data-structures/heap/max-heap.ts +0 -22
  235. package/src/data-structures/heap/min-heap.ts +0 -24
  236. package/src/data-structures/index.ts +0 -11
  237. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -258
  238. package/src/data-structures/linked-list/index.ts +0 -2
  239. package/src/data-structures/linked-list/singly-linked-list.ts +0 -750
  240. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  241. package/src/data-structures/matrix/index.ts +0 -4
  242. package/src/data-structures/matrix/matrix.ts +0 -13
  243. package/src/data-structures/matrix/matrix2d.ts +0 -125
  244. package/src/data-structures/matrix/navigator.ts +0 -99
  245. package/src/data-structures/matrix/vector2d.ts +0 -189
  246. package/src/data-structures/priority-queue/index.ts +0 -3
  247. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -12
  248. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -12
  249. package/src/data-structures/priority-queue/priority-queue.ts +0 -208
  250. package/src/data-structures/queue/deque.ts +0 -139
  251. package/src/data-structures/queue/index.ts +0 -2
  252. package/src/data-structures/queue/queue.ts +0 -123
  253. package/src/data-structures/stack/index.ts +0 -1
  254. package/src/data-structures/stack/stack.ts +0 -104
  255. package/src/data-structures/trampoline.ts +0 -91
  256. package/src/data-structures/trie/index.ts +0 -1
  257. package/src/data-structures/trie/trie.ts +0 -153
  258. package/src/index.ts +0 -1
  259. package/src/types/index.ts +0 -1
  260. package/src/types/patches/index.d.ts +0 -0
  261. package/src/types/utils.ts +0 -158
  262. package/src/utils.ts +0 -605
  263. package/tsconfig.json +0 -53
  264. /package/dist/{types/data-structures/hash/hash-table.d.ts → interfaces/doubly-linked-list.d.ts} +0 -0
  265. /package/dist/{types/data-structures/hash/pair.d.ts → interfaces/heap.d.ts} +0 -0
  266. /package/dist/{types/data-structures/hash/tree-map.d.ts → interfaces/navigator.d.ts} +0 -0
  267. /package/dist/{types/data-structures/hash/tree-set.d.ts → interfaces/priority-queue.d.ts} +0 -0
  268. /package/dist/{types/data-structures/linked-list/skip-linked-list.d.ts → interfaces/segment-tree.d.ts} +0 -0
  269. /package/{src/data-structures/hash/pair.ts → dist/interfaces/singly-linked-list.d.ts} +0 -0
  270. /package/{src/data-structures/hash/tree-map.ts → dist/types/data-structures/doubly-linked-list.d.ts} +0 -0
  271. /package/{src/data-structures/hash/tree-set.ts → dist/types/data-structures/singly-linked-list.d.ts} +0 -0
  272. /package/dist/{types/types → utils}/index.d.ts +0 -0
@@ -1,7 +1,37 @@
1
- export declare class CoordinateSet extends Set {
2
- private readonly _joint;
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
+ export declare class CoordinateSet extends Set<any> {
3
9
  constructor(joint?: string);
10
+ protected _joint: string;
11
+ get joint(): string;
12
+ /**
13
+ * The "has" function overrides the "has" method of the superclass and checks if a value exists in an array after
14
+ * joining its elements with a specified separator.
15
+ * @param {number[]} value - The parameter "value" is an array of numbers.
16
+ * @returns The overridden `has` method is returning the result of calling the `has` method of the superclass, passing
17
+ * in the joined value as an argument.
18
+ */
4
19
  has(value: number[]): boolean;
20
+ /**
21
+ * The "add" function overrides the parent class's "add" function by joining the elements of the input array with a
22
+ * specified delimiter before calling the parent class's "add" function.
23
+ * @param {number[]} value - An array of numbers
24
+ * @returns The overridden `add` method is returning the result of calling the `add` method of the superclass
25
+ * (`super.add`) with the joined string representation of the `value` array (`value.join(this._joint)`).
26
+ */
5
27
  add(value: number[]): this;
28
+ /**
29
+ * The function overrides the delete method and deletes an element from a Set by joining the elements of the input
30
+ * array with a specified joint and then calling the delete method of the parent class.
31
+ * @param {number[]} value - An array of numbers
32
+ * @returns The `delete` method is returning the result of calling the `delete` method of the superclass, with the
33
+ * `value` array joined together using the `_joint` property.
34
+ */
6
35
  delete(value: number[]): boolean;
36
+ protected _setJoint(v: string): void;
7
37
  }
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CoordinateSet = void 0;
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
10
+ */
4
11
  class CoordinateSet extends Set {
5
12
  constructor(joint) {
6
13
  super();
@@ -8,14 +15,41 @@ class CoordinateSet extends Set {
8
15
  if (joint !== undefined)
9
16
  this._joint = joint;
10
17
  }
18
+ get joint() {
19
+ return this._joint;
20
+ }
21
+ /**
22
+ * The "has" function overrides the "has" method of the superclass and checks if a value exists in an array after
23
+ * joining its elements with a specified separator.
24
+ * @param {number[]} value - The parameter "value" is an array of numbers.
25
+ * @returns The overridden `has` method is returning the result of calling the `has` method of the superclass, passing
26
+ * in the joined value as an argument.
27
+ */
11
28
  has(value) {
12
29
  return super.has(value.join(this._joint));
13
30
  }
31
+ /**
32
+ * The "add" function overrides the parent class's "add" function by joining the elements of the input array with a
33
+ * specified delimiter before calling the parent class's "add" function.
34
+ * @param {number[]} value - An array of numbers
35
+ * @returns The overridden `add` method is returning the result of calling the `add` method of the superclass
36
+ * (`super.add`) with the joined string representation of the `value` array (`value.join(this._joint)`).
37
+ */
14
38
  add(value) {
15
39
  return super.add(value.join(this._joint));
16
40
  }
41
+ /**
42
+ * The function overrides the delete method and deletes an element from a Set by joining the elements of the input
43
+ * array with a specified joint and then calling the delete method of the parent class.
44
+ * @param {number[]} value - An array of numbers
45
+ * @returns The `delete` method is returning the result of calling the `delete` method of the superclass, with the
46
+ * `value` array joined together using the `_joint` property.
47
+ */
17
48
  delete(value) {
18
49
  return super.delete(value.join(this._joint));
19
50
  }
51
+ _setJoint(v) {
52
+ this._joint = v;
53
+ }
20
54
  }
21
55
  exports.CoordinateSet = CoordinateSet;
@@ -1 +1,2 @@
1
- export {};
1
+ export declare class HashTable {
2
+ }
@@ -1,2 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HashTable = void 0;
4
+ class HashTable {
5
+ }
6
+ exports.HashTable = HashTable;
@@ -1 +1,6 @@
1
1
  export * from './hash-table';
2
+ export * from './coordinate-map';
3
+ export * from './coordinate-set';
4
+ export * from './pair';
5
+ export * from './tree-map';
6
+ export * from './tree-set';
@@ -15,3 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./hash-table"), exports);
18
+ __exportStar(require("./coordinate-map"), exports);
19
+ __exportStar(require("./coordinate-set"), exports);
20
+ __exportStar(require("./pair"), exports);
21
+ __exportStar(require("./tree-map"), exports);
22
+ __exportStar(require("./tree-set"), exports);
@@ -1 +1,2 @@
1
- export {};
1
+ export declare class Pair {
2
+ }
@@ -1,2 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Pair = void 0;
4
+ class Pair {
5
+ }
6
+ exports.Pair = Pair;
@@ -1 +1,2 @@
1
- export {};
1
+ export declare class TreeMap {
2
+ }
@@ -1,2 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TreeMap = void 0;
4
+ class TreeMap {
5
+ }
6
+ exports.TreeMap = TreeMap;
@@ -1 +1,2 @@
1
- export {};
1
+ export declare class TreeSet {
2
+ }
@@ -1,2 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TreeSet = void 0;
4
+ class TreeSet {
5
+ }
6
+ exports.TreeSet = TreeSet;
@@ -1,72 +1,83 @@
1
- import { PriorityQueue } from '../priority-queue';
2
- export interface HeapOptions<T> {
3
- priority?: (element: T) => number;
4
- }
5
- export interface HeapItem<T> {
6
- priority: number;
7
- element: T | null;
8
- }
9
1
  /**
10
- * @copyright 2021 Pablo Rios <zrwusa@gmail.com>
11
- * @license MIT
2
+ * data-structure-typed
12
3
  *
13
- * @abstract
14
- * @class Heap
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
15
7
  */
16
- export declare abstract class Heap<T> {
17
- protected abstract _pq: PriorityQueue<HeapItem<T>>;
18
- protected _priorityCb: (element: T) => number;
8
+ import { PriorityQueue } from '../priority-queue';
9
+ import type { HeapOptions } from '../../types';
10
+ export declare class HeapItem<T = number> {
11
+ /**
12
+ * The constructor function initializes an instance of a class with a priority and a value.
13
+ * @param {number} priority - The `priority` parameter is a number that represents the priority of the value. It is
14
+ * optional and has a default value of `NaN`.
15
+ * @param {T | null} [val=null] - The `val` parameter is of type `T | null`, which means it can accept a value of type
16
+ * `T` or `null`.
17
+ */
18
+ constructor(priority?: number, val?: T | null);
19
+ private _priority;
20
+ get priority(): number;
21
+ set priority(value: number);
22
+ private _val;
23
+ get val(): T | null;
24
+ set val(value: T | null);
25
+ }
26
+ export declare abstract class Heap<T = number> {
19
27
  /**
20
- * Creates a priority queue
21
- * @public
22
- * @params {object} [options]
28
+ * The function is a constructor for a class that initializes a priority callback function based on the
29
+ * options provided.
30
+ * @param [options] - An optional object that contains configuration options for the Heap.
23
31
  */
24
32
  protected constructor(options?: HeapOptions<T>);
33
+ protected abstract _pq: PriorityQueue<HeapItem<T>>;
34
+ get pq(): PriorityQueue<HeapItem<T>>;
35
+ protected _priorityExtractor: (val: T) => number;
36
+ get priorityExtractor(): (val: T) => number;
25
37
  /**
26
- * @public
27
- * @returns {number}
38
+ * The function returns the size of a priority queue.
39
+ * @returns The size of the priority queue.
28
40
  */
29
41
  get size(): number;
30
42
  /**
31
- * @public
32
- * @returns {boolean}
43
+ * The function checks if a priority queue is empty.
44
+ * @returns {boolean} A boolean value indicating whether the size of the priority queue is less than 1.
33
45
  */
34
46
  isEmpty(): boolean;
47
+ peek(isItem?: undefined): T | undefined;
48
+ peek(isItem: false): T | undefined;
49
+ peek(isItem: true): HeapItem<T> | null;
50
+ peekLast(isItem?: undefined): T | undefined;
51
+ peekLast(isItem: false): T | undefined;
52
+ peekLast(isItem: true): HeapItem<T> | null;
35
53
  /**
36
- * Returns an element with highest priority in the queue
37
- * @public
38
- * @returns {object}
39
- */
40
- peek(): HeapItem<T> | null;
41
- /**
42
- * Returns an element with lowest priority in the queue
43
- * @public
44
- * @returns {object}
45
- */
46
- peekLast(): HeapItem<T> | null;
47
- /**
48
- * Adds an element to the queue
49
- * @public
50
- * @param {any} element
51
- * @param priority
54
+ * The `add` function adds an val to a priority queue with an optional priority value.
55
+ * @param {T} val - The `val` parameter represents the value that you want to add to the heap. It can be of any
56
+ * type.
57
+ * @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the
58
+ * val being added to the heap. If the `val` parameter is a number, then the `priority` parameter is set to
59
+ * the value of `val`. If the `val` parameter is not a number, then the
60
+ * @returns The `add` method returns the instance of the `Heap` class.
52
61
  * @throws {Error} if priority is not a valid number
53
62
  */
54
- offer(element: T, priority?: number): Heap<T>;
55
- /**
56
- * Removes and returns an element with highest priority in the queue
57
- * @public
58
- * @returns {object}
59
- */
60
- poll(): HeapItem<T> | null;
63
+ add(priority: number, val?: T): Heap<T>;
64
+ poll(isItem?: undefined): T | undefined;
65
+ poll(isItem: false): T | undefined;
66
+ poll(isItem: true): HeapItem<T> | null;
61
67
  /**
62
- * Returns a sorted list of elements
63
- * @public
64
- * @returns {array}
68
+ * The function checks if a given node or value exists in the priority queue.
69
+ * @param {T | HeapItem<T>} node - The parameter `node` can be of type `T` or `HeapItem<T>`.
70
+ * @returns a boolean value.
65
71
  */
66
- toArray(): HeapItem<T>[];
72
+ has(node: T | HeapItem<T>): boolean;
73
+ toArray(isItem?: undefined): (T | undefined)[];
74
+ toArray(isItem: false): (T | undefined)[];
75
+ toArray(isItem: true): (HeapItem<T> | null)[];
76
+ sort(isItem?: undefined): (T | undefined)[];
77
+ sort(isItem: false): (T | undefined)[];
78
+ sort(isItem: true): (HeapItem<T> | null)[];
67
79
  /**
68
- * Clears the queue
69
- * @public
80
+ * The clear function clears the priority queue.
70
81
  */
71
82
  clear(): void;
72
83
  }
@@ -1,111 +1,154 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Heap = void 0;
4
- /**
5
- * @copyright 2021 Pablo Rios <zrwusa@gmail.com>
6
- * @license MIT
7
- *
8
- * @abstract
9
- * @class Heap
10
- */
3
+ exports.Heap = exports.HeapItem = void 0;
4
+ class HeapItem {
5
+ /**
6
+ * The constructor function initializes an instance of a class with a priority and a value.
7
+ * @param {number} priority - The `priority` parameter is a number that represents the priority of the value. It is
8
+ * optional and has a default value of `NaN`.
9
+ * @param {T | null} [val=null] - The `val` parameter is of type `T | null`, which means it can accept a value of type
10
+ * `T` or `null`.
11
+ */
12
+ constructor(priority = Number.MAX_SAFE_INTEGER, val = null) {
13
+ this._val = val;
14
+ this._priority = priority;
15
+ }
16
+ get priority() {
17
+ return this._priority;
18
+ }
19
+ set priority(value) {
20
+ this._priority = value;
21
+ }
22
+ get val() {
23
+ return this._val;
24
+ }
25
+ set val(value) {
26
+ this._val = value;
27
+ }
28
+ }
29
+ exports.HeapItem = HeapItem;
11
30
  class Heap {
12
31
  /**
13
- * Creates a priority queue
14
- * @public
15
- * @params {object} [options]
32
+ * The function is a constructor for a class that initializes a priority callback function based on the
33
+ * options provided.
34
+ * @param [options] - An optional object that contains configuration options for the Heap.
16
35
  */
17
36
  constructor(options) {
18
37
  if (options) {
19
- const { priority } = options;
20
- if (priority !== undefined && typeof priority !== 'function') {
38
+ const { priorityExtractor } = options;
39
+ if (priorityExtractor !== undefined && typeof priorityExtractor !== 'function') {
21
40
  throw new Error('.constructor expects a valid priority function');
22
41
  }
23
- this._priorityCb = priority || ((el) => +el);
42
+ this._priorityExtractor = priorityExtractor || ((el) => +el);
24
43
  }
25
44
  else {
26
- this._priorityCb = (el) => +el;
45
+ this._priorityExtractor = (el) => +el;
27
46
  }
28
47
  }
48
+ get pq() {
49
+ return this._pq;
50
+ }
51
+ get priorityExtractor() {
52
+ return this._priorityExtractor;
53
+ }
29
54
  /**
30
- * @public
31
- * @returns {number}
55
+ * The function returns the size of a priority queue.
56
+ * @returns The size of the priority queue.
32
57
  */
33
58
  get size() {
34
59
  return this._pq.size;
35
60
  }
36
61
  /**
37
- * @public
38
- * @returns {boolean}
62
+ * The function checks if a priority queue is empty.
63
+ * @returns {boolean} A boolean value indicating whether the size of the priority queue is less than 1.
39
64
  */
40
65
  isEmpty() {
41
66
  return this._pq.size < 1;
42
67
  }
43
68
  /**
44
- * Returns an element with highest priority in the queue
45
- * @public
46
- * @returns {object}
69
+ * The `peek` function returns the top item in the priority queue without removing it.
70
+ * @returns The `peek()` method is returning either a `HeapItem<T>` object or `null`.Returns an val with the highest priority in the queue
47
71
  */
48
- peek() {
49
- return this._pq.peek();
72
+ peek(isItem) {
73
+ isItem = isItem !== null && isItem !== void 0 ? isItem : false;
74
+ const peeked = this._pq.peek();
75
+ return isItem ? peeked : peeked === null || peeked === void 0 ? void 0 : peeked.val;
50
76
  }
51
77
  /**
52
- * Returns an element with lowest priority in the queue
53
- * @public
54
- * @returns {object}
78
+ * The `peekLast` function returns the last item in the heap.
79
+ * @returns The method `peekLast()` returns either a `HeapItem<T>` object or `null`.Returns an val with the lowest priority in the queue
55
80
  */
56
- peekLast() {
57
- return this._pq.leaf();
81
+ peekLast(isItem) {
82
+ isItem = isItem !== null && isItem !== void 0 ? isItem : false;
83
+ const leafItem = this._pq.leaf();
84
+ return isItem ? leafItem : leafItem === null || leafItem === void 0 ? void 0 : leafItem.val;
58
85
  }
59
86
  /**
60
- * Adds an element to the queue
61
- * @public
62
- * @param {any} element
63
- * @param priority
87
+ * The `add` function adds an val to a priority queue with an optional priority value.
88
+ * @param {T} val - The `val` parameter represents the value that you want to add to the heap. It can be of any
89
+ * type.
90
+ * @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the
91
+ * val being added to the heap. If the `val` parameter is a number, then the `priority` parameter is set to
92
+ * the value of `val`. If the `val` parameter is not a number, then the
93
+ * @returns The `add` method returns the instance of the `Heap` class.
64
94
  * @throws {Error} if priority is not a valid number
65
95
  */
66
- offer(element, priority) {
67
- if (typeof element === 'number') {
68
- priority = element;
69
- }
70
- else {
71
- if (priority === undefined) {
72
- throw new Error('.offer expects a numeric priority');
73
- }
74
- }
75
- if (priority && Number.isNaN(+priority)) {
76
- throw new Error('.offer expects a numeric priority');
77
- }
78
- if (Number.isNaN(+priority) && Number.isNaN(this._priorityCb(element))) {
79
- throw new Error('.offer expects a numeric priority '
80
- + 'or a constructor callback that returns a number');
81
- }
82
- const _priority = !Number.isNaN(+priority) ? priority : this._priorityCb(element);
83
- this._pq.offer({ priority: _priority, element });
96
+ add(priority, val) {
97
+ val = (val === undefined) ? priority : val;
98
+ this._pq.add(new HeapItem(priority, val));
84
99
  return this;
85
100
  }
86
101
  /**
87
- * Removes and returns an element with highest priority in the queue
88
- * @public
89
- * @returns {object}
102
+ * The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an val with the highest priority in the queue
103
+ * @returns either a HeapItem<T> object or null.
90
104
  */
91
- poll() {
105
+ poll(isItem) {
106
+ isItem = isItem !== null && isItem !== void 0 ? isItem : false;
92
107
  const top = this._pq.poll();
93
108
  if (!top) {
94
109
  return null;
95
110
  }
96
- return top;
111
+ return isItem ? top : top.val;
112
+ }
113
+ /**
114
+ * The function checks if a given node or value exists in the priority queue.
115
+ * @param {T | HeapItem<T>} node - The parameter `node` can be of type `T` or `HeapItem<T>`.
116
+ * @returns a boolean value.
117
+ */
118
+ has(node) {
119
+ if (node instanceof HeapItem) {
120
+ return this.pq.getNodes().includes(node);
121
+ }
122
+ else {
123
+ return this.pq.getNodes().findIndex(item => {
124
+ return item.val === node;
125
+ }) !== -1;
126
+ }
127
+ }
128
+ /**
129
+ * The `toArray` function returns an array of `HeapItem<T>` objects.
130
+ * @returns An array of HeapItem<T> objects.Returns a sorted list of vals
131
+ */
132
+ toArray(isItem) {
133
+ isItem = isItem !== null && isItem !== void 0 ? isItem : false;
134
+ const itemArray = this._pq.toArray();
135
+ return isItem ? itemArray : itemArray.map(item => item.val);
97
136
  }
98
137
  /**
99
- * Returns a sorted list of elements
100
- * @public
101
- * @returns {array}
138
+ * The function sorts the elements in the priority queue and returns either the sorted items or their values depending
139
+ * on the value of the isItem parameter.
140
+ * @param {boolean} [isItem] - The `isItem` parameter is a boolean flag that indicates whether the sorted result should
141
+ * be an array of `HeapItem<T>` objects or an array of the values (`T`) of those objects. If `isItem` is `true`, the
142
+ * sorted result will be an array of `HeapItem
143
+ * @returns an array of either `HeapItem<T>`, `null`, `T`, or `undefined` values.
102
144
  */
103
- toArray() {
104
- return this._pq.toArray();
145
+ sort(isItem) {
146
+ isItem = isItem !== null && isItem !== void 0 ? isItem : false;
147
+ const sorted = this._pq.sort();
148
+ return isItem ? sorted : sorted.map(item => item.val);
105
149
  }
106
150
  /**
107
- * Clears the queue
108
- * @public
151
+ * The clear function clears the priority queue.
109
152
  */
110
153
  clear() {
111
154
  this._pq.clear();
@@ -1,14 +1,23 @@
1
1
  /**
2
- * @copyright 2020 Pablo Rios <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
- import { Heap, HeapItem, HeapOptions } from './heap';
8
+ import { Heap, HeapItem } from './heap';
6
9
  import { PriorityQueue } from '../priority-queue';
10
+ import type { HeapOptions } from '../../types';
7
11
  /**
8
12
  * @class MaxHeap
9
13
  * @extends Heap
10
14
  */
11
- export declare class MaxHeap<T> extends Heap<T> {
15
+ export declare class MaxHeap<T = number> extends Heap<T> {
12
16
  protected _pq: PriorityQueue<HeapItem<T>>;
17
+ /**
18
+ * The constructor initializes a PriorityQueue with a custom comparator function.
19
+ * @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
20
+ * type `HeapOptions<T>`, which is a generic type that represents the options for the heap.
21
+ */
13
22
  constructor(options?: HeapOptions<T>);
14
23
  }
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  /**
3
- * @copyright 2020 Pablo Rios <zrwusa@gmail.com>
4
- * @license MIT
3
+ * data-structure-typed
4
+ *
5
+ * @author Tyler Zeng
6
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
7
+ * @license MIT License
5
8
  */
6
9
  Object.defineProperty(exports, "__esModule", { value: true });
7
10
  exports.MaxHeap = void 0;
@@ -12,6 +15,11 @@ const priority_queue_1 = require("../priority-queue");
12
15
  * @extends Heap
13
16
  */
14
17
  class MaxHeap extends heap_1.Heap {
18
+ /**
19
+ * The constructor initializes a PriorityQueue with a custom comparator function.
20
+ * @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
21
+ * type `HeapOptions<T>`, which is a generic type that represents the options for the heap.
22
+ */
15
23
  constructor(options) {
16
24
  super(options);
17
25
  this._pq = new priority_queue_1.PriorityQueue({
@@ -1,14 +1,24 @@
1
1
  /**
2
- * @copyright 2020 Pablo Rios <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
- import { Heap, HeapItem, HeapOptions } from './heap';
8
+ import { Heap, HeapItem } from './heap';
6
9
  import { PriorityQueue } from '../priority-queue';
10
+ import type { HeapOptions } from '../../types';
7
11
  /**
8
12
  * @class MinHeap
9
13
  * @extends Heap
10
14
  */
11
- export declare class MinHeap<T> extends Heap<T> {
15
+ export declare class MinHeap<T = number> extends Heap<T> {
12
16
  protected _pq: PriorityQueue<HeapItem<T>>;
17
+ /**
18
+ * The constructor initializes a PriorityQueue with a comparator function that compares the priority of two HeapItem
19
+ * objects.
20
+ * @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
21
+ * type `HeapOptions<T>`, which is a generic type that represents the options for the heap.
22
+ */
13
23
  constructor(options?: HeapOptions<T>);
14
24
  }
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  /**
3
- * @copyright 2020 Pablo Rios <zrwusa@gmail.com>
4
- * @license MIT
3
+ * data-structure-typed
4
+ *
5
+ * @author Tyler Zeng
6
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
7
+ * @license MIT License
5
8
  */
6
9
  Object.defineProperty(exports, "__esModule", { value: true });
7
10
  exports.MinHeap = void 0;
@@ -12,6 +15,12 @@ const priority_queue_1 = require("../priority-queue");
12
15
  * @extends Heap
13
16
  */
14
17
  class MinHeap extends heap_1.Heap {
18
+ /**
19
+ * The constructor initializes a PriorityQueue with a comparator function that compares the priority of two HeapItem
20
+ * objects.
21
+ * @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
22
+ * type `HeapOptions<T>`, which is a generic type that represents the options for the heap.
23
+ */
15
24
  constructor(options) {
16
25
  super(options);
17
26
  this._pq = new priority_queue_1.PriorityQueue({
@@ -4,6 +4,7 @@ export * from './stack';
4
4
  export * from './queue';
5
5
  export * from './graph';
6
6
  export * from './binary-tree';
7
+ export * from './tree';
7
8
  export * from './heap';
8
9
  export * from './priority-queue';
9
10
  export * from './matrix';
@@ -20,6 +20,7 @@ __exportStar(require("./stack"), exports);
20
20
  __exportStar(require("./queue"), exports);
21
21
  __exportStar(require("./graph"), exports);
22
22
  __exportStar(require("./binary-tree"), exports);
23
+ __exportStar(require("./tree"), exports);
23
24
  __exportStar(require("./heap"), exports);
24
25
  __exportStar(require("./priority-queue"), exports);
25
26
  __exportStar(require("./matrix"), exports);