data-structure-typed 1.34.7 → 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 (167) 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 +314 -457
  8. package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
  9. package/dist/data-structures/binary-tree/avl-tree.js +64 -90
  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 +12 -31
  16. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  17. package/dist/data-structures/binary-tree/bst.js +157 -244
  18. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  19. package/dist/data-structures/binary-tree/rb-tree.js +20 -44
  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 +168 -239
  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 +351 -585
  30. package/dist/data-structures/graph/abstract-graph.js.map +1 -1
  31. package/dist/data-structures/graph/directed-graph.js +152 -282
  32. package/dist/data-structures/graph/directed-graph.js.map +1 -1
  33. package/dist/data-structures/graph/map-graph.js +47 -88
  34. package/dist/data-structures/graph/map-graph.js.map +1 -1
  35. package/dist/data-structures/graph/undirected-graph.js +91 -180
  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 +33 -46
  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 +124 -123
  91. package/lib/data-structures/binary-tree/abstract-binary-tree.js +136 -216
  92. package/lib/data-structures/binary-tree/avl-tree.d.ts +19 -10
  93. package/lib/data-structures/binary-tree/avl-tree.js +35 -13
  94. package/lib/data-structures/binary-tree/binary-tree.d.ts +6 -6
  95. package/lib/data-structures/binary-tree/binary-tree.js +7 -7
  96. package/lib/data-structures/binary-tree/bst.d.ts +34 -34
  97. package/lib/data-structures/binary-tree/bst.js +86 -89
  98. package/lib/data-structures/binary-tree/rb-tree.d.ts +3 -3
  99. package/lib/data-structures/binary-tree/rb-tree.js +4 -4
  100. package/lib/data-structures/binary-tree/tree-multiset.d.ts +40 -42
  101. package/lib/data-structures/binary-tree/tree-multiset.js +76 -86
  102. package/lib/data-structures/graph/abstract-graph.d.ts +62 -62
  103. package/lib/data-structures/graph/abstract-graph.js +86 -86
  104. package/lib/data-structures/graph/directed-graph.d.ts +51 -51
  105. package/lib/data-structures/graph/directed-graph.js +63 -63
  106. package/lib/data-structures/graph/map-graph.d.ts +13 -13
  107. package/lib/data-structures/graph/map-graph.js +12 -12
  108. package/lib/data-structures/graph/undirected-graph.d.ts +30 -30
  109. package/lib/data-structures/graph/undirected-graph.js +32 -32
  110. package/lib/data-structures/priority-queue/priority-queue.d.ts +3 -3
  111. package/lib/data-structures/priority-queue/priority-queue.js +3 -3
  112. package/lib/data-structures/tree/tree.d.ts +4 -4
  113. package/lib/data-structures/tree/tree.js +6 -6
  114. package/lib/interfaces/abstract-binary-tree.d.ts +37 -42
  115. package/lib/interfaces/abstract-graph.d.ts +13 -13
  116. package/lib/interfaces/avl-tree.d.ts +6 -4
  117. package/lib/interfaces/bst.d.ts +10 -9
  118. package/lib/interfaces/directed-graph.d.ts +5 -5
  119. package/lib/interfaces/rb-tree.d.ts +2 -2
  120. package/lib/interfaces/undirected-graph.d.ts +2 -2
  121. package/lib/types/data-structures/abstract-binary-tree.d.ts +3 -3
  122. package/lib/types/data-structures/abstract-binary-tree.js +0 -1
  123. package/lib/types/data-structures/abstract-graph.d.ts +2 -2
  124. package/lib/types/data-structures/bst.d.ts +2 -2
  125. package/lib/types/data-structures/tree-multiset.d.ts +1 -1
  126. package/lib/types/utils/validate-type.d.ts +8 -8
  127. package/package.json +6 -6
  128. package/scripts/rename_clear_files.sh +29 -0
  129. package/src/data-structures/binary-tree/abstract-binary-tree.ts +241 -293
  130. package/src/data-structures/binary-tree/avl-tree.ts +43 -14
  131. package/src/data-structures/binary-tree/binary-tree.ts +8 -8
  132. package/src/data-structures/binary-tree/bst.ts +101 -96
  133. package/src/data-structures/binary-tree/rb-tree.ts +9 -9
  134. package/src/data-structures/binary-tree/tree-multiset.ts +82 -94
  135. package/src/data-structures/graph/abstract-graph.ts +114 -109
  136. package/src/data-structures/graph/directed-graph.ts +77 -77
  137. package/src/data-structures/graph/map-graph.ts +20 -15
  138. package/src/data-structures/graph/undirected-graph.ts +39 -39
  139. package/src/data-structures/priority-queue/priority-queue.ts +3 -3
  140. package/src/data-structures/tree/tree.ts +7 -7
  141. package/src/interfaces/abstract-binary-tree.ts +37 -50
  142. package/src/interfaces/abstract-graph.ts +13 -13
  143. package/src/interfaces/avl-tree.ts +6 -4
  144. package/src/interfaces/bst.ts +9 -9
  145. package/src/interfaces/directed-graph.ts +5 -5
  146. package/src/interfaces/rb-tree.ts +2 -2
  147. package/src/interfaces/undirected-graph.ts +2 -2
  148. package/src/types/data-structures/abstract-binary-tree.ts +3 -4
  149. package/src/types/data-structures/abstract-graph.ts +2 -2
  150. package/src/types/data-structures/bst.ts +2 -2
  151. package/src/types/data-structures/tree-multiset.ts +1 -1
  152. package/src/types/utils/validate-type.ts +10 -10
  153. package/test/integration/avl-tree.test.ts +24 -24
  154. package/test/integration/bst.test.ts +71 -71
  155. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +28 -28
  156. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +4 -12
  157. package/test/unit/data-structures/binary-tree/bst.test.ts +79 -79
  158. package/test/unit/data-structures/binary-tree/overall.test.ts +20 -20
  159. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +80 -80
  160. package/test/unit/data-structures/graph/directed-graph.test.ts +8 -8
  161. package/test/unit/data-structures/graph/map-graph.test.ts +4 -4
  162. package/test/unit/data-structures/graph/overall.test.ts +2 -2
  163. package/test/unit/data-structures/graph/undirected-graph.test.ts +1 -1
  164. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +4 -5
  165. package/test/unit/data-structures/tree/tree.test.ts +2 -2
  166. package/umd/bundle.min.js +1 -1
  167. package/umd/bundle.min.js.map +1 -1
@@ -1,115 +1,52 @@
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 __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __read = (this && this.__read) || function (o, n) {
29
- var m = typeof Symbol === "function" && o[Symbol.iterator];
30
- if (!m) return o;
31
- var i = m.call(o), r, ar = [], e;
32
- try {
33
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
34
- }
35
- catch (error) { e = { error: error }; }
36
- finally {
37
- try {
38
- if (r && !r.done && (m = i["return"])) m.call(i);
39
- }
40
- finally { if (e) throw e.error; }
41
- }
42
- return ar;
43
- };
44
2
  Object.defineProperty(exports, "__esModule", { value: true });
45
3
  exports.TreeMultiset = exports.TreeMultisetNode = void 0;
46
- var types_1 = require("../../types");
47
- var avl_tree_1 = require("./avl-tree");
48
- var TreeMultisetNode = (function (_super) {
49
- __extends(TreeMultisetNode, _super);
50
- function TreeMultisetNode(id, val, count) {
51
- if (count === void 0) { count = 1; }
52
- var _this = _super.call(this, id, val) || this;
53
- _this._count = count;
54
- return _this;
4
+ const types_1 = require("../../types");
5
+ const avl_tree_1 = require("./avl-tree");
6
+ class TreeMultisetNode extends avl_tree_1.AVLTreeNode {
7
+ constructor(key, val, count = 1) {
8
+ super(key, val);
9
+ this.count = count;
55
10
  }
56
- Object.defineProperty(TreeMultisetNode.prototype, "count", {
57
- get: function () {
58
- return this._count;
59
- },
60
- set: function (v) {
61
- this._count = v;
62
- },
63
- enumerable: false,
64
- configurable: true
65
- });
66
- return TreeMultisetNode;
67
- }(avl_tree_1.AVLTreeNode));
11
+ }
68
12
  exports.TreeMultisetNode = TreeMultisetNode;
69
- var TreeMultiset = (function (_super) {
70
- __extends(TreeMultiset, _super);
71
- function TreeMultiset(options) {
72
- var _this = _super.call(this, __assign({}, options)) || this;
73
- _this._count = 0;
74
- return _this;
13
+ class TreeMultiset extends avl_tree_1.AVLTree {
14
+ constructor(options) {
15
+ super(options);
16
+ this._count = 0;
75
17
  }
76
- Object.defineProperty(TreeMultiset.prototype, "count", {
77
- get: function () {
78
- return this._count;
79
- },
80
- enumerable: false,
81
- configurable: true
82
- });
83
- TreeMultiset.prototype.createNode = function (id, val, count) {
84
- return new TreeMultisetNode(id, val, count);
85
- };
86
- TreeMultiset.prototype.swapLocation = function (srcNode, destNode) {
87
- var id = destNode.id, val = destNode.val, count = destNode.count, height = destNode.height;
88
- var tempNode = this.createNode(id, val, count);
18
+ get count() {
19
+ return this._count;
20
+ }
21
+ createNode(key, val, count) {
22
+ return new TreeMultisetNode(key, val, count);
23
+ }
24
+ swapLocation(srcNode, destNode) {
25
+ const { key, val, count, height } = destNode;
26
+ const tempNode = this.createNode(key, val, count);
89
27
  if (tempNode) {
90
28
  tempNode.height = height;
91
- destNode.id = srcNode.id;
29
+ destNode.key = srcNode.key;
92
30
  destNode.val = srcNode.val;
93
31
  destNode.count = srcNode.count;
94
32
  destNode.height = srcNode.height;
95
- srcNode.id = tempNode.id;
33
+ srcNode.key = tempNode.key;
96
34
  srcNode.val = tempNode.val;
97
35
  srcNode.count = tempNode.count;
98
36
  srcNode.height = tempNode.height;
99
37
  }
100
38
  return destNode;
101
- };
102
- TreeMultiset.prototype.add = function (idOrNode, val, count) {
103
- count = count !== null && count !== void 0 ? count : 1;
104
- var inserted = undefined, newNode;
105
- if (idOrNode instanceof TreeMultisetNode) {
106
- newNode = this.createNode(idOrNode.id, idOrNode.val, idOrNode.count);
39
+ }
40
+ add(keyOrNode, val, count = 1) {
41
+ let inserted = undefined, newNode;
42
+ if (keyOrNode instanceof TreeMultisetNode) {
43
+ newNode = this.createNode(keyOrNode.key, keyOrNode.val, keyOrNode.count);
107
44
  }
108
- else if (idOrNode === null) {
45
+ else if (keyOrNode === null) {
109
46
  newNode = null;
110
47
  }
111
48
  else {
112
- newNode = this.createNode(idOrNode, val, count);
49
+ newNode = this.createNode(keyOrNode, val, count);
113
50
  }
114
51
  if (!this.root) {
115
52
  this._setRoot(newNode);
@@ -118,19 +55,19 @@ var TreeMultiset = (function (_super) {
118
55
  inserted = this.root;
119
56
  }
120
57
  else {
121
- var cur = this.root;
122
- var traversing = true;
58
+ let cur = this.root;
59
+ let traversing = true;
123
60
  while (traversing) {
124
61
  if (cur) {
125
62
  if (newNode) {
126
- if (this._compare(cur.id, newNode.id) === types_1.CP.eq) {
63
+ if (this._compare(cur.key, newNode.key) === types_1.CP.eq) {
127
64
  cur.val = newNode.val;
128
65
  cur.count += newNode.count;
129
66
  this._setCount(this.count + newNode.count);
130
67
  traversing = false;
131
68
  inserted = cur;
132
69
  }
133
- else if (this._compare(cur.id, newNode.id) === types_1.CP.gt) {
70
+ else if (this._compare(cur.key, newNode.key) === types_1.CP.gt) {
134
71
  if (cur.left === undefined) {
135
72
  cur.left = newNode;
136
73
  this._setSize(this.size + 1);
@@ -143,7 +80,7 @@ var TreeMultiset = (function (_super) {
143
80
  cur = cur.left;
144
81
  }
145
82
  }
146
- else if (this._compare(cur.id, newNode.id) === types_1.CP.lt) {
83
+ else if (this._compare(cur.key, newNode.key) === types_1.CP.lt) {
147
84
  if (cur.right === undefined) {
148
85
  cur.right = newNode;
149
86
  this._setSize(this.size + 1);
@@ -168,8 +105,8 @@ var TreeMultiset = (function (_super) {
168
105
  if (inserted)
169
106
  this._balancePath(inserted);
170
107
  return inserted;
171
- };
172
- TreeMultiset.prototype._addTo = function (newNode, parent) {
108
+ }
109
+ _addTo(newNode, parent) {
173
110
  if (parent) {
174
111
  if (parent.left === undefined) {
175
112
  parent.left = newNode;
@@ -194,52 +131,51 @@ var TreeMultiset = (function (_super) {
194
131
  else {
195
132
  return;
196
133
  }
197
- };
198
- TreeMultiset.prototype.addMany = function (idsOrNodes, data) {
199
- var inserted = [];
200
- for (var i = 0; i < idsOrNodes.length; i++) {
201
- var idOrNode = idsOrNodes[i];
202
- if (idOrNode instanceof TreeMultisetNode) {
203
- inserted.push(this.add(idOrNode.id, idOrNode.val, idOrNode.count));
134
+ }
135
+ addMany(keysOrNodes, data) {
136
+ const inserted = [];
137
+ for (let i = 0; i < keysOrNodes.length; i++) {
138
+ const keyOrNode = keysOrNodes[i];
139
+ if (keyOrNode instanceof TreeMultisetNode) {
140
+ inserted.push(this.add(keyOrNode.key, keyOrNode.val, keyOrNode.count));
204
141
  continue;
205
142
  }
206
- if (idOrNode === null) {
143
+ if (keyOrNode === null) {
207
144
  inserted.push(this.add(NaN, null, 0));
208
145
  continue;
209
146
  }
210
- inserted.push(this.add(idOrNode, data === null || data === void 0 ? void 0 : data[i], 1));
147
+ inserted.push(this.add(keyOrNode, data === null || data === void 0 ? void 0 : data[i], 1));
211
148
  }
212
149
  return inserted;
213
- };
214
- TreeMultiset.prototype.perfectlyBalance = function () {
215
- var _this = this;
216
- var sorted = this.DFS('in', 'node'), n = sorted.length;
150
+ }
151
+ perfectlyBalance() {
152
+ const sorted = this.dfs('in', 'node'), n = sorted.length;
217
153
  if (sorted.length < 1)
218
154
  return false;
219
155
  this.clear();
220
156
  if (this.loopType === types_1.LoopType.RECURSIVE) {
221
- var buildBalanceBST_1 = function (l, r) {
157
+ const buildBalanceBST = (l, r) => {
222
158
  if (l > r)
223
159
  return;
224
- var m = l + Math.floor((r - l) / 2);
225
- var midNode = sorted[m];
226
- _this.add(midNode.id, midNode.val, midNode.count);
227
- buildBalanceBST_1(l, m - 1);
228
- buildBalanceBST_1(m + 1, r);
160
+ const m = l + Math.floor((r - l) / 2);
161
+ const midNode = sorted[m];
162
+ this.add(midNode.key, midNode.val, midNode.count);
163
+ buildBalanceBST(l, m - 1);
164
+ buildBalanceBST(m + 1, r);
229
165
  };
230
- buildBalanceBST_1(0, n - 1);
166
+ buildBalanceBST(0, n - 1);
231
167
  return true;
232
168
  }
233
169
  else {
234
- var stack = [[0, n - 1]];
170
+ const stack = [[0, n - 1]];
235
171
  while (stack.length > 0) {
236
- var popped = stack.pop();
172
+ const popped = stack.pop();
237
173
  if (popped) {
238
- var _a = __read(popped, 2), l = _a[0], r = _a[1];
174
+ const [l, r] = popped;
239
175
  if (l <= r) {
240
- var m = l + Math.floor((r - l) / 2);
241
- var midNode = sorted[m];
242
- this.add(midNode.id, midNode.val, midNode.count);
176
+ const m = l + Math.floor((r - l) / 2);
177
+ const midNode = sorted[m];
178
+ this.add(midNode.key, midNode.val, midNode.count);
243
179
  stack.push([m + 1, r]);
244
180
  stack.push([l, m - 1]);
245
181
  }
@@ -247,16 +183,16 @@ var TreeMultiset = (function (_super) {
247
183
  }
248
184
  return true;
249
185
  }
250
- };
251
- TreeMultiset.prototype.remove = function (nodeOrId, ignoreCount) {
252
- var bstDeletedResult = [];
186
+ }
187
+ remove(nodeOrKey, ignoreCount = false) {
188
+ const bstDeletedResult = [];
253
189
  if (!this.root)
254
190
  return bstDeletedResult;
255
- var curr = this.get(nodeOrId);
191
+ const curr = this.get(nodeOrKey);
256
192
  if (!curr)
257
193
  return bstDeletedResult;
258
- var parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
259
- var needBalanced = null, orgCurrent = curr;
194
+ const parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
195
+ let needBalanced = null, orgCurrent = curr;
260
196
  if (curr.count > 1 && !ignoreCount) {
261
197
  curr.count--;
262
198
  this._setCount(this.count - 1);
@@ -268,7 +204,7 @@ var TreeMultiset = (function (_super) {
268
204
  this._setRoot(curr.right);
269
205
  }
270
206
  else {
271
- var fp = curr.familyPosition;
207
+ const { familyPosition: fp } = curr;
272
208
  if (fp === types_1.FamilyPosition.LEFT || fp === types_1.FamilyPosition.ROOT_LEFT) {
273
209
  parent.left = curr.right;
274
210
  }
@@ -279,9 +215,9 @@ var TreeMultiset = (function (_super) {
279
215
  }
280
216
  }
281
217
  else {
282
- var leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
218
+ const leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
283
219
  if (leftSubTreeRightMost) {
284
- var parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
220
+ const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
285
221
  orgCurrent = this.swapLocation(curr, leftSubTreeRightMost);
286
222
  if (parentOfLeftSubTreeMax) {
287
223
  if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) {
@@ -297,30 +233,30 @@ var TreeMultiset = (function (_super) {
297
233
  this._setSize(this.size - 1);
298
234
  this._setCount(this.count - orgCurrent.count);
299
235
  }
300
- bstDeletedResult.push({ deleted: orgCurrent, needBalanced: needBalanced });
236
+ bstDeletedResult.push({ deleted: orgCurrent, needBalanced });
301
237
  if (needBalanced) {
302
238
  this._balancePath(needBalanced);
303
239
  }
304
240
  return bstDeletedResult;
305
- };
306
- TreeMultiset.prototype.getSubTreeCount = function (subTreeRoot) {
307
- var res = [0, 0];
241
+ }
242
+ getSubTreeCount(subTreeRoot) {
243
+ const res = [0, 0];
308
244
  if (!subTreeRoot)
309
245
  return res;
310
246
  if (this.loopType === types_1.LoopType.RECURSIVE) {
311
- var _traverse_1 = function (cur) {
247
+ const _traverse = (cur) => {
312
248
  res[0]++;
313
249
  res[1] += cur.count;
314
- cur.left && _traverse_1(cur.left);
315
- cur.right && _traverse_1(cur.right);
250
+ cur.left && _traverse(cur.left);
251
+ cur.right && _traverse(cur.right);
316
252
  };
317
- _traverse_1(subTreeRoot);
253
+ _traverse(subTreeRoot);
318
254
  return res;
319
255
  }
320
256
  else {
321
- var stack = [subTreeRoot];
257
+ const stack = [subTreeRoot];
322
258
  while (stack.length > 0) {
323
- var cur = stack.pop();
259
+ const cur = stack.pop();
324
260
  res[0]++;
325
261
  res[1] += cur.count;
326
262
  cur.right && stack.push(cur.right);
@@ -328,67 +264,66 @@ var TreeMultiset = (function (_super) {
328
264
  }
329
265
  return res;
330
266
  }
331
- };
332
- TreeMultiset.prototype.subTreeSumCount = function (subTreeRoot) {
267
+ }
268
+ subTreeSumCount(subTreeRoot) {
333
269
  if (typeof subTreeRoot === 'number')
334
- subTreeRoot = this.get(subTreeRoot, 'id');
270
+ subTreeRoot = this.get(subTreeRoot, 'key');
335
271
  if (!subTreeRoot)
336
272
  return 0;
337
- var sum = 0;
273
+ let sum = 0;
338
274
  if (this.loopType === types_1.LoopType.RECURSIVE) {
339
- var _traverse_2 = function (cur) {
275
+ const _traverse = (cur) => {
340
276
  sum += cur.count;
341
- cur.left && _traverse_2(cur.left);
342
- cur.right && _traverse_2(cur.right);
277
+ cur.left && _traverse(cur.left);
278
+ cur.right && _traverse(cur.right);
343
279
  };
344
- _traverse_2(subTreeRoot);
280
+ _traverse(subTreeRoot);
345
281
  }
346
282
  else {
347
- var stack = [subTreeRoot];
283
+ const stack = [subTreeRoot];
348
284
  while (stack.length > 0) {
349
- var cur = stack.pop();
285
+ const cur = stack.pop();
350
286
  sum += cur.count;
351
287
  cur.right && stack.push(cur.right);
352
288
  cur.left && stack.push(cur.left);
353
289
  }
354
290
  }
355
291
  return sum;
356
- };
357
- TreeMultiset.prototype.subTreeAddCount = function (subTreeRoot, delta) {
358
- var _this = this;
292
+ }
293
+ subTreeAddCount(subTreeRoot, delta) {
359
294
  if (typeof subTreeRoot === 'number')
360
- subTreeRoot = this.get(subTreeRoot, 'id');
295
+ subTreeRoot = this.get(subTreeRoot, 'key');
361
296
  if (!subTreeRoot)
362
297
  return false;
363
- var _addByProperty = function (cur) {
298
+ const _addByProperty = (cur) => {
364
299
  cur.count += delta;
365
- _this._setCount(_this.count + delta);
300
+ this._setCount(this.count + delta);
366
301
  };
367
302
  if (this.loopType === types_1.LoopType.RECURSIVE) {
368
- var _traverse_3 = function (cur) {
303
+ const _traverse = (cur) => {
369
304
  _addByProperty(cur);
370
- cur.left && _traverse_3(cur.left);
371
- cur.right && _traverse_3(cur.right);
305
+ cur.left && _traverse(cur.left);
306
+ cur.right && _traverse(cur.right);
372
307
  };
373
- _traverse_3(subTreeRoot);
308
+ _traverse(subTreeRoot);
374
309
  }
375
310
  else {
376
- var stack = [subTreeRoot];
311
+ const stack = [subTreeRoot];
377
312
  while (stack.length > 0) {
378
- var cur = stack.pop();
313
+ const cur = stack.pop();
379
314
  _addByProperty(cur);
380
315
  cur.right && stack.push(cur.right);
381
316
  cur.left && stack.push(cur.left);
382
317
  }
383
318
  }
384
319
  return true;
385
- };
386
- TreeMultiset.prototype.getNodesByCount = function (nodeProperty, onlyOne) {
320
+ }
321
+ getNodesByCount(nodeProperty, onlyOne = false) {
387
322
  if (!this.root)
388
323
  return [];
389
- var result = [];
324
+ const result = [];
390
325
  if (this.loopType === types_1.LoopType.RECURSIVE) {
391
- var _traverse_4 = function (cur) {
326
+ const _traverse = (cur) => {
392
327
  if (cur.count === nodeProperty) {
393
328
  result.push(cur);
394
329
  if (onlyOne)
@@ -396,15 +331,15 @@ var TreeMultiset = (function (_super) {
396
331
  }
397
332
  if (!cur.left && !cur.right)
398
333
  return;
399
- cur.left && _traverse_4(cur.left);
400
- cur.right && _traverse_4(cur.right);
334
+ cur.left && _traverse(cur.left);
335
+ cur.right && _traverse(cur.right);
401
336
  };
402
- _traverse_4(this.root);
337
+ _traverse(this.root);
403
338
  }
404
339
  else {
405
- var queue = [this.root];
340
+ const queue = [this.root];
406
341
  while (queue.length > 0) {
407
- var cur = queue.shift();
342
+ const cur = queue.shift();
408
343
  if (cur) {
409
344
  if (cur.count === nodeProperty) {
410
345
  result.push(cur);
@@ -417,72 +352,68 @@ var TreeMultiset = (function (_super) {
417
352
  }
418
353
  }
419
354
  return result;
420
- };
421
- TreeMultiset.prototype.BFSCount = function () {
422
- var nodes = _super.prototype.BFS.call(this, 'node');
423
- return nodes.map(function (node) { return node.count; });
424
- };
425
- TreeMultiset.prototype.listLevelsCount = function (node) {
426
- var levels = _super.prototype.listLevels.call(this, node, 'node');
427
- return levels.map(function (level) { return level.map(function (node) { return node.count; }); });
428
- };
429
- TreeMultiset.prototype.morrisCount = function (pattern) {
430
- pattern = pattern || 'in';
431
- var nodes = _super.prototype.morris.call(this, pattern, 'node');
432
- return nodes.map(function (node) { return node.count; });
433
- };
434
- TreeMultiset.prototype.DFSIterativeCount = function (pattern) {
435
- pattern = pattern !== null && pattern !== void 0 ? pattern : 'in';
436
- var nodes = _super.prototype.DFSIterative.call(this, pattern, 'node');
437
- return nodes.map(function (node) { return node.count; });
438
- };
439
- TreeMultiset.prototype.DFSCount = function (pattern) {
440
- pattern = pattern !== null && pattern !== void 0 ? pattern : 'in';
441
- var nodes = _super.prototype.DFS.call(this, pattern, 'node');
442
- return nodes.map(function (node) { return node.count; });
443
- };
444
- TreeMultiset.prototype.lesserSumCount = function (beginNode) {
445
- var _this = this;
355
+ }
356
+ BFSCount() {
357
+ const nodes = super.bfs('node');
358
+ return nodes.map(node => node.count);
359
+ }
360
+ listLevelsCount(node) {
361
+ const levels = super.listLevels(node, 'node');
362
+ return levels.map(level => level.map(node => node.count));
363
+ }
364
+ morrisCount(pattern = 'in') {
365
+ const nodes = super.morris(pattern, 'node');
366
+ return nodes.map(node => node.count);
367
+ }
368
+ dfsCountIterative(pattern = 'in') {
369
+ const nodes = super.dfsIterative(pattern, 'node');
370
+ return nodes.map(node => node.count);
371
+ }
372
+ dfsCount(pattern = 'in') {
373
+ const nodes = super.dfs(pattern, 'node');
374
+ return nodes.map(node => node.count);
375
+ }
376
+ lesserSumCount(beginNode) {
446
377
  if (typeof beginNode === 'number')
447
- beginNode = this.get(beginNode, 'id');
378
+ beginNode = this.get(beginNode, 'key');
448
379
  if (!beginNode)
449
380
  return 0;
450
381
  if (!this.root)
451
382
  return 0;
452
- var id = beginNode.id;
453
- var sum = 0;
383
+ const key = beginNode.key;
384
+ let sum = 0;
454
385
  if (this.loopType === types_1.LoopType.RECURSIVE) {
455
- var _traverse_5 = function (cur) {
456
- var compared = _this._compare(cur.id, id);
386
+ const _traverse = (cur) => {
387
+ const compared = this._compare(cur.key, key);
457
388
  if (compared === types_1.CP.eq) {
458
389
  if (cur.right)
459
- sum += _this.subTreeSumCount(cur.right);
390
+ sum += this.subTreeSumCount(cur.right);
460
391
  return;
461
392
  }
462
393
  else if (compared === types_1.CP.lt) {
463
394
  if (cur.left)
464
- sum += _this.subTreeSumCount(cur.left);
395
+ sum += this.subTreeSumCount(cur.left);
465
396
  sum += cur.count;
466
397
  if (cur.right)
467
- _traverse_5(cur.right);
398
+ _traverse(cur.right);
468
399
  else
469
400
  return;
470
401
  }
471
402
  else {
472
403
  if (cur.left)
473
- _traverse_5(cur.left);
404
+ _traverse(cur.left);
474
405
  else
475
406
  return;
476
407
  }
477
408
  };
478
- _traverse_5(this.root);
409
+ _traverse(this.root);
479
410
  }
480
411
  else {
481
- var queue = [this.root];
412
+ const queue = [this.root];
482
413
  while (queue.length > 0) {
483
- var cur = queue.shift();
414
+ const cur = queue.shift();
484
415
  if (cur) {
485
- var compared = this._compare(cur.id, id);
416
+ const compared = this._compare(cur.key, key);
486
417
  if (compared === types_1.CP.eq) {
487
418
  if (cur.right)
488
419
  sum += this.subTreeSumCount(cur.right);
@@ -507,56 +438,54 @@ var TreeMultiset = (function (_super) {
507
438
  }
508
439
  }
509
440
  return sum;
510
- };
511
- TreeMultiset.prototype.allGreaterNodesAddCount = function (node, delta) {
512
- var _this = this;
441
+ }
442
+ allGreaterNodesAddCount(node, delta) {
513
443
  if (typeof node === 'number')
514
- node = this.get(node, 'id');
444
+ node = this.get(node, 'key');
515
445
  if (!node)
516
446
  return false;
517
- var id = node.id;
447
+ const key = node.key;
518
448
  if (!this.root)
519
449
  return false;
520
450
  if (this.loopType === types_1.LoopType.RECURSIVE) {
521
- var _traverse_6 = function (cur) {
522
- var compared = _this._compare(cur.id, id);
451
+ const _traverse = (cur) => {
452
+ const compared = this._compare(cur.key, key);
523
453
  if (compared === types_1.CP.gt)
524
454
  cur.count += delta;
525
455
  if (!cur.left && !cur.right)
526
456
  return;
527
- if (cur.left && _this._compare(cur.left.id, id) === types_1.CP.gt)
528
- _traverse_6(cur.left);
529
- if (cur.right && _this._compare(cur.right.id, id) === types_1.CP.gt)
530
- _traverse_6(cur.right);
457
+ if (cur.left && this._compare(cur.left.key, key) === types_1.CP.gt)
458
+ _traverse(cur.left);
459
+ if (cur.right && this._compare(cur.right.key, key) === types_1.CP.gt)
460
+ _traverse(cur.right);
531
461
  };
532
- _traverse_6(this.root);
462
+ _traverse(this.root);
533
463
  return true;
534
464
  }
535
465
  else {
536
- var queue = [this.root];
466
+ const queue = [this.root];
537
467
  while (queue.length > 0) {
538
- var cur = queue.shift();
468
+ const cur = queue.shift();
539
469
  if (cur) {
540
- var compared = this._compare(cur.id, id);
470
+ const compared = this._compare(cur.key, key);
541
471
  if (compared === types_1.CP.gt)
542
472
  cur.count += delta;
543
- if (cur.left && this._compare(cur.left.id, id) === types_1.CP.gt)
473
+ if (cur.left && this._compare(cur.left.key, key) === types_1.CP.gt)
544
474
  queue.push(cur.left);
545
- if (cur.right && this._compare(cur.right.id, id) === types_1.CP.gt)
475
+ if (cur.right && this._compare(cur.right.key, key) === types_1.CP.gt)
546
476
  queue.push(cur.right);
547
477
  }
548
478
  }
549
479
  return true;
550
480
  }
551
- };
552
- TreeMultiset.prototype.clear = function () {
553
- _super.prototype.clear.call(this);
481
+ }
482
+ clear() {
483
+ super.clear();
554
484
  this._setCount(0);
555
- };
556
- TreeMultiset.prototype._setCount = function (v) {
485
+ }
486
+ _setCount(v) {
557
487
  this._count = v;
558
- };
559
- return TreeMultiset;
560
- }(avl_tree_1.AVLTree));
488
+ }
489
+ }
561
490
  exports.TreeMultiset = TreeMultiset;
562
491
  //# sourceMappingURL=tree-multiset.js.map