avl-tree-typed 1.52.5 → 1.52.8

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 (77) hide show
  1. package/dist/constants/index.d.ts +4 -0
  2. package/dist/constants/index.js +8 -0
  3. package/dist/data-structures/base/iterable-element-base.d.ts +8 -1
  4. package/dist/data-structures/base/iterable-element-base.js +10 -1
  5. package/dist/data-structures/base/iterable-entry-base.d.ts +8 -1
  6. package/dist/data-structures/base/iterable-entry-base.js +10 -10
  7. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
  8. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +43 -44
  9. package/dist/data-structures/binary-tree/avl-tree.d.ts +23 -24
  10. package/dist/data-structures/binary-tree/avl-tree.js +71 -64
  11. package/dist/data-structures/binary-tree/binary-indexed-tree.js +2 -2
  12. package/dist/data-structures/binary-tree/binary-tree.d.ts +534 -402
  13. package/dist/data-structures/binary-tree/binary-tree.js +669 -598
  14. package/dist/data-structures/binary-tree/bst.d.ts +72 -65
  15. package/dist/data-structures/binary-tree/bst.js +115 -113
  16. package/dist/data-structures/binary-tree/rb-tree.d.ts +21 -24
  17. package/dist/data-structures/binary-tree/rb-tree.js +40 -39
  18. package/dist/data-structures/binary-tree/segment-tree.d.ts +2 -2
  19. package/dist/data-structures/binary-tree/segment-tree.js +2 -2
  20. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
  21. package/dist/data-structures/binary-tree/tree-multi-map.js +44 -43
  22. package/dist/data-structures/graph/abstract-graph.d.ts +2 -2
  23. package/dist/data-structures/graph/abstract-graph.js +7 -4
  24. package/dist/data-structures/graph/directed-graph.d.ts +2 -2
  25. package/dist/data-structures/graph/directed-graph.js +4 -2
  26. package/dist/data-structures/graph/undirected-graph.d.ts +2 -2
  27. package/dist/data-structures/hash/hash-map.d.ts +2 -2
  28. package/dist/data-structures/hash/hash-map.js +1 -1
  29. package/dist/data-structures/heap/heap.js +3 -3
  30. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  31. package/dist/data-structures/linked-list/doubly-linked-list.js +7 -7
  32. package/dist/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  33. package/dist/data-structures/linked-list/singly-linked-list.js +6 -6
  34. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  35. package/dist/data-structures/matrix/matrix.d.ts +2 -2
  36. package/dist/data-structures/matrix/navigator.d.ts +2 -2
  37. package/dist/data-structures/matrix/navigator.js +4 -2
  38. package/dist/data-structures/queue/deque.d.ts +3 -3
  39. package/dist/data-structures/queue/deque.js +29 -29
  40. package/dist/data-structures/queue/queue.d.ts +1 -1
  41. package/dist/data-structures/stack/stack.d.ts +2 -2
  42. package/dist/data-structures/trie/trie.d.ts +2 -2
  43. package/dist/data-structures/trie/trie.js +1 -1
  44. package/dist/index.d.ts +1 -0
  45. package/dist/index.js +1 -0
  46. package/dist/interfaces/binary-tree.d.ts +2 -2
  47. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
  48. package/dist/types/data-structures/binary-tree/binary-tree.js +0 -6
  49. package/package.json +2 -2
  50. package/src/constants/index.ts +4 -0
  51. package/src/data-structures/base/iterable-element-base.ts +11 -1
  52. package/src/data-structures/base/iterable-entry-base.ts +11 -19
  53. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +47 -50
  54. package/src/data-structures/binary-tree/avl-tree.ts +69 -71
  55. package/src/data-structures/binary-tree/binary-indexed-tree.ts +2 -2
  56. package/src/data-structures/binary-tree/binary-tree.ts +698 -726
  57. package/src/data-structures/binary-tree/bst.ts +123 -129
  58. package/src/data-structures/binary-tree/rb-tree.ts +44 -46
  59. package/src/data-structures/binary-tree/segment-tree.ts +2 -2
  60. package/src/data-structures/binary-tree/tree-multi-map.ts +48 -49
  61. package/src/data-structures/graph/abstract-graph.ts +6 -6
  62. package/src/data-structures/graph/directed-graph.ts +4 -4
  63. package/src/data-structures/graph/undirected-graph.ts +2 -2
  64. package/src/data-structures/hash/hash-map.ts +3 -3
  65. package/src/data-structures/heap/heap.ts +3 -3
  66. package/src/data-structures/linked-list/doubly-linked-list.ts +9 -9
  67. package/src/data-structures/linked-list/singly-linked-list.ts +8 -8
  68. package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
  69. package/src/data-structures/matrix/matrix.ts +2 -2
  70. package/src/data-structures/matrix/navigator.ts +4 -4
  71. package/src/data-structures/queue/deque.ts +31 -31
  72. package/src/data-structures/queue/queue.ts +1 -1
  73. package/src/data-structures/stack/stack.ts +2 -2
  74. package/src/data-structures/trie/trie.ts +3 -3
  75. package/src/index.ts +1 -0
  76. package/src/interfaces/binary-tree.ts +3 -3
  77. package/src/types/data-structures/binary-tree/binary-tree.ts +3 -5
@@ -242,7 +242,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
242
242
  * or the linked list is empty, it will return undefined.
243
243
  */
244
244
  at(index) {
245
- if (index < 0 || index >= this.size)
245
+ if (index < 0 || index >= this._size)
246
246
  return undefined;
247
247
  let current = this.head;
248
248
  for (let i = 0; i < index; i++) {
@@ -262,7 +262,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
262
262
  * valid range of the linked list, otherwise it returns `undefined`.
263
263
  */
264
264
  getNodeAt(index) {
265
- if (index < 0 || index >= this.size)
265
+ if (index < 0 || index >= this._size)
266
266
  return undefined;
267
267
  let current = this.head;
268
268
  for (let i = 0; i < index; i++) {
@@ -303,13 +303,13 @@ class DoublyLinkedList extends base_1.IterableElementBase {
303
303
  * if the index is out of bounds.
304
304
  */
305
305
  addAt(index, value) {
306
- if (index < 0 || index > this.size)
306
+ if (index < 0 || index > this._size)
307
307
  return false;
308
308
  if (index === 0) {
309
309
  this.unshift(value);
310
310
  return true;
311
311
  }
312
- if (index === this.size) {
312
+ if (index === this._size) {
313
313
  this.push(value);
314
314
  return true;
315
315
  }
@@ -407,13 +407,13 @@ class DoublyLinkedList extends base_1.IterableElementBase {
407
407
  * bounds.
408
408
  */
409
409
  deleteAt(index) {
410
- if (index < 0 || index >= this.size)
410
+ if (index < 0 || index >= this._size)
411
411
  return false;
412
412
  if (index === 0) {
413
413
  this.shift();
414
414
  return true;
415
415
  }
416
- if (index === this.size - 1) {
416
+ if (index === this._size - 1) {
417
417
  this.pop();
418
418
  return true;
419
419
  }
@@ -469,7 +469,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
469
469
  * @returns A boolean value is being returned.
470
470
  */
471
471
  isEmpty() {
472
- return this.size === 0;
472
+ return this._size === 0;
473
473
  }
474
474
  /**
475
475
  * Time Complexity: O(1)
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { ElementCallback, SinglyLinkedListOptions } from '../../types';
@@ -213,7 +213,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
213
213
  * `undefined` if the index is out of bounds.
214
214
  */
215
215
  at(index) {
216
- if (index < 0 || index >= this.size)
216
+ if (index < 0 || index >= this._size)
217
217
  return undefined;
218
218
  let current = this.head;
219
219
  for (let i = 0; i < index; i++) {
@@ -249,13 +249,13 @@ class SinglyLinkedList extends base_1.IterableElementBase {
249
249
  * bounds.
250
250
  */
251
251
  deleteAt(index) {
252
- if (index < 0 || index >= this.size)
252
+ if (index < 0 || index >= this._size)
253
253
  return false;
254
254
  if (index === 0) {
255
255
  this.shift();
256
256
  return true;
257
257
  }
258
- if (index === this.size - 1) {
258
+ if (index === this._size - 1) {
259
259
  this.pop();
260
260
  return true;
261
261
  }
@@ -321,13 +321,13 @@ class SinglyLinkedList extends base_1.IterableElementBase {
321
321
  * if the index is out of bounds.
322
322
  */
323
323
  addAt(index, value) {
324
- if (index < 0 || index > this.size)
324
+ if (index < 0 || index > this._size)
325
325
  return false;
326
326
  if (index === 0) {
327
327
  this.unshift(value);
328
328
  return true;
329
329
  }
330
- if (index === this.size) {
330
+ if (index === this._size) {
331
331
  this.push(value);
332
332
  return true;
333
333
  }
@@ -344,7 +344,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
344
344
  * @returns A boolean value indicating whether the length of the object is equal to 0.
345
345
  */
346
346
  isEmpty() {
347
- return this.size === 0;
347
+ return this._size === 0;
348
348
  }
349
349
  /**
350
350
  * The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { SkipLinkedListOptions } from '../../types';
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { MatrixOptions } from '../../types';
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { Direction, NavigatorParams, Turning } from '../../types';
@@ -27,7 +27,8 @@ class Navigator {
27
27
  this._cur = cur;
28
28
  this._character = new Character(charDir, turning);
29
29
  this.onMove = onMove;
30
- this.onMove && this.onMove(this._cur);
30
+ if (this.onMove)
31
+ this.onMove(this._cur);
31
32
  this._VISITED = VISITED;
32
33
  this._matrix[this._cur[0]][this._cur[1]] = this._VISITED;
33
34
  }
@@ -100,7 +101,8 @@ class Navigator {
100
101
  }
101
102
  const [i, j] = this._cur;
102
103
  this._matrix[i][j] = this._VISITED;
103
- this.onMove && this.onMove(this._cur);
104
+ if (this.onMove)
105
+ this.onMove(this._cur);
104
106
  }
105
107
  }
106
108
  exports.Navigator = Navigator;
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { DequeOptions, ElementCallback, IterableWithSizeOrLength } from '../../types';
@@ -287,7 +287,7 @@ export declare class Deque<E = any, R = any> extends IterableElementBase<E, R, D
287
287
  * The `shrinkToFit` function reorganizes the elements in an array-like data structure to minimize
288
288
  * memory usage.
289
289
  * @returns Nothing is being returned. The function is using the `return` statement to exit early if
290
- * `this.size` is 0, but it does not return any value.
290
+ * `this._size` is 0, but it does not return any value.
291
291
  */
292
292
  shrinkToFit(): void;
293
293
  /**
@@ -142,7 +142,7 @@ class Deque extends base_1.IterableElementBase {
142
142
  * @returns The first element of the collection, of type E, is being returned.
143
143
  */
144
144
  get first() {
145
- if (this.size === 0)
145
+ if (this._size === 0)
146
146
  return;
147
147
  return this._buckets[this._bucketFirst][this._firstInBucket];
148
148
  }
@@ -151,7 +151,7 @@ class Deque extends base_1.IterableElementBase {
151
151
  * @return The last element in the array
152
152
  */
153
153
  get last() {
154
- if (this.size === 0)
154
+ if (this._size === 0)
155
155
  return;
156
156
  return this._buckets[this._bucketLast][this._lastInBucket];
157
157
  }
@@ -165,7 +165,7 @@ class Deque extends base_1.IterableElementBase {
165
165
  * @returns The size of the data structure after the element has been pushed.
166
166
  */
167
167
  push(element) {
168
- if (this.size) {
168
+ if (this._size) {
169
169
  if (this._lastInBucket < this._bucketSize - 1) {
170
170
  this._lastInBucket += 1;
171
171
  }
@@ -195,10 +195,10 @@ class Deque extends base_1.IterableElementBase {
195
195
  * @returns The element that was removed from the data structure is being returned.
196
196
  */
197
197
  pop() {
198
- if (this.size === 0)
198
+ if (this._size === 0)
199
199
  return;
200
200
  const element = this._buckets[this._bucketLast][this._lastInBucket];
201
- if (this.size !== 1) {
201
+ if (this._size !== 1) {
202
202
  if (this._lastInBucket > 0) {
203
203
  this._lastInBucket -= 1;
204
204
  }
@@ -225,7 +225,7 @@ class Deque extends base_1.IterableElementBase {
225
225
  * @returns The size of the data structure after the element has been added.
226
226
  */
227
227
  unshift(element) {
228
- if (this.size) {
228
+ if (this._size) {
229
229
  if (this._firstInBucket > 0) {
230
230
  this._firstInBucket -= 1;
231
231
  }
@@ -256,10 +256,10 @@ class Deque extends base_1.IterableElementBase {
256
256
  * returned.
257
257
  */
258
258
  shift() {
259
- if (this.size === 0)
259
+ if (this._size === 0)
260
260
  return;
261
261
  const element = this._buckets[this._bucketFirst][this._firstInBucket];
262
- if (this.size !== 1) {
262
+ if (this._size !== 1) {
263
263
  if (this._firstInBucket < this._bucketSize - 1) {
264
264
  this._firstInBucket += 1;
265
265
  }
@@ -283,7 +283,7 @@ class Deque extends base_1.IterableElementBase {
283
283
  * @returns A boolean value indicating whether the size of the object is 0 or not.
284
284
  */
285
285
  isEmpty() {
286
- return this.size === 0;
286
+ return this._size === 0;
287
287
  }
288
288
  /**
289
289
  * Time Complexity: O(1)
@@ -303,7 +303,7 @@ class Deque extends base_1.IterableElementBase {
303
303
  */
304
304
  *begin() {
305
305
  let index = 0;
306
- while (index < this.size) {
306
+ while (index < this._size) {
307
307
  yield this.at(index);
308
308
  index++;
309
309
  }
@@ -313,7 +313,7 @@ class Deque extends base_1.IterableElementBase {
313
313
  * the last element.
314
314
  */
315
315
  *reverseBegin() {
316
- let index = this.size - 1;
316
+ let index = this._size - 1;
317
317
  while (index >= 0) {
318
318
  yield this.at(index);
319
319
  index--;
@@ -330,7 +330,7 @@ class Deque extends base_1.IterableElementBase {
330
330
  * @returns The element at the specified position in the data structure is being returned.
331
331
  */
332
332
  at(pos) {
333
- (0, utils_1.rangeCheck)(pos, 0, this.size - 1);
333
+ (0, utils_1.rangeCheck)(pos, 0, this._size - 1);
334
334
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
335
335
  return this._buckets[bucketIndex][indexInBucket];
336
336
  }
@@ -345,7 +345,7 @@ class Deque extends base_1.IterableElementBase {
345
345
  * position in the data structure.
346
346
  */
347
347
  setAt(pos, element) {
348
- (0, utils_1.rangeCheck)(pos, 0, this.size - 1);
348
+ (0, utils_1.rangeCheck)(pos, 0, this._size - 1);
349
349
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
350
350
  this._buckets[bucketIndex][indexInBucket] = element;
351
351
  return true;
@@ -366,19 +366,19 @@ class Deque extends base_1.IterableElementBase {
366
366
  * @returns The size of the array after the insertion is being returned.
367
367
  */
368
368
  addAt(pos, element, num = 1) {
369
- const length = this.size;
369
+ const length = this._size;
370
370
  (0, utils_1.rangeCheck)(pos, 0, length);
371
371
  if (pos === 0) {
372
372
  while (num--)
373
373
  this.unshift(element);
374
374
  }
375
- else if (pos === this.size) {
375
+ else if (pos === this._size) {
376
376
  while (num--)
377
377
  this.push(element);
378
378
  }
379
379
  else {
380
380
  const arr = [];
381
- for (let i = pos; i < this.size; ++i) {
381
+ for (let i = pos; i < this._size; ++i) {
382
382
  arr.push(this.at(i));
383
383
  }
384
384
  this.cut(pos - 1, true);
@@ -450,7 +450,7 @@ class Deque extends base_1.IterableElementBase {
450
450
  const newDeque = new Deque([], { bucketSize: this._bucketSize });
451
451
  if (pos < 0)
452
452
  pos = 0;
453
- for (let i = pos; i < this.size; i++) {
453
+ for (let i = pos; i < this._size; i++) {
454
454
  newDeque.push(this.at(i));
455
455
  }
456
456
  return newDeque;
@@ -468,13 +468,13 @@ class Deque extends base_1.IterableElementBase {
468
468
  * @returns The size of the data structure after the deletion operation is performed.
469
469
  */
470
470
  deleteAt(pos) {
471
- (0, utils_1.rangeCheck)(pos, 0, this.size - 1);
471
+ (0, utils_1.rangeCheck)(pos, 0, this._size - 1);
472
472
  if (pos === 0)
473
473
  this.shift();
474
- else if (pos === this.size - 1)
474
+ else if (pos === this._size - 1)
475
475
  this.pop();
476
476
  else {
477
- const length = this.size - 1;
477
+ const length = this._size - 1;
478
478
  let { bucketIndex: curBucket, indexInBucket: curPointer } = this._getBucketAndPosition(pos);
479
479
  for (let i = pos; i < length; ++i) {
480
480
  const { bucketIndex: nextBucket, indexInBucket: nextPointer } = this._getBucketAndPosition(pos + 1);
@@ -497,7 +497,7 @@ class Deque extends base_1.IterableElementBase {
497
497
  * @returns The size of the data structure after the element has been deleted.
498
498
  */
499
499
  delete(element) {
500
- const size = this.size;
500
+ const size = this._size;
501
501
  if (size === 0)
502
502
  return false;
503
503
  let i = 0;
@@ -542,12 +542,12 @@ class Deque extends base_1.IterableElementBase {
542
542
  * @returns The size of the modified array is being returned.
543
543
  */
544
544
  unique() {
545
- if (this.size <= 1) {
545
+ if (this._size <= 1) {
546
546
  return this;
547
547
  }
548
548
  let index = 1;
549
549
  let prev = this.at(0);
550
- for (let i = 1; i < this.size; ++i) {
550
+ for (let i = 1; i < this._size; ++i) {
551
551
  const cur = this.at(i);
552
552
  if (cur !== prev) {
553
553
  prev = cur;
@@ -569,11 +569,11 @@ class Deque extends base_1.IterableElementBase {
569
569
  */
570
570
  sort(comparator) {
571
571
  const arr = [];
572
- for (let i = 0; i < this.size; ++i) {
572
+ for (let i = 0; i < this._size; ++i) {
573
573
  arr.push(this.at(i));
574
574
  }
575
575
  arr.sort(comparator);
576
- for (let i = 0; i < this.size; ++i) {
576
+ for (let i = 0; i < this._size; ++i) {
577
577
  this.setAt(i, arr[i]);
578
578
  }
579
579
  return this;
@@ -585,10 +585,10 @@ class Deque extends base_1.IterableElementBase {
585
585
  * The `shrinkToFit` function reorganizes the elements in an array-like data structure to minimize
586
586
  * memory usage.
587
587
  * @returns Nothing is being returned. The function is using the `return` statement to exit early if
588
- * `this.size` is 0, but it does not return any value.
588
+ * `this._size` is 0, but it does not return any value.
589
589
  */
590
590
  shrinkToFit() {
591
- if (this.size === 0)
591
+ if (this._size === 0)
592
592
  return;
593
593
  const newBuckets = [];
594
594
  if (this._bucketFirst === this._bucketLast)
@@ -622,7 +622,7 @@ class Deque extends base_1.IterableElementBase {
622
622
  * in the data structure. If the element is not found, it returns -1.
623
623
  */
624
624
  indexOf(element) {
625
- for (let i = 0; i < this.size; ++i) {
625
+ for (let i = 0; i < this._size; ++i) {
626
626
  if (this.at(i) === element) {
627
627
  return i;
628
628
  }
@@ -713,7 +713,7 @@ class Deque extends base_1.IterableElementBase {
713
713
  * object to be iterated over using a for...of loop.
714
714
  */
715
715
  *_getIterator() {
716
- for (let i = 0; i < this.size; ++i) {
716
+ for (let i = 0; i < this._size; ++i) {
717
717
  yield this.at(i);
718
718
  }
719
719
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license MIT
3
- * @copyright Tyler Zeng <zrwusa@gmail.com>
3
+ * @copyright Pablo Zeng <zrwusa@gmail.com>
4
4
  * @class
5
5
  */
6
6
  import type { ElementCallback, QueueOptions } from '../../types';
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { ElementCallback, StackOptions } from '../../types';
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { ElementCallback, TrieOptions } from '../../types';
@@ -178,7 +178,7 @@ class Trie extends base_1.IterableElementBase {
178
178
  * @return True if the size of the queue is 0
179
179
  */
180
180
  isEmpty() {
181
- return this.size === 0;
181
+ return this._size === 0;
182
182
  }
183
183
  /**
184
184
  * Time Complexity: O(1)
package/dist/index.d.ts CHANGED
@@ -12,3 +12,4 @@ export * from './types/data-structures/binary-tree/avl-tree';
12
12
  export * from './types/data-structures/binary-tree/bst';
13
13
  export * from './types/data-structures/binary-tree/binary-tree';
14
14
  export * from './types/common';
15
+ export * from './constants';
package/dist/index.js CHANGED
@@ -28,3 +28,4 @@ __exportStar(require("./types/data-structures/binary-tree/avl-tree"), exports);
28
28
  __exportStar(require("./types/data-structures/binary-tree/bst"), exports);
29
29
  __exportStar(require("./types/data-structures/binary-tree/binary-tree"), exports);
30
30
  __exportStar(require("./types/common"), exports);
31
+ __exportStar(require("./constants"), exports);
@@ -1,9 +1,9 @@
1
1
  import { BinaryTree, BinaryTreeNode } from '../data-structures';
2
- import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNKeyOrNodeOrEntry } from '../types';
2
+ import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNKeyOrNodeOrEntry, BTNPredicate } from '../types';
3
3
  export interface IBinaryTree<K = any, V = any, R = [K, V], NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNodeNested<K, V>, TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTreeNested<K, V, R, NODE>> {
4
4
  createNode(key: K, value?: NODE['value']): NODE;
5
5
  createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): TREE;
6
6
  add(keyOrNodeOrEntryOrRawElement: BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
7
7
  addMany(nodes: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): boolean[];
8
- delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeleteResult<NODE>[];
8
+ delete(predicate: R | BTNKeyOrNodeOrEntry<K, V, NODE> | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[];
9
9
  }
@@ -1,5 +1,6 @@
1
1
  import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
2
2
  import { IterationType, OptValue } from '../../common';
3
+ import { DFSOperation } from '../../../constants';
3
4
  export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
5
  export type BinaryTreeNested<K, V, R, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
6
  export type BinaryTreeOptions<K, V, R> = {
@@ -23,10 +24,7 @@ export type BinaryTreeDeleteResult<NODE> = {
23
24
  needBalanced: OptBTNOrNull<NODE>;
24
25
  };
25
26
  export type BTNCallback<NODE, D = any> = (node: NODE) => D;
26
- export declare enum DFSOperation {
27
- VISIT = 0,
28
- PROCESS = 1
29
- }
27
+ export type BTNPredicate<NODE> = (node: NODE) => boolean;
30
28
  export type DFSStackItem<NODE> = {
31
29
  opt: DFSOperation;
32
30
  node: OptBTNOrNull<NODE>;
@@ -1,8 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DFSOperation = void 0;
4
- var DFSOperation;
5
- (function (DFSOperation) {
6
- DFSOperation[DFSOperation["VISIT"] = 0] = "VISIT";
7
- DFSOperation[DFSOperation["PROCESS"] = 1] = "PROCESS";
8
- })(DFSOperation = exports.DFSOperation || (exports.DFSOperation = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "avl-tree-typed",
3
- "version": "1.52.5",
3
+ "version": "1.52.8",
4
4
  "description": "AVLTree(Adelson-Velsky and Landis Tree). Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -163,6 +163,6 @@
163
163
  "typescript": "^4.9.5"
164
164
  },
165
165
  "dependencies": {
166
- "data-structure-typed": "^1.52.5"
166
+ "data-structure-typed": "^1.52.8"
167
167
  }
168
168
  }
@@ -0,0 +1,4 @@
1
+ export enum DFSOperation {
2
+ VISIT = 0,
3
+ PROCESS = 1
4
+ }
@@ -192,10 +192,20 @@ export abstract class IterableElementBase<E, R, C> {
192
192
  *
193
193
  * The print function logs the elements of an array to the console.
194
194
  */
195
- print(): E[] {
195
+ toVisual(): E[] {
196
196
  return [...this];
197
197
  }
198
198
 
199
+ /**
200
+ * Time Complexity: O(n)
201
+ * Space Complexity: O(n)
202
+ *
203
+ * The print function logs the elements of an array to the console.
204
+ */
205
+ print(): void {
206
+ console.log(this.toVisual());
207
+ }
208
+
199
209
  abstract isEmpty(): boolean;
200
210
 
201
211
  abstract clear(): void;
@@ -1,26 +1,8 @@
1
1
  import { EntryCallback, ReduceEntryCallback } from '../../types';
2
2
 
3
3
  export abstract class IterableEntryBase<K = any, V = any> {
4
- // protected constructor(options?: IterableEntryBaseOptions<K, V, R>) {
5
- // if (options) {
6
- // const { toEntryFn } = options;
7
- // if (typeof toEntryFn === 'function') this._toEntryFn = toEntryFn
8
- // else throw new TypeError('toEntryFn must be a function type');
9
- // }
10
- // }
11
-
12
4
  abstract get size(): number;
13
5
 
14
- // protected _toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
15
- //
16
- // /**
17
- // * The function returns the value of the _toEntryFn property.
18
- // * @returns The function being returned is `this._toEntryFn`.
19
- // */
20
- // get toEntryFn() {
21
- // return this._toEntryFn;
22
- // }
23
-
24
6
  /**
25
7
  * Time Complexity: O(n)
26
8
  * Space Complexity: O(1)
@@ -251,10 +233,20 @@ export abstract class IterableEntryBase<K = any, V = any> {
251
233
  *
252
234
  * The print function logs the elements of an array to the console.
253
235
  */
254
- print(): [K, V][] | string {
236
+ toVisual(): [K, V][] | string {
255
237
  return [...this];
256
238
  }
257
239
 
240
+ /**
241
+ * Time Complexity: O(n)
242
+ * Space Complexity: O(n)
243
+ *
244
+ * The print function logs the elements of an array to the console.
245
+ */
246
+ print(): void {
247
+ console.log(this.toVisual());
248
+ }
249
+
258
250
  abstract isEmpty(): boolean;
259
251
 
260
252
  abstract clear(): void;