data-structure-typed 0.9.16 → 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 (264) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +665 -172
  3. package/dist/bundle.js +2 -0
  4. package/dist/bundle.js.LICENSE.txt +13 -0
  5. package/dist/data-structures/binary-tree/aa-tree.js +2 -5
  6. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +364 -0
  7. package/dist/data-structures/binary-tree/abstract-binary-tree.js +1308 -0
  8. package/dist/data-structures/binary-tree/avl-tree.d.ts +85 -14
  9. package/dist/data-structures/binary-tree/avl-tree.js +142 -116
  10. package/dist/data-structures/binary-tree/b-tree.js +2 -5
  11. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +39 -1
  12. package/dist/data-structures/binary-tree/binary-indexed-tree.js +54 -13
  13. package/dist/data-structures/binary-tree/binary-tree.d.ts +29 -126
  14. package/dist/data-structures/binary-tree/binary-tree.js +31 -1093
  15. package/dist/data-structures/binary-tree/bst.d.ts +117 -23
  16. package/dist/data-structures/binary-tree/bst.js +233 -240
  17. package/dist/data-structures/binary-tree/index.d.ts +1 -0
  18. package/dist/data-structures/binary-tree/index.js +1 -0
  19. package/dist/data-structures/binary-tree/rb-tree.d.ts +18 -1
  20. package/dist/data-structures/binary-tree/rb-tree.js +40 -5
  21. package/dist/data-structures/binary-tree/segment-tree.d.ts +61 -11
  22. package/dist/data-structures/binary-tree/segment-tree.js +126 -93
  23. package/dist/data-structures/binary-tree/splay-tree.js +2 -5
  24. package/dist/data-structures/binary-tree/tree-multiset.d.ts +213 -6
  25. package/dist/data-structures/binary-tree/tree-multiset.js +687 -34
  26. package/dist/data-structures/binary-tree/two-three-tree.js +2 -5
  27. package/dist/data-structures/graph/abstract-graph.d.ts +270 -36
  28. package/dist/data-structures/graph/abstract-graph.js +610 -572
  29. package/dist/data-structures/graph/directed-graph.d.ts +173 -16
  30. package/dist/data-structures/graph/directed-graph.js +345 -313
  31. package/dist/data-structures/graph/index.d.ts +1 -0
  32. package/dist/data-structures/graph/index.js +1 -0
  33. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  34. package/dist/data-structures/graph/map-graph.js +111 -0
  35. package/dist/data-structures/graph/undirected-graph.d.ts +111 -9
  36. package/dist/data-structures/graph/undirected-graph.js +203 -178
  37. package/dist/data-structures/hash/coordinate-map.d.ts +38 -1
  38. package/dist/data-structures/hash/coordinate-map.js +59 -36
  39. package/dist/data-structures/hash/coordinate-set.d.ts +32 -2
  40. package/dist/data-structures/hash/coordinate-set.js +49 -33
  41. package/dist/data-structures/hash/hash-table.d.ts +2 -1
  42. package/dist/data-structures/hash/hash-table.js +4 -0
  43. package/dist/data-structures/hash/pair.d.ts +2 -1
  44. package/dist/data-structures/hash/pair.js +4 -0
  45. package/dist/data-structures/hash/tree-map.d.ts +2 -1
  46. package/dist/data-structures/hash/tree-map.js +4 -0
  47. package/dist/data-structures/hash/tree-set.d.ts +2 -1
  48. package/dist/data-structures/hash/tree-set.js +4 -0
  49. package/dist/data-structures/heap/heap.d.ts +62 -45
  50. package/dist/data-structures/heap/heap.js +124 -86
  51. package/dist/data-structures/heap/max-heap.d.ts +13 -5
  52. package/dist/data-structures/heap/max-heap.js +18 -28
  53. package/dist/data-structures/heap/min-heap.d.ts +14 -5
  54. package/dist/data-structures/heap/min-heap.js +19 -28
  55. package/dist/data-structures/index.d.ts +1 -1
  56. package/dist/data-structures/index.js +1 -1
  57. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +193 -56
  58. package/dist/data-structures/linked-list/doubly-linked-list.js +484 -220
  59. package/dist/data-structures/linked-list/index.d.ts +1 -0
  60. package/dist/data-structures/linked-list/index.js +1 -0
  61. package/dist/data-structures/linked-list/singly-linked-list.d.ts +117 -315
  62. package/dist/data-structures/linked-list/singly-linked-list.js +374 -727
  63. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -1
  64. package/dist/data-structures/linked-list/skip-linked-list.js +4 -0
  65. package/dist/data-structures/matrix/matrix.d.ts +12 -0
  66. package/dist/data-structures/matrix/matrix.js +21 -8
  67. package/dist/data-structures/matrix/matrix2d.d.ts +85 -2
  68. package/dist/data-structures/matrix/matrix2d.js +146 -80
  69. package/dist/data-structures/matrix/navigator.d.ts +36 -1
  70. package/dist/data-structures/matrix/navigator.js +46 -37
  71. package/dist/data-structures/matrix/vector2d.d.ts +142 -15
  72. package/dist/data-structures/matrix/vector2d.js +215 -109
  73. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -2
  74. package/dist/data-structures/priority-queue/max-priority-queue.js +33 -26
  75. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -2
  76. package/dist/data-structures/priority-queue/min-priority-queue.js +34 -26
  77. package/dist/data-structures/priority-queue/priority-queue.d.ts +153 -3
  78. package/dist/data-structures/priority-queue/priority-queue.js +244 -143
  79. package/dist/data-structures/queue/deque.d.ts +141 -13
  80. package/dist/data-structures/queue/deque.js +200 -82
  81. package/dist/data-structures/queue/queue.d.ts +65 -38
  82. package/dist/data-structures/queue/queue.js +110 -66
  83. package/dist/data-structures/stack/stack.d.ts +27 -32
  84. package/dist/data-structures/stack/stack.js +47 -53
  85. package/dist/data-structures/tree/index.d.ts +1 -0
  86. package/dist/data-structures/tree/index.js +17 -0
  87. package/dist/data-structures/tree/tree.d.ts +14 -0
  88. package/dist/data-structures/tree/tree.js +60 -0
  89. package/dist/data-structures/trie/trie.d.ts +33 -10
  90. package/dist/data-structures/trie/trie.js +123 -208
  91. package/dist/index.d.ts +3 -0
  92. package/dist/index.js +3 -0
  93. package/dist/interfaces/abstract-binary-tree.d.ts +90 -0
  94. package/dist/interfaces/abstract-graph.d.ts +17 -0
  95. package/dist/interfaces/avl-tree.d.ts +9 -0
  96. package/dist/interfaces/binary-tree.d.ts +6 -0
  97. package/dist/interfaces/bst.d.ts +17 -0
  98. package/dist/interfaces/directed-graph.d.ts +12 -0
  99. package/{src/data-structures/types/index.ts → dist/interfaces/index.d.ts} +10 -8
  100. package/dist/interfaces/index.js +31 -0
  101. package/{src/data-structures/hash/hash-table.ts → dist/interfaces/priority-queue.d.ts} +1 -1
  102. package/dist/interfaces/rb-tree.d.ts +8 -0
  103. package/dist/interfaces/segment-tree.d.ts +1 -0
  104. package/dist/interfaces/singly-linked-list.d.ts +1 -0
  105. package/dist/interfaces/singly-linked-list.js +2 -0
  106. package/dist/interfaces/tree-multiset.d.ts +7 -0
  107. package/dist/interfaces/tree-multiset.js +2 -0
  108. package/dist/interfaces/undirected-graph.d.ts +5 -0
  109. package/dist/interfaces/undirected-graph.js +2 -0
  110. package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
  111. package/dist/types/data-structures/abstract-binary-tree.js +25 -0
  112. package/dist/types/data-structures/abstract-graph.d.ts +11 -0
  113. package/dist/types/data-structures/abstract-graph.js +2 -0
  114. package/dist/types/data-structures/avl-tree.d.ts +4 -0
  115. package/dist/types/data-structures/avl-tree.js +2 -0
  116. package/dist/types/data-structures/binary-tree.d.ts +4 -0
  117. package/dist/types/data-structures/binary-tree.js +2 -0
  118. package/dist/types/data-structures/bst.d.ts +13 -0
  119. package/dist/types/data-structures/bst.js +9 -0
  120. package/dist/types/data-structures/directed-graph.d.ts +6 -0
  121. package/dist/types/data-structures/directed-graph.js +9 -0
  122. package/dist/types/data-structures/doubly-linked-list.d.ts +1 -0
  123. package/dist/types/data-structures/doubly-linked-list.js +2 -0
  124. package/dist/types/data-structures/heap.d.ts +3 -0
  125. package/dist/types/data-structures/heap.js +2 -0
  126. package/dist/{data-structures/types → types/data-structures}/index.d.ts +3 -1
  127. package/dist/{data-structures/types → types/data-structures}/index.js +3 -1
  128. package/dist/types/data-structures/map-graph.d.ts +1 -0
  129. package/dist/types/data-structures/map-graph.js +2 -0
  130. package/dist/{data-structures/types → types/data-structures}/navigator.d.ts +2 -2
  131. package/dist/types/data-structures/navigator.js +2 -0
  132. package/dist/{data-structures/types → types/data-structures}/priority-queue.d.ts +2 -2
  133. package/dist/types/data-structures/priority-queue.js +2 -0
  134. package/dist/types/data-structures/rb-tree.d.ts +8 -0
  135. package/dist/types/data-structures/rb-tree.js +8 -0
  136. package/dist/types/data-structures/segment-tree.js +2 -0
  137. package/dist/types/data-structures/singly-linked-list.d.ts +1 -0
  138. package/dist/types/data-structures/singly-linked-list.js +2 -0
  139. package/dist/types/data-structures/tree-multiset.d.ts +4 -0
  140. package/dist/types/data-structures/tree-multiset.js +2 -0
  141. package/dist/types/helpers.d.ts +1 -0
  142. package/dist/types/helpers.js +2 -0
  143. package/dist/types/index.d.ts +3 -0
  144. package/dist/types/index.js +19 -0
  145. package/dist/types/utils/index.d.ts +2 -0
  146. package/dist/types/utils/index.js +18 -0
  147. package/dist/types/utils/utils.d.ts +7 -0
  148. package/dist/types/utils/utils.js +2 -0
  149. package/dist/types/utils/validate-type.d.ts +19 -0
  150. package/dist/types/utils/validate-type.js +2 -0
  151. package/dist/utils/utils.d.ts +17 -103
  152. package/dist/utils/utils.js +40 -625
  153. package/package.json +96 -23
  154. package/.idea/data-structure-typed.iml +0 -12
  155. package/.idea/modules.xml +0 -8
  156. package/.idea/vcs.xml +0 -6
  157. package/dist/data-structures/trampoline.d.ts +0 -16
  158. package/dist/data-structures/trampoline.js +0 -130
  159. package/dist/data-structures/types/abstract-graph.d.ts +0 -29
  160. package/dist/data-structures/types/avl-tree.d.ts +0 -5
  161. package/dist/data-structures/types/binary-tree.d.ts +0 -16
  162. package/dist/data-structures/types/bst.d.ts +0 -7
  163. package/dist/data-structures/types/directed-graph.d.ts +0 -10
  164. package/dist/data-structures/types/doubly-linked-list.d.ts +0 -1
  165. package/dist/data-structures/types/heap.d.ts +0 -7
  166. package/dist/data-structures/types/singly-linked-list.d.ts +0 -5
  167. package/dist/data-structures/types/tree-multiset.d.ts +0 -5
  168. package/dist/data-structures/types/utils.d.ts +0 -52
  169. package/dist/data-structures/types/utils.js +0 -54
  170. package/src/data-structures/binary-tree/aa-tree.ts +0 -3
  171. package/src/data-structures/binary-tree/avl-tree.ts +0 -227
  172. package/src/data-structures/binary-tree/b-tree.ts +0 -3
  173. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -33
  174. package/src/data-structures/binary-tree/binary-tree.ts +0 -1133
  175. package/src/data-structures/binary-tree/bst.ts +0 -395
  176. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  177. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  178. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  179. package/src/data-structures/binary-tree/index.ts +0 -11
  180. package/src/data-structures/binary-tree/rb-tree.ts +0 -3
  181. package/src/data-structures/binary-tree/segment-tree.ts +0 -172
  182. package/src/data-structures/binary-tree/splay-tree.ts +0 -3
  183. package/src/data-structures/binary-tree/tree-multiset.ts +0 -18
  184. package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  185. package/src/data-structures/diagrams/README.md +0 -7
  186. package/src/data-structures/graph/abstract-graph.ts +0 -753
  187. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
  188. package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
  189. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
  190. package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
  191. package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
  192. package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
  193. package/src/data-structures/graph/diagrams/edge-list.png +0 -0
  194. package/src/data-structures/graph/diagrams/max-flow.png +0 -0
  195. package/src/data-structures/graph/diagrams/mst.png +0 -0
  196. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  197. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  198. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  199. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  200. package/src/data-structures/graph/directed-graph.ts +0 -306
  201. package/src/data-structures/graph/index.ts +0 -3
  202. package/src/data-structures/graph/undirected-graph.ts +0 -155
  203. package/src/data-structures/hash/coordinate-map.ts +0 -24
  204. package/src/data-structures/hash/coordinate-set.ts +0 -20
  205. package/src/data-structures/hash/index.ts +0 -6
  206. package/src/data-structures/heap/heap.ts +0 -127
  207. package/src/data-structures/heap/index.ts +0 -3
  208. package/src/data-structures/heap/max-heap.ts +0 -23
  209. package/src/data-structures/heap/min-heap.ts +0 -25
  210. package/src/data-structures/index.ts +0 -12
  211. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -250
  212. package/src/data-structures/linked-list/index.ts +0 -2
  213. package/src/data-structures/linked-list/singly-linked-list.ts +0 -736
  214. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  215. package/src/data-structures/matrix/index.ts +0 -4
  216. package/src/data-structures/matrix/matrix.ts +0 -13
  217. package/src/data-structures/matrix/matrix2d.ts +0 -125
  218. package/src/data-structures/matrix/navigator.ts +0 -87
  219. package/src/data-structures/matrix/vector2d.ts +0 -189
  220. package/src/data-structures/priority-queue/index.ts +0 -3
  221. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -13
  222. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -13
  223. package/src/data-structures/priority-queue/priority-queue.ts +0 -200
  224. package/src/data-structures/queue/deque.ts +0 -139
  225. package/src/data-structures/queue/index.ts +0 -2
  226. package/src/data-structures/queue/queue.ts +0 -122
  227. package/src/data-structures/stack/index.ts +0 -1
  228. package/src/data-structures/stack/stack.ts +0 -103
  229. package/src/data-structures/trampoline.ts +0 -51
  230. package/src/data-structures/trie/index.ts +0 -1
  231. package/src/data-structures/trie/trie.ts +0 -203
  232. package/src/data-structures/types/abstract-graph.ts +0 -51
  233. package/src/data-structures/types/avl-tree.ts +0 -6
  234. package/src/data-structures/types/binary-tree.ts +0 -15
  235. package/src/data-structures/types/bst.ts +0 -5
  236. package/src/data-structures/types/directed-graph.ts +0 -18
  237. package/src/data-structures/types/doubly-linked-list.ts +0 -1
  238. package/src/data-structures/types/heap.ts +0 -8
  239. package/src/data-structures/types/navigator.ts +0 -12
  240. package/src/data-structures/types/priority-queue.ts +0 -9
  241. package/src/data-structures/types/segment-tree.ts +0 -1
  242. package/src/data-structures/types/singly-linked-list.ts +0 -15
  243. package/src/data-structures/types/tree-multiset.ts +0 -3
  244. package/src/data-structures/types/utils.ts +0 -173
  245. package/src/index.ts +0 -1
  246. package/src/utils/index.ts +0 -1
  247. package/src/utils/utils.ts +0 -505
  248. package/tsconfig.json +0 -56
  249. /package/dist/{data-structures/types/abstract-graph.js → interfaces/abstract-binary-tree.js} +0 -0
  250. /package/dist/{data-structures/types/avl-tree.js → interfaces/abstract-graph.js} +0 -0
  251. /package/dist/{data-structures/types/binary-tree.js → interfaces/avl-tree.js} +0 -0
  252. /package/dist/{data-structures/types/bst.js → interfaces/binary-tree.js} +0 -0
  253. /package/dist/{data-structures/types/directed-graph.js → interfaces/bst.js} +0 -0
  254. /package/dist/{data-structures/types/doubly-linked-list.js → interfaces/directed-graph.js} +0 -0
  255. /package/{src/data-structures/hash/pair.ts → dist/interfaces/doubly-linked-list.d.ts} +0 -0
  256. /package/dist/{data-structures/types/heap.js → interfaces/doubly-linked-list.js} +0 -0
  257. /package/{src/data-structures/hash/tree-map.ts → dist/interfaces/heap.d.ts} +0 -0
  258. /package/dist/{data-structures/types/navigator.js → interfaces/heap.js} +0 -0
  259. /package/{src/data-structures/hash/tree-set.ts → dist/interfaces/navigator.d.ts} +0 -0
  260. /package/dist/{data-structures/types/priority-queue.js → interfaces/navigator.js} +0 -0
  261. /package/dist/{data-structures/types/segment-tree.js → interfaces/priority-queue.js} +0 -0
  262. /package/dist/{data-structures/types/singly-linked-list.js → interfaces/rb-tree.js} +0 -0
  263. /package/dist/{data-structures/types/tree-multiset.js → interfaces/segment-tree.js} +0 -0
  264. /package/dist/{data-structures/types → types/data-structures}/segment-tree.d.ts +0 -0
@@ -1,39 +1,55 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.CoordinateSet = void 0;
19
- var CoordinateSet = /** @class */ (function (_super) {
20
- __extends(CoordinateSet, _super);
21
- function CoordinateSet(joint) {
22
- var _this = _super.call(this) || this;
23
- _this._joint = '_';
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
+ */
11
+ class CoordinateSet extends Set {
12
+ constructor(joint) {
13
+ super();
14
+ this._joint = '_';
24
15
  if (joint !== undefined)
25
- _this._joint = joint;
26
- return _this;
16
+ this._joint = joint;
27
17
  }
28
- CoordinateSet.prototype.has = function (value) {
29
- return _super.prototype.has.call(this, value.join(this._joint));
30
- };
31
- CoordinateSet.prototype.add = function (value) {
32
- return _super.prototype.add.call(this, value.join(this._joint));
33
- };
34
- CoordinateSet.prototype.delete = function (value) {
35
- return _super.prototype.delete.call(this, value.join(this._joint));
36
- };
37
- return CoordinateSet;
38
- }(Set));
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
+ */
28
+ has(value) {
29
+ return super.has(value.join(this._joint));
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
+ */
38
+ add(value) {
39
+ return super.add(value.join(this._joint));
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
+ */
48
+ delete(value) {
49
+ return super.delete(value.join(this._joint));
50
+ }
51
+ _setJoint(v) {
52
+ this._joint = v;
53
+ }
54
+ }
39
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,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,66 +1,83 @@
1
- import { PriorityQueue } from '../priority-queue';
2
- import type { HeapItem, HeapOptions } from '../types';
3
1
  /**
4
- * @copyright 2021 Tyler Zeng <zrwusa@gmail.com>
5
- * @license MIT
2
+ * data-structure-typed
6
3
  *
7
- * @abstract
8
- * @class Heap
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
9
7
  */
10
- export declare abstract class Heap<T> {
11
- protected abstract _pq: PriorityQueue<HeapItem<T>>;
12
- protected _priorityCb: (element: T) => number;
8
+ import { PriorityQueue } from '../priority-queue';
9
+ import type { HeapOptions } from '../../types';
10
+ export declare class HeapItem<T = number> {
13
11
  /**
14
- * Creates a priority queue
15
- * @public
16
- * @params {object} [options]
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> {
27
+ /**
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.
17
31
  */
18
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;
19
37
  /**
20
- * @public
21
- * @returns {number}
38
+ * The function returns the size of a priority queue.
39
+ * @returns The size of the priority queue.
22
40
  */
23
41
  get size(): number;
24
42
  /**
25
- * @public
26
- * @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.
27
45
  */
28
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;
29
53
  /**
30
- * Returns an element with highest priority in the queue
31
- * @public
32
- * @returns {object}
33
- */
34
- peek(): HeapItem<T> | null;
35
- /**
36
- * Returns an element with lowest priority in the queue
37
- * @public
38
- * @returns {object}
39
- */
40
- peekLast(): HeapItem<T> | null;
41
- /**
42
- * Adds an element to the queue
43
- * @public
44
- * @param {any} element
45
- * @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.
46
61
  * @throws {Error} if priority is not a valid number
47
62
  */
48
- offer(element: T, priority?: number): Heap<T>;
49
- /**
50
- * Removes and returns an element with highest priority in the queue
51
- * @public
52
- * @returns {object}
53
- */
54
- 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;
55
67
  /**
56
- * Returns a sorted list of elements
57
- * @public
58
- * @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.
59
71
  */
60
- 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)[];
61
79
  /**
62
- * Clears the queue
63
- * @public
80
+ * The clear function clears the priority queue.
64
81
  */
65
82
  clear(): void;
66
83
  }
@@ -1,119 +1,157 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Heap = void 0;
4
- /**
5
- * @copyright 2021 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT
7
- *
8
- * @abstract
9
- * @class Heap
10
- */
11
- var Heap = /** @class */ (function () {
3
+ exports.Heap = exports.HeapItem = void 0;
4
+ class HeapItem {
12
5
  /**
13
- * Creates a priority queue
14
- * @public
15
- * @params {object} [options]
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`.
16
11
  */
17
- function Heap(options) {
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;
30
+ class Heap {
31
+ /**
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.
35
+ */
36
+ constructor(options) {
18
37
  if (options) {
19
- var priority = options.priority;
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 || (function (el) { return +el; });
42
+ this._priorityExtractor = priorityExtractor || ((el) => +el);
24
43
  }
25
44
  else {
26
- this._priorityCb = function (el) { return +el; };
45
+ this._priorityExtractor = (el) => +el;
27
46
  }
28
47
  }
29
- Object.defineProperty(Heap.prototype, "size", {
30
- /**
31
- * @public
32
- * @returns {number}
33
- */
34
- get: function () {
35
- return this._pq.size;
36
- },
37
- enumerable: false,
38
- configurable: true
39
- });
48
+ get pq() {
49
+ return this._pq;
50
+ }
51
+ get priorityExtractor() {
52
+ return this._priorityExtractor;
53
+ }
40
54
  /**
41
- * @public
42
- * @returns {boolean}
55
+ * The function returns the size of a priority queue.
56
+ * @returns The size of the priority queue.
43
57
  */
44
- Heap.prototype.isEmpty = function () {
58
+ get size() {
59
+ return this._pq.size;
60
+ }
61
+ /**
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.
64
+ */
65
+ isEmpty() {
45
66
  return this._pq.size < 1;
46
- };
67
+ }
47
68
  /**
48
- * Returns an element with highest priority in the queue
49
- * @public
50
- * @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
51
71
  */
52
- Heap.prototype.peek = function () {
53
- return this._pq.peek();
54
- };
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;
76
+ }
55
77
  /**
56
- * Returns an element with lowest priority in the queue
57
- * @public
58
- * @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
59
80
  */
60
- Heap.prototype.peekLast = function () {
61
- return this._pq.leaf();
62
- };
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;
85
+ }
63
86
  /**
64
- * Adds an element to the queue
65
- * @public
66
- * @param {any} element
67
- * @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.
68
94
  * @throws {Error} if priority is not a valid number
69
95
  */
70
- Heap.prototype.offer = function (element, priority) {
71
- if (typeof element === 'number') {
72
- priority = element;
73
- }
74
- else {
75
- if (priority === undefined) {
76
- throw new Error('.offer expects a numeric priority');
77
- }
78
- }
79
- if (priority && Number.isNaN(+priority)) {
80
- throw new Error('.offer expects a numeric priority');
81
- }
82
- if (Number.isNaN(+priority) && Number.isNaN(this._priorityCb(element))) {
83
- throw new Error('.offer expects a numeric priority '
84
- + 'or a constructor callback that returns a number');
85
- }
86
- var _priority = !Number.isNaN(+priority) ? priority : this._priorityCb(element);
87
- this._pq.offer({ priority: _priority, element: element });
96
+ add(priority, val) {
97
+ val = (val === undefined) ? priority : val;
98
+ this._pq.add(new HeapItem(priority, val));
88
99
  return this;
89
- };
100
+ }
90
101
  /**
91
- * Removes and returns an element with highest priority in the queue
92
- * @public
93
- * @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.
94
104
  */
95
- Heap.prototype.poll = function () {
96
- var top = this._pq.poll();
105
+ poll(isItem) {
106
+ isItem = isItem !== null && isItem !== void 0 ? isItem : false;
107
+ const top = this._pq.poll();
97
108
  if (!top) {
98
109
  return null;
99
110
  }
100
- return top;
101
- };
111
+ return isItem ? top : top.val;
112
+ }
102
113
  /**
103
- * Returns a sorted list of elements
104
- * @public
105
- * @returns {array}
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.
106
117
  */
107
- Heap.prototype.toArray = function () {
108
- return this._pq.toArray();
109
- };
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);
136
+ }
110
137
  /**
111
- * Clears the queue
112
- * @public
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.
113
144
  */
114
- Heap.prototype.clear = function () {
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);
149
+ }
150
+ /**
151
+ * The clear function clears the priority queue.
152
+ */
153
+ clear() {
115
154
  this._pq.clear();
116
- };
117
- return Heap;
118
- }());
155
+ }
156
+ }
119
157
  exports.Heap = Heap;
@@ -1,15 +1,23 @@
1
1
  /**
2
- * @copyright 2020 Tyler Zeng <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 } from './heap';
8
+ import { Heap, HeapItem } from './heap';
6
9
  import { PriorityQueue } from '../priority-queue';
7
- import type { HeapItem, HeapOptions } from '../types';
10
+ import type { HeapOptions } from '../../types';
8
11
  /**
9
12
  * @class MaxHeap
10
13
  * @extends Heap
11
14
  */
12
- export declare class MaxHeap<T> extends Heap<T> {
15
+ export declare class MaxHeap<T = number> extends Heap<T> {
13
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
+ */
14
22
  constructor(options?: HeapOptions<T>);
15
23
  }
@@ -1,40 +1,30 @@
1
1
  "use strict";
2
2
  /**
3
- * @copyright 2020 Tyler Zeng <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
- var __extends = (this && this.__extends) || (function () {
7
- var extendStatics = function (d, b) {
8
- extendStatics = Object.setPrototypeOf ||
9
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
10
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
11
- return extendStatics(d, b);
12
- };
13
- return function (d, b) {
14
- if (typeof b !== "function" && b !== null)
15
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
16
- extendStatics(d, b);
17
- function __() { this.constructor = d; }
18
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
19
- };
20
- })();
21
9
  Object.defineProperty(exports, "__esModule", { value: true });
22
10
  exports.MaxHeap = void 0;
23
- var heap_1 = require("./heap");
24
- var priority_queue_1 = require("../priority-queue");
11
+ const heap_1 = require("./heap");
12
+ const priority_queue_1 = require("../priority-queue");
25
13
  /**
26
14
  * @class MaxHeap
27
15
  * @extends Heap
28
16
  */
29
- var MaxHeap = /** @class */ (function (_super) {
30
- __extends(MaxHeap, _super);
31
- function MaxHeap(options) {
32
- var _this = _super.call(this, options) || this;
33
- _this._pq = new priority_queue_1.PriorityQueue({
34
- comparator: function (a, b) { return b.priority - a.priority; }
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
+ */
23
+ constructor(options) {
24
+ super(options);
25
+ this._pq = new priority_queue_1.PriorityQueue({
26
+ comparator: (a, b) => b.priority - a.priority
35
27
  });
36
- return _this;
37
28
  }
38
- return MaxHeap;
39
- }(heap_1.Heap));
29
+ }
40
30
  exports.MaxHeap = MaxHeap;
@@ -1,15 +1,24 @@
1
1
  /**
2
- * @copyright 2020 Tyler Zeng <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 } from './heap';
8
+ import { Heap, HeapItem } from './heap';
6
9
  import { PriorityQueue } from '../priority-queue';
7
- import type { HeapItem, HeapOptions } from '../types';
10
+ import type { HeapOptions } from '../../types';
8
11
  /**
9
12
  * @class MinHeap
10
13
  * @extends Heap
11
14
  */
12
- export declare class MinHeap<T> extends Heap<T> {
15
+ export declare class MinHeap<T = number> extends Heap<T> {
13
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
+ */
14
23
  constructor(options?: HeapOptions<T>);
15
24
  }