data-structure-typed 0.9.16 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +134 -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,108 +1,80 @@
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
- var __read = (this && this.__read) || function (o, n) {
18
- var m = typeof Symbol === "function" && o[Symbol.iterator];
19
- if (!m) return o;
20
- var i = m.call(o), r, ar = [], e;
21
- try {
22
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
23
- }
24
- catch (error) { e = { error: error }; }
25
- finally {
26
- try {
27
- if (r && !r.done && (m = i["return"])) m.call(i);
28
- }
29
- finally { if (e) throw e.error; }
30
- }
31
- return ar;
32
- };
33
2
  Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.BST = exports.BSTNode = exports.CP = void 0;
35
- var binary_tree_1 = require("./binary-tree");
36
- var CP;
37
- (function (CP) {
38
- CP[CP["lt"] = -1] = "lt";
39
- CP[CP["eq"] = 0] = "eq";
40
- CP[CP["gt"] = 1] = "gt";
41
- })(CP = exports.CP || (exports.CP = {}));
42
- var BSTNode = /** @class */ (function (_super) {
43
- __extends(BSTNode, _super);
44
- function BSTNode() {
45
- return _super !== null && _super.apply(this, arguments) || this;
3
+ exports.BST = exports.BSTNode = void 0;
4
+ const types_1 = require("../../types");
5
+ const binary_tree_1 = require("./binary-tree");
6
+ class BSTNode extends binary_tree_1.BinaryTreeNode {
7
+ constructor(id, val) {
8
+ super(id, val);
46
9
  }
47
- BSTNode.prototype.clone = function () {
48
- return new BSTNode(this.id, this.val, this.count);
49
- };
50
- return BSTNode;
51
- }(binary_tree_1.BinaryTreeNode));
10
+ }
52
11
  exports.BSTNode = BSTNode;
53
- var BST = /** @class */ (function (_super) {
54
- __extends(BST, _super);
55
- function BST(options) {
56
- var _this = _super.call(this, options) || this;
57
- _this._comparator = function (a, b) { return a - b; };
12
+ class BST extends binary_tree_1.BinaryTree {
13
+ /**
14
+ * The constructor function initializes a binary search tree object with an optional comparator function.
15
+ * @param {BSTOptions} [options] - An optional object that contains configuration options for the binary search tree.
16
+ */
17
+ constructor(options) {
18
+ super(options);
19
+ this._comparator = (a, b) => a - b;
58
20
  if (options !== undefined) {
59
- var comparator = options.comparator;
21
+ const { comparator } = options;
60
22
  if (comparator !== undefined) {
61
- _this._comparator = comparator;
23
+ this._comparator = comparator;
62
24
  }
63
25
  }
64
- return _this;
65
26
  }
66
- BST.prototype.createNode = function (id, val, count) {
67
- return val !== null ? new BSTNode(id, val, count) : null;
68
- };
69
- BST.prototype.put = function (id, val, count) {
70
- var _a;
71
- if (count === void 0) { count = 1; }
72
- var inserted = null;
73
- var newNode = this.createNode(id, val, count);
27
+ /**
28
+ * The function creates a new binary search tree node with the given id and value.
29
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
30
+ * identify each node in the binary tree.
31
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
32
+ * that will be stored in the node.
33
+ * @returns a new instance of the BSTNode class with the specified id and value.
34
+ */
35
+ createNode(id, val) {
36
+ return new BSTNode(id, val);
37
+ }
38
+ /**
39
+ * The `add` function adds a new node to a binary tree, ensuring that duplicates are not accepted.
40
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add. It
41
+ * is of type `BinaryTreeNodeId`.
42
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node being added. It represents
43
+ * the value associated with the node.
44
+ * @returns The function `add` returns the inserted node (`inserted`) if it was successfully added to the binary tree.
45
+ * If the node was not added (e.g., due to a duplicate ID), it returns `null` or `undefined`.
46
+ */
47
+ add(id, val) {
48
+ // TODO support node as a param
49
+ let inserted = null;
50
+ const newNode = this.createNode(id, val);
74
51
  if (this.root === null) {
75
- this.root = newNode;
76
- this.size++;
77
- this.count += (_a = newNode === null || newNode === void 0 ? void 0 : newNode.count) !== null && _a !== void 0 ? _a : 1;
52
+ this._setRoot(newNode);
53
+ this._setSize(this.size + 1);
78
54
  inserted = (this.root);
79
55
  }
80
56
  else {
81
- var cur = this.root;
82
- var traversing = true;
57
+ let cur = this.root;
58
+ let traversing = true;
83
59
  while (traversing) {
84
60
  if (cur !== null && newNode !== null) {
85
- if (this._compare(cur.id, id) === CP.eq) {
61
+ if (this._compare(cur.id, id) === types_1.CP.eq) {
86
62
  if (newNode) {
87
- cur.count += newNode.count;
88
- this.count += newNode.count;
89
63
  cur.val = newNode.val;
90
64
  }
91
65
  //Duplicates are not accepted.
92
66
  traversing = false;
93
67
  inserted = cur;
94
68
  }
95
- else if (this._compare(cur.id, id) === CP.gt) {
69
+ else if (this._compare(cur.id, id) === types_1.CP.gt) {
96
70
  // Traverse left of the node
97
71
  if (cur.left === undefined) {
98
72
  if (newNode) {
99
73
  newNode.parent = cur;
100
- newNode.familyPosition = binary_tree_1.FamilyPosition.left;
101
74
  }
102
75
  //Add to the left of the current node
103
76
  cur.left = newNode;
104
- this.size++;
105
- this.count += newNode.count;
77
+ this._setSize(this.size + 1);
106
78
  traversing = false;
107
79
  inserted = cur.left;
108
80
  }
@@ -112,17 +84,15 @@ var BST = /** @class */ (function (_super) {
112
84
  cur = cur.left;
113
85
  }
114
86
  }
115
- else if (this._compare(cur.id, id) === CP.lt) {
87
+ else if (this._compare(cur.id, id) === types_1.CP.lt) {
116
88
  // Traverse right of the node
117
89
  if (cur.right === undefined) {
118
90
  if (newNode) {
119
91
  newNode.parent = cur;
120
- newNode.familyPosition = binary_tree_1.FamilyPosition.right;
121
92
  }
122
93
  //Add to the right of the current node
123
94
  cur.right = newNode;
124
- this.size++;
125
- this.count += newNode.count;
95
+ this._setSize(this.size + 1);
126
96
  traversing = false;
127
97
  inserted = (cur.right);
128
98
  }
@@ -139,108 +109,82 @@ var BST = /** @class */ (function (_super) {
139
109
  }
140
110
  }
141
111
  return inserted;
142
- };
143
- BST.prototype.get = function (nodeProperty, propertyName) {
112
+ }
113
+ /**
114
+ * The function returns the first node in a binary tree that matches the given property name and value.
115
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
116
+ * generic type `N`. It represents the property of the binary tree node that you want to search for.
117
+ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
118
+ * specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'id'`.
119
+ * @returns The method is returning either a BinaryTreeNodeId or N (generic type) or null.
120
+ */
121
+ get(nodeProperty, propertyName) {
144
122
  var _a;
145
123
  propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
146
124
  return (_a = this.getNodes(nodeProperty, propertyName, true)[0]) !== null && _a !== void 0 ? _a : null;
147
- };
148
- BST.prototype.lastKey = function () {
125
+ }
126
+ /**
127
+ * The function returns the id of the rightmost node if the comparison between two values is less than, the id of the
128
+ * leftmost node if the comparison is greater than, and the id of the rightmost node otherwise.
129
+ * @returns The method `lastKey()` returns the id of the rightmost node in the binary tree if the comparison between
130
+ * the values at index 0 and 1 is less than, otherwise it returns the id of the leftmost node. If the comparison is
131
+ * equal, it returns the id of the rightmost node. If there are no nodes in the tree, it returns 0.
132
+ */
133
+ lastKey() {
149
134
  var _a, _b, _c, _d, _e, _f;
150
- if (this._compare(0, 1) === CP.lt)
135
+ if (this._compare(0, 1) === types_1.CP.lt)
151
136
  return (_b = (_a = this.getRightMost()) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : 0;
152
- else if (this._compare(0, 1) === CP.gt)
137
+ else if (this._compare(0, 1) === types_1.CP.gt)
153
138
  return (_d = (_c = this.getLeftMost()) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : 0;
154
139
  else
155
140
  return (_f = (_e = this.getRightMost()) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : 0;
156
- };
157
- BST.prototype.remove = function (id, ignoreCount) {
158
- var bstDeletedResult = [];
159
- if (!this.root)
160
- return bstDeletedResult;
161
- var curr = this.get(id);
162
- if (!curr)
163
- return bstDeletedResult;
164
- var parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
165
- var needBalanced = null, orgCurrent = curr;
166
- if (curr.count > 1 && !ignoreCount) {
167
- curr.count--;
168
- this.count--;
169
- }
170
- else {
171
- if (!curr.left) {
172
- if (!parent) {
173
- if (curr.right !== undefined)
174
- this.root = curr.right;
175
- }
176
- else {
177
- switch (curr.familyPosition) {
178
- case binary_tree_1.FamilyPosition.left:
179
- parent.left = curr.right;
180
- break;
181
- case binary_tree_1.FamilyPosition.right:
182
- parent.right = curr.right;
183
- break;
184
- }
185
- needBalanced = parent;
186
- }
187
- }
188
- else {
189
- var leftSubTreeMax = curr.left ? this.getRightMost(curr.left) : null;
190
- if (leftSubTreeMax) {
191
- var parentOfLeftSubTreeMax = leftSubTreeMax.parent;
192
- orgCurrent = curr.swapLocation(leftSubTreeMax);
193
- if (parentOfLeftSubTreeMax) {
194
- if (parentOfLeftSubTreeMax.right === leftSubTreeMax)
195
- parentOfLeftSubTreeMax.right = leftSubTreeMax.left;
196
- else
197
- parentOfLeftSubTreeMax.left = leftSubTreeMax.left;
198
- needBalanced = parentOfLeftSubTreeMax;
199
- }
200
- }
201
- }
202
- this.size--;
203
- this.count -= curr.count;
204
- }
205
- bstDeletedResult.push({ deleted: orgCurrent, needBalanced: needBalanced });
206
- return bstDeletedResult;
207
- };
208
- BST.prototype.getNodes = function (nodeProperty, propertyName, onlyOne) {
209
- var _this = this;
141
+ }
142
+ /**
143
+ * The function `getNodes` returns an array of nodes in a binary tree that match a given property value.
144
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or an
145
+ * `N` type. It represents the property of the binary tree node that you want to compare with.
146
+ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
147
+ * specifies the property name to use for comparison. If not provided, it defaults to `'id'`.
148
+ * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
149
+ * return only one node that matches the given `nodeProperty` or all nodes that match the `nodeProperty`. If `onlyOne`
150
+ * is set to `true`, the function will return an array with only one node (if
151
+ * @returns an array of nodes (type N).
152
+ */
153
+ getNodes(nodeProperty, propertyName, onlyOne) {
210
154
  propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
211
155
  if (!this.root)
212
156
  return [];
213
- var result = [];
214
- if (this._loopType === binary_tree_1.LoopType.recursive) {
215
- var _traverse_1 = function (cur) {
216
- if (_this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
157
+ const result = [];
158
+ if (this.loopType === types_1.LoopType.RECURSIVE) {
159
+ const _traverse = (cur) => {
160
+ if (this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
217
161
  return;
218
162
  if (!cur.left && !cur.right)
219
163
  return;
220
164
  if (propertyName === 'id') {
221
- if (_this._compare(cur.id, nodeProperty) === CP.gt)
222
- cur.left && _traverse_1(cur.left);
223
- if (_this._compare(cur.id, nodeProperty) === CP.lt)
224
- cur.right && _traverse_1(cur.right);
165
+ if (this._compare(cur.id, nodeProperty) === types_1.CP.gt)
166
+ cur.left && _traverse(cur.left);
167
+ if (this._compare(cur.id, nodeProperty) === types_1.CP.lt)
168
+ cur.right && _traverse(cur.right);
225
169
  }
226
170
  else {
227
- cur.left && _traverse_1(cur.left);
228
- cur.right && _traverse_1(cur.right);
171
+ cur.left && _traverse(cur.left);
172
+ cur.right && _traverse(cur.right);
229
173
  }
230
174
  };
231
- _traverse_1(this.root);
175
+ _traverse(this.root);
232
176
  }
233
177
  else {
234
- var queue = [this.root];
178
+ const queue = [this.root];
235
179
  while (queue.length > 0) {
236
- var cur = queue.shift();
180
+ const cur = queue.shift();
237
181
  if (cur) {
238
182
  if (this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
239
183
  return result;
240
184
  if (propertyName === 'id') {
241
- if (this._compare(cur.id, nodeProperty) === CP.gt)
185
+ if (this._compare(cur.id, nodeProperty) === types_1.CP.gt)
242
186
  cur.left && queue.push(cur.left);
243
- if (this._compare(cur.id, nodeProperty) === CP.lt)
187
+ if (this._compare(cur.id, nodeProperty) === types_1.CP.lt)
244
188
  cur.right && queue.push(cur.right);
245
189
  }
246
190
  else {
@@ -251,67 +195,77 @@ var BST = /** @class */ (function (_super) {
251
195
  }
252
196
  }
253
197
  return result;
254
- };
198
+ }
255
199
  // --- start additional functions
256
- BST.prototype.lesserSum = function (id, propertyName) {
257
- var _this = this;
200
+ /**
201
+ * The `lesserSum` function calculates the sum of property values in a binary tree for nodes that have a property value
202
+ * less than a given node.
203
+ * @param {N | BinaryTreeNodeId | null} beginNode - The `beginNode` parameter can be one of the following:
204
+ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
205
+ * specifies the property name to use for calculating the sum. If not provided, it defaults to `'id'`.
206
+ * @returns The function `lesserSum` returns a number, which represents the sum of the values of the nodes in the
207
+ * binary tree that have a lesser value than the specified `beginNode` based on the `propertyName`.
208
+ */
209
+ lesserSum(beginNode, propertyName) {
258
210
  propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
211
+ if (typeof beginNode === 'number')
212
+ beginNode = this.get(beginNode, 'id');
213
+ if (!beginNode)
214
+ return 0;
259
215
  if (!this.root)
260
216
  return 0;
261
- var getSumByPropertyName = function (cur) {
262
- var needSum;
217
+ const id = beginNode.id;
218
+ const getSumByPropertyName = (cur) => {
219
+ let needSum;
263
220
  switch (propertyName) {
264
221
  case 'id':
265
222
  needSum = cur.id;
266
223
  break;
267
- case 'count':
268
- needSum = cur.count;
269
- break;
270
224
  default:
271
225
  needSum = cur.id;
272
226
  break;
273
227
  }
274
228
  return needSum;
275
229
  };
276
- var sum = 0;
277
- if (this._loopType === binary_tree_1.LoopType.recursive) {
278
- var _traverse_2 = function (cur) {
279
- var compared = _this._compare(cur.id, id);
280
- if (compared === CP.eq) {
230
+ let sum = 0;
231
+ if (this.loopType === types_1.LoopType.RECURSIVE) {
232
+ const _traverse = (cur) => {
233
+ const compared = this._compare(cur.id, id);
234
+ if (compared === types_1.CP.eq) {
281
235
  if (cur.right)
282
- sum += _this.subTreeSum(cur.right, propertyName);
236
+ sum += this.subTreeSum(cur.right, propertyName);
283
237
  return;
284
238
  }
285
- else if (compared === CP.lt) {
239
+ else if (compared === types_1.CP.lt) {
286
240
  if (cur.left)
287
- sum += _this.subTreeSum(cur.left, propertyName);
241
+ sum += this.subTreeSum(cur.left, propertyName);
288
242
  sum += getSumByPropertyName(cur);
289
243
  if (cur.right)
290
- _traverse_2(cur.right);
244
+ _traverse(cur.right);
291
245
  else
292
246
  return;
293
247
  }
294
248
  else {
295
249
  if (cur.left)
296
- _traverse_2(cur.left);
250
+ _traverse(cur.left);
297
251
  else
298
252
  return;
299
253
  }
300
254
  };
301
- _traverse_2(this.root);
255
+ _traverse(this.root);
302
256
  }
303
257
  else {
304
- var queue = [this.root];
258
+ const queue = [this.root];
305
259
  while (queue.length > 0) {
306
- var cur = queue.shift();
260
+ const cur = queue.shift();
307
261
  if (cur) {
308
- var compared = this._compare(cur.id, id);
309
- if (compared === CP.eq) {
262
+ const compared = this._compare(cur.id, id);
263
+ if (compared === types_1.CP.eq) {
310
264
  if (cur.right)
311
265
  sum += this.subTreeSum(cur.right, propertyName);
312
266
  return sum;
313
267
  }
314
- else if (compared === CP.lt) { // todo maybe a bug
268
+ else if (compared === types_1.CP.lt) { // todo maybe a bug
315
269
  if (cur.left)
316
270
  sum += this.subTreeSum(cur.left, propertyName);
317
271
  sum += getSumByPropertyName(cur);
@@ -330,84 +284,112 @@ var BST = /** @class */ (function (_super) {
330
284
  }
331
285
  }
332
286
  return sum;
333
- };
334
- BST.prototype.allGreaterNodesAdd = function (node, delta, propertyName) {
335
- var _this = this;
287
+ }
288
+ /**
289
+ * The `allGreaterNodesAdd` function adds a delta value to the specified property of all nodes in a binary tree that
290
+ * have a greater value than a given node.
291
+ * @param {N | BinaryTreeNodeId | null} node - The `node` parameter can be either of type `N` (a generic type),
292
+ * `BinaryTreeNodeId`, or `null`. It represents the node in the binary tree to which the delta value will be added.
293
+ * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
294
+ * each greater node should be increased.
295
+ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
296
+ * specifies the property name of the nodes in the binary tree that you want to update. If not provided, it defaults to
297
+ * 'id'.
298
+ * @returns a boolean value.
299
+ */
300
+ allGreaterNodesAdd(node, delta, propertyName) {
336
301
  propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
302
+ if (typeof node === 'number')
303
+ node = this.get(node, 'id');
304
+ if (!node)
305
+ return false;
306
+ const id = node.id;
337
307
  if (!this.root)
338
308
  return false;
339
- var _sumByPropertyName = function (cur) {
309
+ const _sumByPropertyName = (cur) => {
340
310
  switch (propertyName) {
341
311
  case 'id':
342
312
  cur.id += delta;
343
313
  break;
344
- case 'count':
345
- cur.count += delta;
346
- break;
347
314
  default:
348
315
  cur.id += delta;
349
316
  break;
350
317
  }
351
318
  };
352
- if (this._loopType === binary_tree_1.LoopType.recursive) {
353
- var _traverse_3 = function (cur) {
354
- var compared = _this._compare(cur.id, node.id);
355
- _sumByPropertyName(cur);
319
+ if (this.loopType === types_1.LoopType.RECURSIVE) {
320
+ const _traverse = (cur) => {
321
+ const compared = this._compare(cur.id, id);
322
+ if (compared === types_1.CP.gt)
323
+ _sumByPropertyName(cur);
356
324
  if (!cur.left && !cur.right)
357
325
  return;
358
- if (cur.left && compared === CP.gt)
359
- _traverse_3(cur.left);
360
- else if (cur.right && compared === CP.gt)
361
- _traverse_3(cur.right);
326
+ if (cur.left && this._compare(cur.left.id, id) === types_1.CP.gt)
327
+ _traverse(cur.left);
328
+ if (cur.right && this._compare(cur.right.id, id) === types_1.CP.gt)
329
+ _traverse(cur.right);
362
330
  };
363
- _traverse_3(this.root);
331
+ _traverse(this.root);
364
332
  return true;
365
333
  }
366
334
  else {
367
- var queue = [this.root];
335
+ const queue = [this.root];
368
336
  while (queue.length > 0) {
369
- var cur = queue.shift();
337
+ const cur = queue.shift();
370
338
  if (cur) {
371
- var compared = this._compare(cur.id, node.id);
372
- _sumByPropertyName(cur);
373
- if (cur.left && compared === CP.gt)
339
+ const compared = this._compare(cur.id, id);
340
+ if (compared === types_1.CP.gt)
341
+ _sumByPropertyName(cur);
342
+ if (cur.left && this._compare(cur.left.id, id) === types_1.CP.gt)
374
343
  queue.push(cur.left);
375
- else if (cur.right && compared === CP.gt)
344
+ if (cur.right && this._compare(cur.right.id, id) === types_1.CP.gt)
376
345
  queue.push(cur.right);
377
346
  }
378
347
  }
379
348
  return true;
380
349
  }
381
- };
382
- BST.prototype.balance = function () {
383
- var _this = this;
384
- var sorted = this.DFS('in', 'node'), n = sorted.length;
350
+ }
351
+ /**
352
+ * Balancing Adjustment:
353
+ * Perfectly Balanced Binary Tree: Since the balance of a perfectly balanced binary tree is already fixed, no additional balancing adjustment is needed. Any insertion or deletion operation will disrupt the perfect balance, often requiring a complete reconstruction of the tree.
354
+ * AVL Tree: After insertion or deletion operations, an AVL tree performs rotation adjustments based on the balance factor of nodes to restore the tree's balance. These rotations can be left rotations, right rotations, left-right rotations, or right-left rotations, performed as needed.
355
+ *
356
+ * Use Cases and Efficiency:
357
+ * Perfectly Balanced Binary Tree: Perfectly balanced binary trees are typically used in specific scenarios such as complete binary heaps in heap sort or certain types of Huffman trees. However, they are not suitable for dynamic operations requiring frequent insertions and deletions, as these operations often necessitate full tree reconstruction.
358
+ * AVL Tree: AVL trees are well-suited for scenarios involving frequent searching, insertion, and deletion operations. Through rotation adjustments, AVL trees maintain their balance, ensuring average and worst-case time complexity of O(log n).
359
+ */
360
+ /**
361
+ * The `perfectlyBalance` function takes a binary tree, performs a depth-first search to sort the nodes, and then
362
+ * constructs a balanced binary search tree using either a recursive or iterative approach.
363
+ * @returns The function `perfectlyBalance()` returns a boolean value.
364
+ */
365
+ perfectlyBalance() {
366
+ const sorted = this.DFS('in', 'node'), n = sorted.length;
385
367
  this.clear();
386
368
  if (sorted.length < 1)
387
369
  return false;
388
- if (this._loopType === binary_tree_1.LoopType.recursive) {
389
- var buildBalanceBST_1 = function (l, r) {
370
+ if (this.loopType === types_1.LoopType.RECURSIVE) {
371
+ const buildBalanceBST = (l, r) => {
390
372
  if (l > r)
391
373
  return;
392
- var m = l + Math.floor((r - l) / 2);
393
- var midNode = sorted[m];
394
- _this.put(midNode.id, midNode.val, midNode.count);
395
- buildBalanceBST_1(l, m - 1);
396
- buildBalanceBST_1(m + 1, r);
374
+ const m = l + Math.floor((r - l) / 2);
375
+ const midNode = sorted[m];
376
+ this.add(midNode.id, midNode.val);
377
+ buildBalanceBST(l, m - 1);
378
+ buildBalanceBST(m + 1, r);
397
379
  };
398
- buildBalanceBST_1(0, n - 1);
380
+ buildBalanceBST(0, n - 1);
399
381
  return true;
400
382
  }
401
383
  else {
402
- var stack = [[0, n - 1]];
384
+ const stack = [[0, n - 1]];
403
385
  while (stack.length > 0) {
404
- var popped = stack.pop();
386
+ const popped = stack.pop();
405
387
  if (popped) {
406
- var _a = __read(popped, 2), l = _a[0], r = _a[1];
388
+ const [l, r] = popped;
407
389
  if (l <= r) {
408
- var m = l + Math.floor((r - l) / 2);
409
- var midNode = sorted[m];
410
- this.put(midNode.id, midNode.val, midNode.count);
390
+ const m = l + Math.floor((r - l) / 2);
391
+ const midNode = sorted[m];
392
+ this.add(midNode.id, midNode.val);
411
393
  stack.push([m + 1, r]);
412
394
  stack.push([l, m - 1]);
413
395
  }
@@ -415,27 +397,31 @@ var BST = /** @class */ (function (_super) {
415
397
  }
416
398
  return true;
417
399
  }
418
- };
419
- BST.prototype.isAVLBalanced = function () {
400
+ }
401
+ /**
402
+ * The function `isAVLBalanced` checks if a binary tree is balanced according to the AVL tree property.
403
+ * @returns a boolean value.
404
+ */
405
+ isAVLBalanced() {
420
406
  var _a, _b;
421
407
  if (!this.root)
422
408
  return true;
423
- var balanced = true;
424
- if (this._loopType === binary_tree_1.LoopType.recursive) {
425
- var _height_1 = function (cur) {
409
+ let balanced = true;
410
+ if (this.loopType === types_1.LoopType.RECURSIVE) {
411
+ const _height = (cur) => {
426
412
  if (!cur)
427
413
  return 0;
428
- var leftHeight = _height_1(cur.left), rightHeight = _height_1(cur.right);
414
+ const leftHeight = _height(cur.left), rightHeight = _height(cur.right);
429
415
  if (Math.abs(leftHeight - rightHeight) > 1)
430
416
  balanced = false;
431
417
  return Math.max(leftHeight, rightHeight) + 1;
432
418
  };
433
- _height_1(this.root);
419
+ _height(this.root);
434
420
  }
435
421
  else {
436
- var stack = [];
437
- var node = this.root, last = null;
438
- var depths = new Map();
422
+ const stack = [];
423
+ let node = this.root, last = null;
424
+ const depths = new Map();
439
425
  while (stack.length > 0 || node) {
440
426
  if (node) {
441
427
  stack.push(node);
@@ -446,8 +432,8 @@ var BST = /** @class */ (function (_super) {
446
432
  if (!node.right || last === node.right) {
447
433
  node = stack.pop();
448
434
  if (node) {
449
- var left = node.left ? (_a = depths.get(node.left)) !== null && _a !== void 0 ? _a : -1 : -1;
450
- var right = node.right ? (_b = depths.get(node.right)) !== null && _b !== void 0 ? _b : -1 : -1;
435
+ const left = node.left ? (_a = depths.get(node.left)) !== null && _a !== void 0 ? _a : -1 : -1;
436
+ const right = node.right ? (_b = depths.get(node.right)) !== null && _b !== void 0 ? _b : -1 : -1;
451
437
  if (Math.abs(left - right) > 1)
452
438
  return false;
453
439
  depths.set(node, 1 + Math.max(left, right));
@@ -461,16 +447,23 @@ var BST = /** @class */ (function (_super) {
461
447
  }
462
448
  }
463
449
  return balanced;
464
- };
465
- BST.prototype._compare = function (a, b) {
466
- var compared = this._comparator(a, b);
450
+ }
451
+ /**
452
+ * The function compares two binary tree node IDs using a comparator function and returns whether the first ID is
453
+ * greater than, less than, or equal to the second ID.
454
+ * @param {BinaryTreeNodeId} a - a is a BinaryTreeNodeId, which represents the identifier of a binary tree node.
455
+ * @param {BinaryTreeNodeId} b - The parameter "b" in the above code refers to a BinaryTreeNodeId.
456
+ * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less
457
+ * than), or CP.eq (equal).
458
+ */
459
+ _compare(a, b) {
460
+ const compared = this._comparator(a, b);
467
461
  if (compared > 0)
468
- return CP.gt;
462
+ return types_1.CP.gt;
469
463
  else if (compared < 0)
470
- return CP.lt;
464
+ return types_1.CP.lt;
471
465
  else
472
- return CP.eq;
473
- };
474
- return BST;
475
- }(binary_tree_1.BinaryTree));
466
+ return types_1.CP.eq;
467
+ }
468
+ }
476
469
  exports.BST = BST;