data-structure-typed 1.34.8 → 1.34.9

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 (126) hide show
  1. package/.eslintrc.js +1 -0
  2. package/CHANGELOG.md +1 -1
  3. package/CONTRIBUTING.md +0 -0
  4. package/README.md +8 -8
  5. package/dist/data-structures/binary-tree/aa-tree.js +2 -5
  6. package/dist/data-structures/binary-tree/aa-tree.js.map +1 -1
  7. package/dist/data-structures/binary-tree/abstract-binary-tree.js +280 -423
  8. package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
  9. package/dist/data-structures/binary-tree/avl-tree.js +63 -89
  10. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  11. package/dist/data-structures/binary-tree/b-tree.js +2 -5
  12. package/dist/data-structures/binary-tree/b-tree.js.map +1 -1
  13. package/dist/data-structures/binary-tree/binary-indexed-tree.js +17 -22
  14. package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  15. package/dist/data-structures/binary-tree/binary-tree.js +11 -30
  16. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  17. package/dist/data-structures/binary-tree/bst.js +127 -214
  18. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  19. package/dist/data-structures/binary-tree/rb-tree.js +19 -43
  20. package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
  21. package/dist/data-structures/binary-tree/segment-tree.js +80 -122
  22. package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
  23. package/dist/data-structures/binary-tree/splay-tree.js +2 -5
  24. package/dist/data-structures/binary-tree/splay-tree.js.map +1 -1
  25. package/dist/data-structures/binary-tree/tree-multiset.js +147 -218
  26. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  27. package/dist/data-structures/binary-tree/two-three-tree.js +2 -5
  28. package/dist/data-structures/binary-tree/two-three-tree.js.map +1 -1
  29. package/dist/data-structures/graph/abstract-graph.js +338 -572
  30. package/dist/data-structures/graph/abstract-graph.js.map +1 -1
  31. package/dist/data-structures/graph/directed-graph.js +145 -275
  32. package/dist/data-structures/graph/directed-graph.js.map +1 -1
  33. package/dist/data-structures/graph/map-graph.js +46 -87
  34. package/dist/data-structures/graph/map-graph.js.map +1 -1
  35. package/dist/data-structures/graph/undirected-graph.js +90 -179
  36. package/dist/data-structures/graph/undirected-graph.js.map +1 -1
  37. package/dist/data-structures/hash/coordinate-map.js +23 -45
  38. package/dist/data-structures/hash/coordinate-map.js.map +1 -1
  39. package/dist/data-structures/hash/coordinate-set.js +20 -42
  40. package/dist/data-structures/hash/coordinate-set.js.map +1 -1
  41. package/dist/data-structures/hash/hash-map.js +85 -247
  42. package/dist/data-structures/hash/hash-map.js.map +1 -1
  43. package/dist/data-structures/hash/hash-table.js +87 -128
  44. package/dist/data-structures/hash/hash-table.js.map +1 -1
  45. package/dist/data-structures/hash/pair.js +2 -5
  46. package/dist/data-structures/hash/pair.js.map +1 -1
  47. package/dist/data-structures/hash/tree-map.js +2 -5
  48. package/dist/data-structures/hash/tree-map.js.map +1 -1
  49. package/dist/data-structures/hash/tree-set.js +2 -5
  50. package/dist/data-structures/hash/tree-set.js.map +1 -1
  51. package/dist/data-structures/heap/heap.js +56 -80
  52. package/dist/data-structures/heap/heap.js.map +1 -1
  53. package/dist/data-structures/heap/max-heap.js +8 -26
  54. package/dist/data-structures/heap/max-heap.js.map +1 -1
  55. package/dist/data-structures/heap/min-heap.js +8 -26
  56. package/dist/data-structures/heap/min-heap.js.map +1 -1
  57. package/dist/data-structures/linked-list/doubly-linked-list.js +149 -218
  58. package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  59. package/dist/data-structures/linked-list/singly-linked-list.js +119 -218
  60. package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
  61. package/dist/data-structures/linked-list/skip-linked-list.js +50 -70
  62. package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
  63. package/dist/data-structures/matrix/matrix.js +7 -8
  64. package/dist/data-structures/matrix/matrix.js.map +1 -1
  65. package/dist/data-structures/matrix/matrix2d.js +57 -70
  66. package/dist/data-structures/matrix/matrix2d.js.map +1 -1
  67. package/dist/data-structures/matrix/navigator.js +18 -37
  68. package/dist/data-structures/matrix/navigator.js.map +1 -1
  69. package/dist/data-structures/matrix/vector2d.js +63 -84
  70. package/dist/data-structures/matrix/vector2d.js.map +1 -1
  71. package/dist/data-structures/priority-queue/max-priority-queue.js +13 -41
  72. package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  73. package/dist/data-structures/priority-queue/min-priority-queue.js +13 -41
  74. package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  75. package/dist/data-structures/priority-queue/priority-queue.js +93 -139
  76. package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
  77. package/dist/data-structures/queue/deque.js +82 -128
  78. package/dist/data-structures/queue/deque.js.map +1 -1
  79. package/dist/data-structures/queue/queue.js +57 -157
  80. package/dist/data-structures/queue/queue.js.map +1 -1
  81. package/dist/data-structures/stack/stack.js +21 -22
  82. package/dist/data-structures/stack/stack.js.map +1 -1
  83. package/dist/data-structures/tree/tree.js +32 -45
  84. package/dist/data-structures/tree/tree.js.map +1 -1
  85. package/dist/data-structures/trie/trie.js +93 -200
  86. package/dist/data-structures/trie/trie.js.map +1 -1
  87. package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
  88. package/dist/utils/utils.js +22 -107
  89. package/dist/utils/utils.js.map +1 -1
  90. package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +79 -78
  91. package/lib/data-structures/binary-tree/abstract-binary-tree.js +61 -141
  92. package/lib/data-structures/binary-tree/avl-tree.d.ts +9 -0
  93. package/lib/data-structures/binary-tree/avl-tree.js +22 -0
  94. package/lib/data-structures/binary-tree/bst.d.ts +3 -3
  95. package/lib/data-structures/binary-tree/bst.js +12 -15
  96. package/lib/data-structures/binary-tree/tree-multiset.d.ts +16 -18
  97. package/lib/data-structures/binary-tree/tree-multiset.js +26 -36
  98. package/lib/data-structures/graph/abstract-graph.d.ts +2 -2
  99. package/lib/data-structures/graph/abstract-graph.js +5 -5
  100. package/lib/data-structures/priority-queue/priority-queue.d.ts +3 -3
  101. package/lib/data-structures/priority-queue/priority-queue.js +3 -3
  102. package/lib/interfaces/abstract-binary-tree.d.ts +23 -28
  103. package/lib/interfaces/avl-tree.d.ts +3 -1
  104. package/lib/interfaces/bst.d.ts +2 -1
  105. package/lib/types/data-structures/abstract-binary-tree.js +0 -1
  106. package/package.json +6 -6
  107. package/src/data-structures/binary-tree/abstract-binary-tree.ts +151 -203
  108. package/src/data-structures/binary-tree/avl-tree.ts +29 -0
  109. package/src/data-structures/binary-tree/bst.ts +12 -15
  110. package/src/data-structures/binary-tree/tree-multiset.ts +27 -39
  111. package/src/data-structures/graph/abstract-graph.ts +5 -5
  112. package/src/data-structures/priority-queue/priority-queue.ts +3 -3
  113. package/src/interfaces/abstract-binary-tree.ts +23 -36
  114. package/src/interfaces/avl-tree.ts +3 -1
  115. package/src/interfaces/bst.ts +1 -1
  116. package/src/types/data-structures/abstract-binary-tree.ts +0 -1
  117. package/test/integration/avl-tree.test.ts +24 -24
  118. package/test/integration/bst.test.ts +71 -71
  119. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
  120. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +1 -9
  121. package/test/unit/data-structures/binary-tree/bst.test.ts +8 -8
  122. package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
  123. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +9 -9
  124. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +4 -4
  125. package/umd/bundle.min.js +1 -1
  126. package/umd/bundle.min.js.map +1 -1
@@ -1,225 +1,118 @@
1
1
  "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
2
  Object.defineProperty(exports, "__esModule", { value: true });
19
3
  exports.AbstractBinaryTree = exports.AbstractBinaryTreeNode = void 0;
20
- var utils_1 = require("../../utils");
21
- var types_1 = require("../../types");
22
- var AbstractBinaryTreeNode = (function () {
23
- function AbstractBinaryTreeNode(key, val) {
24
- this._height = 0;
25
- this._key = key;
26
- this._val = val;
27
- }
28
- Object.defineProperty(AbstractBinaryTreeNode.prototype, "key", {
29
- get: function () {
30
- return this._key;
31
- },
32
- set: function (v) {
33
- this._key = v;
34
- },
35
- enumerable: false,
36
- configurable: true
37
- });
38
- Object.defineProperty(AbstractBinaryTreeNode.prototype, "val", {
39
- get: function () {
40
- return this._val;
41
- },
42
- set: function (value) {
43
- this._val = value;
44
- },
45
- enumerable: false,
46
- configurable: true
47
- });
48
- Object.defineProperty(AbstractBinaryTreeNode.prototype, "left", {
49
- get: function () {
50
- return this._left;
51
- },
52
- set: function (v) {
53
- if (v) {
54
- v.parent = this;
55
- }
56
- this._left = v;
57
- },
58
- enumerable: false,
59
- configurable: true
60
- });
61
- Object.defineProperty(AbstractBinaryTreeNode.prototype, "right", {
62
- get: function () {
63
- return this._right;
64
- },
65
- set: function (v) {
66
- if (v) {
67
- v.parent = this;
68
- }
69
- this._right = v;
70
- },
71
- enumerable: false,
72
- configurable: true
73
- });
74
- Object.defineProperty(AbstractBinaryTreeNode.prototype, "parent", {
75
- get: function () {
76
- return this._parent;
77
- },
78
- set: function (v) {
79
- this._parent = v;
80
- },
81
- enumerable: false,
82
- configurable: true
83
- });
84
- Object.defineProperty(AbstractBinaryTreeNode.prototype, "height", {
85
- get: function () {
86
- return this._height;
87
- },
88
- set: function (v) {
89
- this._height = v;
90
- },
91
- enumerable: false,
92
- configurable: true
93
- });
94
- Object.defineProperty(AbstractBinaryTreeNode.prototype, "familyPosition", {
95
- get: function () {
96
- var that = this;
97
- if (that.parent) {
98
- if (that.parent.left === that) {
99
- if (that.left || that.right) {
100
- return types_1.FamilyPosition.ROOT_LEFT;
101
- }
102
- else {
103
- return types_1.FamilyPosition.LEFT;
104
- }
105
- }
106
- else if (that.parent.right === that) {
107
- if (that.left || that.right) {
108
- return types_1.FamilyPosition.ROOT_RIGHT;
109
- }
110
- else {
111
- return types_1.FamilyPosition.RIGHT;
112
- }
4
+ const utils_1 = require("../../utils");
5
+ const types_1 = require("../../types");
6
+ class AbstractBinaryTreeNode {
7
+ constructor(key, val) {
8
+ this.key = key;
9
+ this.val = val;
10
+ }
11
+ get left() {
12
+ return this._left;
13
+ }
14
+ set left(v) {
15
+ if (v) {
16
+ v.parent = this;
17
+ }
18
+ this._left = v;
19
+ }
20
+ get right() {
21
+ return this._right;
22
+ }
23
+ set right(v) {
24
+ if (v) {
25
+ v.parent = this;
26
+ }
27
+ this._right = v;
28
+ }
29
+ get familyPosition() {
30
+ const that = this;
31
+ if (that.parent) {
32
+ if (that.parent.left === that) {
33
+ if (that.left || that.right) {
34
+ return types_1.FamilyPosition.ROOT_LEFT;
113
35
  }
114
36
  else {
115
- return types_1.FamilyPosition.MAL_NODE;
37
+ return types_1.FamilyPosition.LEFT;
116
38
  }
117
39
  }
118
- else {
40
+ else if (that.parent.right === that) {
119
41
  if (that.left || that.right) {
120
- return types_1.FamilyPosition.ROOT;
42
+ return types_1.FamilyPosition.ROOT_RIGHT;
121
43
  }
122
44
  else {
123
- return types_1.FamilyPosition.ISOLATED;
45
+ return types_1.FamilyPosition.RIGHT;
124
46
  }
125
47
  }
126
- },
127
- enumerable: false,
128
- configurable: true
129
- });
130
- return AbstractBinaryTreeNode;
131
- }());
48
+ else {
49
+ return types_1.FamilyPosition.MAL_NODE;
50
+ }
51
+ }
52
+ else {
53
+ if (that.left || that.right) {
54
+ return types_1.FamilyPosition.ROOT;
55
+ }
56
+ else {
57
+ return types_1.FamilyPosition.ISOLATED;
58
+ }
59
+ }
60
+ }
61
+ }
132
62
  exports.AbstractBinaryTreeNode = AbstractBinaryTreeNode;
133
- var AbstractBinaryTree = (function () {
134
- function AbstractBinaryTree(options) {
63
+ class AbstractBinaryTree {
64
+ constructor(options) {
135
65
  this._root = null;
136
66
  this._size = 0;
137
67
  this._loopType = types_1.LoopType.ITERATIVE;
138
- this._visitedKey = [];
139
- this._visitedVal = [];
140
- this._visitedNode = [];
68
+ this.visitedKey = [];
69
+ this.visitedVal = [];
70
+ this.visitedNode = [];
141
71
  if (options !== undefined) {
142
- var _a = options.loopType, loopType = _a === void 0 ? types_1.LoopType.ITERATIVE : _a;
72
+ const { loopType = types_1.LoopType.ITERATIVE } = options;
143
73
  this._loopType = loopType;
144
74
  }
145
75
  this.clear();
146
76
  }
147
- Object.defineProperty(AbstractBinaryTree.prototype, "root", {
148
- get: function () {
149
- return this._root;
150
- },
151
- enumerable: false,
152
- configurable: true
153
- });
154
- Object.defineProperty(AbstractBinaryTree.prototype, "size", {
155
- get: function () {
156
- return this._size;
157
- },
158
- enumerable: false,
159
- configurable: true
160
- });
161
- Object.defineProperty(AbstractBinaryTree.prototype, "loopType", {
162
- get: function () {
163
- return this._loopType;
164
- },
165
- enumerable: false,
166
- configurable: true
167
- });
168
- Object.defineProperty(AbstractBinaryTree.prototype, "visitedKey", {
169
- get: function () {
170
- return this._visitedKey;
171
- },
172
- enumerable: false,
173
- configurable: true
174
- });
175
- Object.defineProperty(AbstractBinaryTree.prototype, "visitedVal", {
176
- get: function () {
177
- return this._visitedVal;
178
- },
179
- enumerable: false,
180
- configurable: true
181
- });
182
- Object.defineProperty(AbstractBinaryTree.prototype, "visitedNode", {
183
- get: function () {
184
- return this._visitedNode;
185
- },
186
- enumerable: false,
187
- configurable: true
188
- });
189
- AbstractBinaryTree.prototype.swapLocation = function (srcNode, destNode) {
190
- var key = destNode.key, val = destNode.val, height = destNode.height;
191
- var tempNode = this.createNode(key, val);
77
+ get root() {
78
+ return this._root;
79
+ }
80
+ get size() {
81
+ return this._size;
82
+ }
83
+ get loopType() {
84
+ return this._loopType;
85
+ }
86
+ swapLocation(srcNode, destNode) {
87
+ const { key, val } = destNode;
88
+ const tempNode = this.createNode(key, val);
192
89
  if (tempNode) {
193
- tempNode.height = height;
194
90
  destNode.key = srcNode.key;
195
91
  destNode.val = srcNode.val;
196
- destNode.height = srcNode.height;
197
92
  srcNode.key = tempNode.key;
198
93
  srcNode.val = tempNode.val;
199
- srcNode.height = tempNode.height;
200
94
  }
201
95
  return destNode;
202
- };
203
- AbstractBinaryTree.prototype.clear = function () {
96
+ }
97
+ clear() {
204
98
  this._root = null;
205
99
  this._size = 0;
206
100
  this._clearResults();
207
- };
208
- AbstractBinaryTree.prototype.isEmpty = function () {
101
+ }
102
+ isEmpty() {
209
103
  return this.size === 0;
210
- };
211
- AbstractBinaryTree.prototype.add = function (keyOrNode, val) {
212
- var _this = this;
213
- var _bfs = function (root, newNode) {
214
- var queue = [root];
104
+ }
105
+ add(keyOrNode, val) {
106
+ const _bfs = (root, newNode) => {
107
+ const queue = [root];
215
108
  while (queue.length > 0) {
216
- var cur = queue.shift();
109
+ const cur = queue.shift();
217
110
  if (cur) {
218
111
  if (newNode && cur.key === newNode.key)
219
112
  return;
220
- var inserted_1 = _this._addTo(newNode, cur);
221
- if (inserted_1 !== undefined)
222
- return inserted_1;
113
+ const inserted = this._addTo(newNode, cur);
114
+ if (inserted !== undefined)
115
+ return inserted;
223
116
  if (cur.left)
224
117
  queue.push(cur.left);
225
118
  if (cur.right)
@@ -230,7 +123,7 @@ var AbstractBinaryTree = (function () {
230
123
  }
231
124
  return;
232
125
  };
233
- var inserted, needInsert;
126
+ let inserted, needInsert;
234
127
  if (keyOrNode === null) {
235
128
  needInsert = null;
236
129
  }
@@ -243,7 +136,7 @@ var AbstractBinaryTree = (function () {
243
136
  else {
244
137
  return;
245
138
  }
246
- var existNode = keyOrNode ? this.get(keyOrNode, 'key') : undefined;
139
+ const existNode = keyOrNode ? this.get(keyOrNode, 'key') : undefined;
247
140
  if (this.root) {
248
141
  if (existNode) {
249
142
  existNode.val = val;
@@ -264,11 +157,11 @@ var AbstractBinaryTree = (function () {
264
157
  inserted = this.root;
265
158
  }
266
159
  return inserted;
267
- };
268
- AbstractBinaryTree.prototype.addMany = function (idsOrNodes, data) {
269
- var inserted = [];
270
- for (var i = 0; i < idsOrNodes.length; i++) {
271
- var keyOrNode = idsOrNodes[i];
160
+ }
161
+ addMany(keysOrNodes, data) {
162
+ const inserted = [];
163
+ for (let i = 0; i < keysOrNodes.length; i++) {
164
+ const keyOrNode = keysOrNodes[i];
272
165
  if (keyOrNode instanceof AbstractBinaryTreeNode) {
273
166
  inserted.push(this.add(keyOrNode.key, keyOrNode.val));
274
167
  continue;
@@ -277,31 +170,31 @@ var AbstractBinaryTree = (function () {
277
170
  inserted.push(this.add(null));
278
171
  continue;
279
172
  }
280
- var val = data === null || data === void 0 ? void 0 : data[i];
173
+ const val = data === null || data === void 0 ? void 0 : data[i];
281
174
  inserted.push(this.add(keyOrNode, val));
282
175
  }
283
176
  return inserted;
284
- };
285
- AbstractBinaryTree.prototype.fill = function (idsOrNodes, data) {
177
+ }
178
+ refill(keysOrNodes, data) {
286
179
  this.clear();
287
- return idsOrNodes.length === this.addMany(idsOrNodes, data).length;
288
- };
289
- AbstractBinaryTree.prototype.remove = function (nodeOrKey) {
290
- var bstDeletedResult = [];
180
+ return keysOrNodes.length === this.addMany(keysOrNodes, data).length;
181
+ }
182
+ remove(nodeOrKey) {
183
+ const bstDeletedResult = [];
291
184
  if (!this.root)
292
185
  return bstDeletedResult;
293
- var curr = typeof nodeOrKey === 'number' ? this.get(nodeOrKey) : nodeOrKey;
186
+ const curr = typeof nodeOrKey === 'number' ? this.get(nodeOrKey) : nodeOrKey;
294
187
  if (!curr)
295
188
  return bstDeletedResult;
296
- var parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
297
- var needBalanced = null, orgCurrent = curr;
189
+ const parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
190
+ let needBalanced = null, orgCurrent = curr;
298
191
  if (!curr.left) {
299
192
  if (!parent) {
300
193
  if (curr.right !== undefined)
301
194
  this._setRoot(curr.right);
302
195
  }
303
196
  else {
304
- var fp = curr.familyPosition;
197
+ const { familyPosition: fp } = curr;
305
198
  if (fp === types_1.FamilyPosition.LEFT || fp === types_1.FamilyPosition.ROOT_LEFT) {
306
199
  parent.left = curr.right;
307
200
  }
@@ -312,9 +205,9 @@ var AbstractBinaryTree = (function () {
312
205
  }
313
206
  }
314
207
  else {
315
- var leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
208
+ const leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
316
209
  if (leftSubTreeRightMost) {
317
- var parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
210
+ const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
318
211
  orgCurrent = this.swapLocation(curr, leftSubTreeRightMost);
319
212
  if (parentOfLeftSubTreeMax) {
320
213
  if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
@@ -326,43 +219,42 @@ var AbstractBinaryTree = (function () {
326
219
  }
327
220
  }
328
221
  this._setSize(this.size - 1);
329
- bstDeletedResult.push({ deleted: orgCurrent, needBalanced: needBalanced });
222
+ bstDeletedResult.push({ deleted: orgCurrent, needBalanced });
330
223
  return bstDeletedResult;
331
- };
332
- AbstractBinaryTree.prototype.getDepth = function (beginRoot) {
224
+ }
225
+ getDepth(beginRoot = this.root) {
333
226
  if (typeof beginRoot === 'number')
334
227
  beginRoot = this.get(beginRoot, 'key');
335
- var depth = 0;
228
+ let depth = 0;
336
229
  while (beginRoot === null || beginRoot === void 0 ? void 0 : beginRoot.parent) {
337
230
  depth++;
338
231
  beginRoot = beginRoot.parent;
339
232
  }
340
233
  return depth;
341
- };
342
- AbstractBinaryTree.prototype.getHeight = function (beginRoot) {
343
- beginRoot = beginRoot !== null && beginRoot !== void 0 ? beginRoot : this.root;
234
+ }
235
+ getHeight(beginRoot = this.root) {
344
236
  if (typeof beginRoot === 'number')
345
237
  beginRoot = this.get(beginRoot, 'key');
346
238
  if (!beginRoot)
347
239
  return -1;
348
240
  if (this._loopType === types_1.LoopType.RECURSIVE) {
349
- var _getMaxHeight_1 = function (cur) {
241
+ const _getMaxHeight = (cur) => {
350
242
  if (!cur)
351
243
  return -1;
352
- var leftHeight = _getMaxHeight_1(cur.left);
353
- var rightHeight = _getMaxHeight_1(cur.right);
244
+ const leftHeight = _getMaxHeight(cur.left);
245
+ const rightHeight = _getMaxHeight(cur.right);
354
246
  return Math.max(leftHeight, rightHeight) + 1;
355
247
  };
356
- return _getMaxHeight_1(beginRoot);
248
+ return _getMaxHeight(beginRoot);
357
249
  }
358
250
  else {
359
251
  if (!beginRoot) {
360
252
  return -1;
361
253
  }
362
- var stack = [{ node: beginRoot, depth: 0 }];
363
- var maxHeight = 0;
254
+ const stack = [{ node: beginRoot, depth: 0 }];
255
+ let maxHeight = 0;
364
256
  while (stack.length > 0) {
365
- var _a = stack.pop(), node = _a.node, depth = _a.depth;
257
+ const { node, depth } = stack.pop();
366
258
  if (node.left) {
367
259
  stack.push({ node: node.left, depth: depth + 1 });
368
260
  }
@@ -373,28 +265,27 @@ var AbstractBinaryTree = (function () {
373
265
  }
374
266
  return maxHeight;
375
267
  }
376
- };
377
- AbstractBinaryTree.prototype.getMinHeight = function (beginRoot) {
268
+ }
269
+ getMinHeight(beginRoot = this.root) {
378
270
  var _a, _b, _c;
379
- beginRoot = beginRoot || this.root;
380
271
  if (!beginRoot)
381
272
  return -1;
382
273
  if (this._loopType === types_1.LoopType.RECURSIVE) {
383
- var _getMinHeight_1 = function (cur) {
274
+ const _getMinHeight = (cur) => {
384
275
  if (!cur)
385
276
  return 0;
386
277
  if (!cur.left && !cur.right)
387
278
  return 0;
388
- var leftMinHeight = _getMinHeight_1(cur.left);
389
- var rightMinHeight = _getMinHeight_1(cur.right);
279
+ const leftMinHeight = _getMinHeight(cur.left);
280
+ const rightMinHeight = _getMinHeight(cur.right);
390
281
  return Math.min(leftMinHeight, rightMinHeight) + 1;
391
282
  };
392
- return _getMinHeight_1(beginRoot);
283
+ return _getMinHeight(beginRoot);
393
284
  }
394
285
  else {
395
- var stack = [];
396
- var node = beginRoot, last = null;
397
- var depths = new Map();
286
+ const stack = [];
287
+ let node = beginRoot, last = null;
288
+ const depths = new Map();
398
289
  while (stack.length > 0 || node) {
399
290
  if (node) {
400
291
  stack.push(node);
@@ -405,8 +296,8 @@ var AbstractBinaryTree = (function () {
405
296
  if (!node.right || last === node.right) {
406
297
  node = stack.pop();
407
298
  if (node) {
408
- var leftMinHeight = node.left ? (_a = depths.get(node.left)) !== null && _a !== void 0 ? _a : -1 : -1;
409
- var rightMinHeight = node.right ? (_b = depths.get(node.right)) !== null && _b !== void 0 ? _b : -1 : -1;
299
+ const leftMinHeight = node.left ? (_a = depths.get(node.left)) !== null && _a !== void 0 ? _a : -1 : -1;
300
+ const rightMinHeight = node.right ? (_b = depths.get(node.right)) !== null && _b !== void 0 ? _b : -1 : -1;
410
301
  depths.set(node, 1 + Math.min(leftMinHeight, rightMinHeight));
411
302
  last = node;
412
303
  node = null;
@@ -418,31 +309,29 @@ var AbstractBinaryTree = (function () {
418
309
  }
419
310
  return (_c = depths.get(beginRoot)) !== null && _c !== void 0 ? _c : -1;
420
311
  }
421
- };
422
- AbstractBinaryTree.prototype.isPerfectlyBalanced = function (beginRoot) {
312
+ }
313
+ isPerfectlyBalanced(beginRoot = this.root) {
423
314
  return this.getMinHeight(beginRoot) + 1 >= this.getHeight(beginRoot);
424
- };
425
- AbstractBinaryTree.prototype.getNodes = function (nodeProperty, propertyName, onlyOne) {
426
- var _this = this;
315
+ }
316
+ getNodes(nodeProperty, propertyName = 'key', onlyOne = false) {
427
317
  if (!this.root)
428
318
  return [];
429
- propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
430
- var result = [];
319
+ const result = [];
431
320
  if (this.loopType === types_1.LoopType.RECURSIVE) {
432
- var _traverse_1 = function (cur) {
433
- if (_this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
321
+ const _traverse = (cur) => {
322
+ if (this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
434
323
  return;
435
324
  if (!cur.left && !cur.right)
436
325
  return;
437
- cur.left && _traverse_1(cur.left);
438
- cur.right && _traverse_1(cur.right);
326
+ cur.left && _traverse(cur.left);
327
+ cur.right && _traverse(cur.right);
439
328
  };
440
- _traverse_1(this.root);
329
+ _traverse(this.root);
441
330
  }
442
331
  else {
443
- var queue = [this.root];
332
+ const queue = [this.root];
444
333
  while (queue.length > 0) {
445
- var cur = queue.shift();
334
+ const cur = queue.shift();
446
335
  if (cur) {
447
336
  if (this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
448
337
  return result;
@@ -452,86 +341,81 @@ var AbstractBinaryTree = (function () {
452
341
  }
453
342
  }
454
343
  return result;
455
- };
456
- AbstractBinaryTree.prototype.has = function (nodeProperty, propertyName) {
457
- propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
344
+ }
345
+ has(nodeProperty, propertyName = 'key') {
458
346
  return this.getNodes(nodeProperty, propertyName).length > 0;
459
- };
460
- AbstractBinaryTree.prototype.get = function (nodeProperty, propertyName) {
347
+ }
348
+ get(nodeProperty, propertyName = 'key') {
461
349
  var _a;
462
- propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
463
350
  return (_a = this.getNodes(nodeProperty, propertyName, true)[0]) !== null && _a !== void 0 ? _a : null;
464
- };
465
- AbstractBinaryTree.prototype.getPathToRoot = function (node, isReverse) {
466
- if (isReverse === void 0) { isReverse = true; }
467
- var result = [];
351
+ }
352
+ getPathToRoot(node, isReverse = true) {
353
+ const result = [];
468
354
  while (node.parent) {
469
355
  result.push(node);
470
356
  node = node.parent;
471
357
  }
472
358
  result.push(node);
473
359
  return isReverse ? result.reverse() : result;
474
- };
475
- AbstractBinaryTree.prototype.getLeftMost = function (beginRoot) {
360
+ }
361
+ getLeftMost(beginRoot = this.root) {
476
362
  if (typeof beginRoot === 'number')
477
363
  beginRoot = this.get(beginRoot, 'key');
478
- beginRoot = beginRoot !== null && beginRoot !== void 0 ? beginRoot : this.root;
479
364
  if (!beginRoot)
480
365
  return beginRoot;
481
366
  if (this._loopType === types_1.LoopType.RECURSIVE) {
482
- var _traverse_2 = function (cur) {
367
+ const _traverse = (cur) => {
483
368
  if (!cur.left)
484
369
  return cur;
485
- return _traverse_2(cur.left);
370
+ return _traverse(cur.left);
486
371
  };
487
- return _traverse_2(beginRoot);
372
+ return _traverse(beginRoot);
488
373
  }
489
374
  else {
490
- var _traverse_3 = (0, utils_1.trampoline)(function (cur) {
375
+ const _traverse = (0, utils_1.trampoline)((cur) => {
491
376
  if (!cur.left)
492
377
  return cur;
493
- return _traverse_3.cont(cur.left);
378
+ return _traverse.cont(cur.left);
494
379
  });
495
- return _traverse_3(beginRoot);
380
+ return _traverse(beginRoot);
496
381
  }
497
- };
498
- AbstractBinaryTree.prototype.getRightMost = function (node) {
499
- node = node !== null && node !== void 0 ? node : this.root;
500
- if (!node)
501
- return node;
382
+ }
383
+ getRightMost(beginRoot = this.root) {
384
+ if (!beginRoot)
385
+ return beginRoot;
502
386
  if (this._loopType === types_1.LoopType.RECURSIVE) {
503
- var _traverse_4 = function (cur) {
387
+ const _traverse = (cur) => {
504
388
  if (!cur.right)
505
389
  return cur;
506
- return _traverse_4(cur.right);
390
+ return _traverse(cur.right);
507
391
  };
508
- return _traverse_4(node);
392
+ return _traverse(beginRoot);
509
393
  }
510
394
  else {
511
- var _traverse_5 = (0, utils_1.trampoline)(function (cur) {
395
+ const _traverse = (0, utils_1.trampoline)((cur) => {
512
396
  if (!cur.right)
513
397
  return cur;
514
- return _traverse_5.cont(cur.right);
398
+ return _traverse.cont(cur.right);
515
399
  });
516
- return _traverse_5(node);
400
+ return _traverse(beginRoot);
517
401
  }
518
- };
519
- AbstractBinaryTree.prototype.isSubtreeBST = function (node) {
402
+ }
403
+ isSubtreeBST(node) {
520
404
  if (!node)
521
405
  return true;
522
406
  if (this._loopType === types_1.LoopType.RECURSIVE) {
523
- var dfs_1 = function (cur, min, max) {
407
+ const dfs = (cur, min, max) => {
524
408
  if (!cur)
525
409
  return true;
526
410
  if (cur.key <= min || cur.key >= max)
527
411
  return false;
528
- return dfs_1(cur.left, min, cur.key) && dfs_1(cur.right, cur.key, max);
412
+ return dfs(cur.left, min, cur.key) && dfs(cur.right, cur.key, max);
529
413
  };
530
- return dfs_1(node, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
414
+ return dfs(node, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
531
415
  }
532
416
  else {
533
- var stack = [];
534
- var prev = Number.MIN_SAFE_INTEGER, curr = node;
417
+ const stack = [];
418
+ let prev = Number.MIN_SAFE_INTEGER, curr = node;
535
419
  while (curr || stack.length > 0) {
536
420
  while (curr) {
537
421
  stack.push(curr);
@@ -545,43 +429,42 @@ var AbstractBinaryTree = (function () {
545
429
  }
546
430
  return true;
547
431
  }
548
- };
549
- AbstractBinaryTree.prototype.isBST = function () {
432
+ }
433
+ isBST() {
550
434
  return this.isSubtreeBST(this.root);
551
- };
552
- AbstractBinaryTree.prototype.getSubTreeSize = function (subTreeRoot) {
553
- var size = 0;
435
+ }
436
+ getSubTreeSize(subTreeRoot) {
437
+ let size = 0;
554
438
  if (!subTreeRoot)
555
439
  return size;
556
440
  if (this._loopType === types_1.LoopType.RECURSIVE) {
557
- var _traverse_6 = function (cur) {
441
+ const _traverse = (cur) => {
558
442
  size++;
559
- cur.left && _traverse_6(cur.left);
560
- cur.right && _traverse_6(cur.right);
443
+ cur.left && _traverse(cur.left);
444
+ cur.right && _traverse(cur.right);
561
445
  };
562
- _traverse_6(subTreeRoot);
446
+ _traverse(subTreeRoot);
563
447
  return size;
564
448
  }
565
449
  else {
566
- var stack = [subTreeRoot];
450
+ const stack = [subTreeRoot];
567
451
  while (stack.length > 0) {
568
- var cur = stack.pop();
452
+ const cur = stack.pop();
569
453
  size++;
570
454
  cur.right && stack.push(cur.right);
571
455
  cur.left && stack.push(cur.left);
572
456
  }
573
457
  return size;
574
458
  }
575
- };
576
- AbstractBinaryTree.prototype.subTreeSum = function (subTreeRoot, propertyName) {
577
- propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
459
+ }
460
+ subTreeSum(subTreeRoot, propertyName = 'key') {
578
461
  if (typeof subTreeRoot === 'number')
579
462
  subTreeRoot = this.get(subTreeRoot, 'key');
580
463
  if (!subTreeRoot)
581
464
  return 0;
582
- var sum = 0;
583
- var _sumByProperty = function (cur) {
584
- var needSum;
465
+ let sum = 0;
466
+ const _sumByProperty = (cur) => {
467
+ let needSum;
585
468
  switch (propertyName) {
586
469
  case 'key':
587
470
  needSum = cur.key;
@@ -596,31 +479,30 @@ var AbstractBinaryTree = (function () {
596
479
  return needSum;
597
480
  };
598
481
  if (this._loopType === types_1.LoopType.RECURSIVE) {
599
- var _traverse_7 = function (cur) {
482
+ const _traverse = (cur) => {
600
483
  sum += _sumByProperty(cur);
601
- cur.left && _traverse_7(cur.left);
602
- cur.right && _traverse_7(cur.right);
484
+ cur.left && _traverse(cur.left);
485
+ cur.right && _traverse(cur.right);
603
486
  };
604
- _traverse_7(subTreeRoot);
487
+ _traverse(subTreeRoot);
605
488
  }
606
489
  else {
607
- var stack = [subTreeRoot];
490
+ const stack = [subTreeRoot];
608
491
  while (stack.length > 0) {
609
- var cur = stack.pop();
492
+ const cur = stack.pop();
610
493
  sum += _sumByProperty(cur);
611
494
  cur.right && stack.push(cur.right);
612
495
  cur.left && stack.push(cur.left);
613
496
  }
614
497
  }
615
498
  return sum;
616
- };
617
- AbstractBinaryTree.prototype.subTreeAdd = function (subTreeRoot, delta, propertyName) {
618
- propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
499
+ }
500
+ subTreeAdd(subTreeRoot, delta, propertyName = 'key') {
619
501
  if (typeof subTreeRoot === 'number')
620
502
  subTreeRoot = this.get(subTreeRoot, 'key');
621
503
  if (!subTreeRoot)
622
504
  return false;
623
- var _addByProperty = function (cur) {
505
+ const _addByProperty = (cur) => {
624
506
  switch (propertyName) {
625
507
  case 'key':
626
508
  cur.key += delta;
@@ -631,30 +513,29 @@ var AbstractBinaryTree = (function () {
631
513
  }
632
514
  };
633
515
  if (this._loopType === types_1.LoopType.RECURSIVE) {
634
- var _traverse_8 = function (cur) {
516
+ const _traverse = (cur) => {
635
517
  _addByProperty(cur);
636
- cur.left && _traverse_8(cur.left);
637
- cur.right && _traverse_8(cur.right);
518
+ cur.left && _traverse(cur.left);
519
+ cur.right && _traverse(cur.right);
638
520
  };
639
- _traverse_8(subTreeRoot);
521
+ _traverse(subTreeRoot);
640
522
  }
641
523
  else {
642
- var stack = [subTreeRoot];
524
+ const stack = [subTreeRoot];
643
525
  while (stack.length > 0) {
644
- var cur = stack.pop();
526
+ const cur = stack.pop();
645
527
  _addByProperty(cur);
646
528
  cur.right && stack.push(cur.right);
647
529
  cur.left && stack.push(cur.left);
648
530
  }
649
531
  }
650
532
  return true;
651
- };
652
- AbstractBinaryTree.prototype.BFS = function (nodeOrPropertyName) {
653
- nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'key';
533
+ }
534
+ bfs(nodeOrPropertyName = 'key') {
654
535
  this._clearResults();
655
- var queue = [this.root];
536
+ const queue = [this.root];
656
537
  while (queue.length !== 0) {
657
- var cur = queue.shift();
538
+ const cur = queue.shift();
658
539
  if (cur) {
659
540
  this._accumulatedByPropertyName(cur, nodeOrPropertyName);
660
541
  if ((cur === null || cur === void 0 ? void 0 : cur.left) !== null)
@@ -664,23 +545,20 @@ var AbstractBinaryTree = (function () {
664
545
  }
665
546
  }
666
547
  return this._getResultByPropertyName(nodeOrPropertyName);
667
- };
668
- AbstractBinaryTree.prototype.DFS = function (pattern, nodeOrPropertyName) {
669
- var _this = this;
670
- pattern = pattern !== null && pattern !== void 0 ? pattern : 'in';
671
- nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'key';
548
+ }
549
+ dfs(pattern = 'in', nodeOrPropertyName = 'key') {
672
550
  this._clearResults();
673
- var _traverse = function (node) {
551
+ const _traverse = (node) => {
674
552
  switch (pattern) {
675
553
  case 'in':
676
554
  if (node.left)
677
555
  _traverse(node.left);
678
- _this._accumulatedByPropertyName(node, nodeOrPropertyName);
556
+ this._accumulatedByPropertyName(node, nodeOrPropertyName);
679
557
  if (node.right)
680
558
  _traverse(node.right);
681
559
  break;
682
560
  case 'pre':
683
- _this._accumulatedByPropertyName(node, nodeOrPropertyName);
561
+ this._accumulatedByPropertyName(node, nodeOrPropertyName);
684
562
  if (node.left)
685
563
  _traverse(node.left);
686
564
  if (node.right)
@@ -691,22 +569,20 @@ var AbstractBinaryTree = (function () {
691
569
  _traverse(node.left);
692
570
  if (node.right)
693
571
  _traverse(node.right);
694
- _this._accumulatedByPropertyName(node, nodeOrPropertyName);
572
+ this._accumulatedByPropertyName(node, nodeOrPropertyName);
695
573
  break;
696
574
  }
697
575
  };
698
576
  this.root && _traverse(this.root);
699
577
  return this._getResultByPropertyName(nodeOrPropertyName);
700
- };
701
- AbstractBinaryTree.prototype.DFSIterative = function (pattern, nodeOrPropertyName) {
702
- pattern = pattern || 'in';
703
- nodeOrPropertyName = nodeOrPropertyName || 'key';
578
+ }
579
+ dfsIterative(pattern = 'in', nodeOrPropertyName = 'key') {
704
580
  this._clearResults();
705
581
  if (!this.root)
706
582
  return this._getResultByPropertyName(nodeOrPropertyName);
707
- var stack = [{ opt: 0, node: this.root }];
583
+ const stack = [{ opt: 0, node: this.root }];
708
584
  while (stack.length > 0) {
709
- var cur = stack.pop();
585
+ const cur = stack.pop();
710
586
  if (!cur || !cur.node)
711
587
  continue;
712
588
  if (cur.opt === 1) {
@@ -738,16 +614,14 @@ var AbstractBinaryTree = (function () {
738
614
  }
739
615
  }
740
616
  return this._getResultByPropertyName(nodeOrPropertyName);
741
- };
742
- AbstractBinaryTree.prototype.levelIterative = function (node, nodeOrPropertyName) {
743
- nodeOrPropertyName = nodeOrPropertyName || 'key';
744
- node = node || this.root;
617
+ }
618
+ levelIterative(node = this.root, nodeOrPropertyName = 'key') {
745
619
  if (!node)
746
620
  return [];
747
621
  this._clearResults();
748
- var queue = [node];
622
+ const queue = [node];
749
623
  while (queue.length > 0) {
750
- var cur = queue.shift();
624
+ const cur = queue.shift();
751
625
  if (cur) {
752
626
  this._accumulatedByPropertyName(cur, nodeOrPropertyName);
753
627
  if (cur.left) {
@@ -759,14 +633,12 @@ var AbstractBinaryTree = (function () {
759
633
  }
760
634
  }
761
635
  return this._getResultByPropertyName(nodeOrPropertyName);
762
- };
763
- AbstractBinaryTree.prototype.listLevels = function (node, nodeOrPropertyName) {
764
- nodeOrPropertyName = nodeOrPropertyName || 'key';
765
- node = node || this.root;
636
+ }
637
+ listLevels(node = this.root, nodeOrPropertyName = 'key') {
766
638
  if (!node)
767
639
  return [];
768
- var levelsNodes = [];
769
- var collectByProperty = function (node, level) {
640
+ const levelsNodes = [];
641
+ const collectByProperty = (node, level) => {
770
642
  switch (nodeOrPropertyName) {
771
643
  case 'key':
772
644
  levelsNodes[level].push(node.key);
@@ -783,36 +655,36 @@ var AbstractBinaryTree = (function () {
783
655
  }
784
656
  };
785
657
  if (this.loopType === types_1.LoopType.RECURSIVE) {
786
- var _recursive_1 = function (node, level) {
658
+ const _recursive = (node, level) => {
787
659
  if (!levelsNodes[level])
788
660
  levelsNodes[level] = [];
789
661
  collectByProperty(node, level);
790
662
  if (node.left)
791
- _recursive_1(node.left, level + 1);
663
+ _recursive(node.left, level + 1);
792
664
  if (node.right)
793
- _recursive_1(node.right, level + 1);
665
+ _recursive(node.right, level + 1);
794
666
  };
795
- _recursive_1(node, 0);
667
+ _recursive(node, 0);
796
668
  }
797
669
  else {
798
- var stack = [[node, 0]];
670
+ const stack = [[node, 0]];
799
671
  while (stack.length > 0) {
800
- var head = stack.pop();
801
- var _a = __read(head, 2), node_1 = _a[0], level = _a[1];
672
+ const head = stack.pop();
673
+ const [node, level] = head;
802
674
  if (!levelsNodes[level])
803
675
  levelsNodes[level] = [];
804
- collectByProperty(node_1, level);
805
- if (node_1.right)
806
- stack.push([node_1.right, level + 1]);
807
- if (node_1.left)
808
- stack.push([node_1.left, level + 1]);
676
+ collectByProperty(node, level);
677
+ if (node.right)
678
+ stack.push([node.right, level + 1]);
679
+ if (node.left)
680
+ stack.push([node.left, level + 1]);
809
681
  }
810
682
  }
811
683
  return levelsNodes;
812
- };
813
- AbstractBinaryTree.prototype.getPredecessor = function (node) {
684
+ }
685
+ getPredecessor(node) {
814
686
  if (node.left) {
815
- var predecessor = node.left;
687
+ let predecessor = node.left;
816
688
  while (!predecessor || (predecessor.right && predecessor.right !== node)) {
817
689
  if (predecessor) {
818
690
  predecessor = predecessor.right;
@@ -823,18 +695,15 @@ var AbstractBinaryTree = (function () {
823
695
  else {
824
696
  return node;
825
697
  }
826
- };
827
- AbstractBinaryTree.prototype.morris = function (pattern, nodeOrPropertyName) {
828
- var _this = this;
698
+ }
699
+ morris(pattern = 'in', nodeOrPropertyName = 'key') {
829
700
  if (this.root === null)
830
701
  return [];
831
- pattern = pattern || 'in';
832
- nodeOrPropertyName = nodeOrPropertyName || 'key';
833
702
  this._clearResults();
834
- var cur = this.root;
835
- var _reverseEdge = function (node) {
836
- var pre = null;
837
- var next = null;
703
+ let cur = this.root;
704
+ const _reverseEdge = (node) => {
705
+ let pre = null;
706
+ let next = null;
838
707
  while (node) {
839
708
  next = node.right;
840
709
  node.right = pre;
@@ -843,11 +712,11 @@ var AbstractBinaryTree = (function () {
843
712
  }
844
713
  return pre;
845
714
  };
846
- var _printEdge = function (node) {
847
- var tail = _reverseEdge(node);
848
- var cur = tail;
715
+ const _printEdge = (node) => {
716
+ const tail = _reverseEdge(node);
717
+ let cur = tail;
849
718
  while (cur) {
850
- _this._accumulatedByPropertyName(cur, nodeOrPropertyName);
719
+ this._accumulatedByPropertyName(cur, nodeOrPropertyName);
851
720
  cur = cur.right;
852
721
  }
853
722
  _reverseEdge(tail);
@@ -856,7 +725,7 @@ var AbstractBinaryTree = (function () {
856
725
  case 'in':
857
726
  while (cur) {
858
727
  if (cur.left) {
859
- var predecessor = this.getPredecessor(cur);
728
+ const predecessor = this.getPredecessor(cur);
860
729
  if (!predecessor.right) {
861
730
  predecessor.right = cur;
862
731
  cur = cur.left;
@@ -873,7 +742,7 @@ var AbstractBinaryTree = (function () {
873
742
  case 'pre':
874
743
  while (cur) {
875
744
  if (cur.left) {
876
- var predecessor = this.getPredecessor(cur);
745
+ const predecessor = this.getPredecessor(cur);
877
746
  if (!predecessor.right) {
878
747
  predecessor.right = cur;
879
748
  this._accumulatedByPropertyName(cur, nodeOrPropertyName);
@@ -893,7 +762,7 @@ var AbstractBinaryTree = (function () {
893
762
  case 'post':
894
763
  while (cur) {
895
764
  if (cur.left) {
896
- var predecessor = this.getPredecessor(cur);
765
+ const predecessor = this.getPredecessor(cur);
897
766
  if (predecessor.right === null) {
898
767
  predecessor.right = cur;
899
768
  cur = cur.left;
@@ -910,8 +779,8 @@ var AbstractBinaryTree = (function () {
910
779
  break;
911
780
  }
912
781
  return this._getResultByPropertyName(nodeOrPropertyName);
913
- };
914
- AbstractBinaryTree.prototype._addTo = function (newNode, parent) {
782
+ }
783
+ _addTo(newNode, parent) {
915
784
  if (parent) {
916
785
  if (parent.left === undefined) {
917
786
  parent.left = newNode;
@@ -934,86 +803,74 @@ var AbstractBinaryTree = (function () {
934
803
  else {
935
804
  return;
936
805
  }
937
- };
938
- AbstractBinaryTree.prototype._setLoopType = function (value) {
806
+ }
807
+ _setLoopType(value) {
939
808
  this._loopType = value;
940
- };
941
- AbstractBinaryTree.prototype._setVisitedKey = function (value) {
942
- this._visitedKey = value;
943
- };
944
- AbstractBinaryTree.prototype._setVisitedVal = function (value) {
945
- this._visitedVal = value;
946
- };
947
- AbstractBinaryTree.prototype._setVisitedNode = function (value) {
948
- this._visitedNode = value;
949
- };
950
- AbstractBinaryTree.prototype._setRoot = function (v) {
809
+ }
810
+ _setRoot(v) {
951
811
  if (v) {
952
812
  v.parent = undefined;
953
813
  }
954
814
  this._root = v;
955
- };
956
- AbstractBinaryTree.prototype._setSize = function (v) {
815
+ }
816
+ _setSize(v) {
957
817
  this._size = v;
958
- };
959
- AbstractBinaryTree.prototype._clearResults = function () {
960
- this._visitedKey = [];
961
- this._visitedVal = [];
962
- this._visitedNode = [];
963
- };
964
- AbstractBinaryTree.prototype._pushByPropertyNameStopOrNot = function (cur, result, nodeProperty, propertyName, onlyOne) {
818
+ }
819
+ _clearResults() {
820
+ this.visitedKey = [];
821
+ this.visitedVal = [];
822
+ this.visitedNode = [];
823
+ }
824
+ _pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName = 'key', onlyOne = false) {
965
825
  switch (propertyName) {
966
826
  case 'key':
967
827
  if (cur.key === nodeProperty) {
968
828
  result.push(cur);
969
- return !!onlyOne;
829
+ return onlyOne;
970
830
  }
971
831
  break;
972
832
  case 'val':
973
833
  if (cur.val === nodeProperty) {
974
834
  result.push(cur);
975
- return !!onlyOne;
835
+ return onlyOne;
976
836
  }
977
837
  break;
978
838
  default:
979
839
  if (cur.key === nodeProperty) {
980
840
  result.push(cur);
981
- return !!onlyOne;
841
+ return onlyOne;
982
842
  }
983
843
  break;
984
844
  }
985
- };
986
- AbstractBinaryTree.prototype._accumulatedByPropertyName = function (node, nodeOrPropertyName) {
987
- nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'key';
845
+ }
846
+ _accumulatedByPropertyName(node, nodeOrPropertyName = 'key') {
988
847
  switch (nodeOrPropertyName) {
989
848
  case 'key':
990
- this._visitedKey.push(node.key);
849
+ this.visitedKey.push(node.key);
991
850
  break;
992
851
  case 'val':
993
- this._visitedVal.push(node.val);
852
+ this.visitedVal.push(node.val);
994
853
  break;
995
854
  case 'node':
996
- this._visitedNode.push(node);
855
+ this.visitedNode.push(node);
997
856
  break;
998
857
  default:
999
- this._visitedKey.push(node.key);
858
+ this.visitedKey.push(node.key);
1000
859
  break;
1001
860
  }
1002
- };
1003
- AbstractBinaryTree.prototype._getResultByPropertyName = function (nodeOrPropertyName) {
1004
- nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'key';
861
+ }
862
+ _getResultByPropertyName(nodeOrPropertyName = 'key') {
1005
863
  switch (nodeOrPropertyName) {
1006
864
  case 'key':
1007
- return this._visitedKey;
865
+ return this.visitedKey;
1008
866
  case 'val':
1009
- return this._visitedVal;
867
+ return this.visitedVal;
1010
868
  case 'node':
1011
- return this._visitedNode;
869
+ return this.visitedNode;
1012
870
  default:
1013
- return this._visitedKey;
871
+ return this.visitedKey;
1014
872
  }
1015
- };
1016
- return AbstractBinaryTree;
1017
- }());
873
+ }
874
+ }
1018
875
  exports.AbstractBinaryTree = AbstractBinaryTree;
1019
876
  //# sourceMappingURL=abstract-binary-tree.js.map