data-structure-typed 1.47.5 → 1.47.6

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 (139) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +8 -8
  3. package/dist/cjs/data-structures/binary-tree/avl-tree.js +23 -15
  4. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  5. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +65 -28
  6. package/dist/cjs/data-structures/binary-tree/binary-tree.js +66 -82
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/bst.d.ts +38 -37
  9. package/dist/cjs/data-structures/binary-tree/bst.js +56 -40
  10. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +11 -7
  12. package/dist/cjs/data-structures/binary-tree/rb-tree.js +26 -17
  13. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +16 -16
  15. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +31 -22
  16. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  17. package/dist/cjs/data-structures/graph/abstract-graph.js +1 -1
  18. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  19. package/dist/cjs/data-structures/heap/heap.d.ts +19 -21
  20. package/dist/cjs/data-structures/heap/heap.js +52 -34
  21. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  22. package/dist/cjs/data-structures/heap/max-heap.d.ts +2 -5
  23. package/dist/cjs/data-structures/heap/max-heap.js +2 -2
  24. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  25. package/dist/cjs/data-structures/heap/min-heap.d.ts +2 -5
  26. package/dist/cjs/data-structures/heap/min-heap.js +2 -2
  27. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  28. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  29. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +9 -1
  30. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  31. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  32. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +8 -1
  33. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  34. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +2 -5
  35. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +2 -2
  36. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  37. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +2 -5
  38. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +2 -2
  39. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  40. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +2 -5
  41. package/dist/cjs/data-structures/priority-queue/priority-queue.js +2 -2
  42. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  43. package/dist/cjs/data-structures/queue/deque.d.ts +1 -0
  44. package/dist/cjs/data-structures/queue/deque.js +3 -0
  45. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  46. package/dist/cjs/data-structures/queue/queue.d.ts +1 -0
  47. package/dist/cjs/data-structures/queue/queue.js +3 -0
  48. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  49. package/dist/cjs/data-structures/stack/stack.d.ts +2 -1
  50. package/dist/cjs/data-structures/stack/stack.js +10 -2
  51. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  52. package/dist/cjs/interfaces/binary-tree.d.ts +3 -1
  53. package/dist/cjs/types/common.d.ts +2 -0
  54. package/dist/cjs/types/common.js.map +1 -1
  55. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  56. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +2 -2
  57. package/dist/cjs/types/data-structures/heap/heap.d.ts +4 -1
  58. package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +2 -1
  59. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +8 -8
  60. package/dist/mjs/data-structures/binary-tree/avl-tree.js +26 -16
  61. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +65 -28
  62. package/dist/mjs/data-structures/binary-tree/binary-tree.js +66 -83
  63. package/dist/mjs/data-structures/binary-tree/bst.d.ts +38 -37
  64. package/dist/mjs/data-structures/binary-tree/bst.js +59 -41
  65. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +11 -7
  66. package/dist/mjs/data-structures/binary-tree/rb-tree.js +30 -19
  67. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +16 -16
  68. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +34 -23
  69. package/dist/mjs/data-structures/graph/abstract-graph.js +1 -1
  70. package/dist/mjs/data-structures/heap/heap.d.ts +19 -21
  71. package/dist/mjs/data-structures/heap/heap.js +53 -35
  72. package/dist/mjs/data-structures/heap/max-heap.d.ts +2 -5
  73. package/dist/mjs/data-structures/heap/max-heap.js +2 -2
  74. package/dist/mjs/data-structures/heap/min-heap.d.ts +2 -5
  75. package/dist/mjs/data-structures/heap/min-heap.js +2 -2
  76. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  77. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +9 -1
  78. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  79. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +8 -1
  80. package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +2 -5
  81. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +2 -2
  82. package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +2 -5
  83. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +2 -2
  84. package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +2 -5
  85. package/dist/mjs/data-structures/priority-queue/priority-queue.js +2 -2
  86. package/dist/mjs/data-structures/queue/deque.d.ts +1 -0
  87. package/dist/mjs/data-structures/queue/deque.js +3 -0
  88. package/dist/mjs/data-structures/queue/queue.d.ts +1 -0
  89. package/dist/mjs/data-structures/queue/queue.js +3 -0
  90. package/dist/mjs/data-structures/stack/stack.d.ts +2 -1
  91. package/dist/mjs/data-structures/stack/stack.js +10 -2
  92. package/dist/mjs/interfaces/binary-tree.d.ts +3 -1
  93. package/dist/mjs/types/common.d.ts +2 -0
  94. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  95. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +2 -2
  96. package/dist/mjs/types/data-structures/heap/heap.d.ts +4 -1
  97. package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +2 -1
  98. package/dist/umd/data-structure-typed.js +307 -229
  99. package/dist/umd/data-structure-typed.min.js +2 -2
  100. package/dist/umd/data-structure-typed.min.js.map +1 -1
  101. package/package.json +1 -1
  102. package/src/data-structures/binary-tree/avl-tree.ts +27 -17
  103. package/src/data-structures/binary-tree/binary-tree.ts +114 -97
  104. package/src/data-structures/binary-tree/bst.ts +67 -47
  105. package/src/data-structures/binary-tree/rb-tree.ts +34 -20
  106. package/src/data-structures/binary-tree/tree-multimap.ts +43 -25
  107. package/src/data-structures/graph/abstract-graph.ts +1 -1
  108. package/src/data-structures/heap/heap.ts +57 -39
  109. package/src/data-structures/heap/max-heap.ts +5 -5
  110. package/src/data-structures/heap/min-heap.ts +5 -5
  111. package/src/data-structures/linked-list/doubly-linked-list.ts +10 -1
  112. package/src/data-structures/linked-list/singly-linked-list.ts +9 -1
  113. package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
  114. package/src/data-structures/priority-queue/min-priority-queue.ts +12 -12
  115. package/src/data-structures/priority-queue/priority-queue.ts +3 -3
  116. package/src/data-structures/queue/deque.ts +4 -0
  117. package/src/data-structures/queue/queue.ts +4 -0
  118. package/src/data-structures/stack/stack.ts +12 -3
  119. package/src/interfaces/binary-tree.ts +13 -1
  120. package/src/types/common.ts +5 -1
  121. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  122. package/src/types/data-structures/binary-tree/bst.ts +2 -3
  123. package/src/types/data-structures/heap/heap.ts +3 -1
  124. package/src/types/data-structures/priority-queue/priority-queue.ts +3 -1
  125. package/test/performance/data-structures/comparison/comparison.test.ts +7 -6
  126. package/test/performance/data-structures/heap/heap.test.ts +2 -2
  127. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +1 -1
  128. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +1 -1
  129. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +6 -6
  130. package/test/unit/data-structures/binary-tree/bst.test.ts +1 -1
  131. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +1 -1
  132. package/test/unit/data-structures/heap/heap.test.ts +2 -2
  133. package/test/unit/data-structures/heap/max-heap.test.ts +1 -1
  134. package/test/unit/data-structures/heap/min-heap.test.ts +1 -1
  135. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +4 -3
  136. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +9 -10
  137. package/test/unit/data-structures/stack/stack.test.ts +2 -2
  138. package/test/unit/unrestricted-interconversion.test.ts +100 -0
  139. package/test/integration/conversion.test.ts +0 -0
@@ -886,13 +886,17 @@ var dataStructureTyped = (() => {
886
886
  /**
887
887
  * The constructor initializes the linked list with an empty head, tail, and length.
888
888
  */
889
- constructor() {
889
+ constructor(elements) {
890
890
  __publicField(this, "_head");
891
891
  __publicField(this, "_tail");
892
892
  __publicField(this, "_length");
893
893
  this._head = null;
894
894
  this._tail = null;
895
895
  this._length = 0;
896
+ if (elements) {
897
+ for (const el of elements)
898
+ this.push(el);
899
+ }
896
900
  }
897
901
  get head() {
898
902
  return this._head;
@@ -1568,6 +1572,9 @@ var dataStructureTyped = (() => {
1568
1572
  }
1569
1573
  return accumulator;
1570
1574
  }
1575
+ print() {
1576
+ console.log([...this]);
1577
+ }
1571
1578
  };
1572
1579
 
1573
1580
  // src/data-structures/linked-list/doubly-linked-list.ts
@@ -1590,13 +1597,18 @@ var dataStructureTyped = (() => {
1590
1597
  /**
1591
1598
  * The constructor initializes the linked list with an empty head, tail, and length.
1592
1599
  */
1593
- constructor() {
1600
+ constructor(elements) {
1594
1601
  __publicField(this, "_head");
1595
1602
  __publicField(this, "_tail");
1596
1603
  __publicField(this, "_length");
1597
1604
  this._head = null;
1598
1605
  this._tail = null;
1599
1606
  this._length = 0;
1607
+ if (elements) {
1608
+ for (const el of elements) {
1609
+ this.push(el);
1610
+ }
1611
+ }
1600
1612
  }
1601
1613
  get head() {
1602
1614
  return this._head;
@@ -2325,6 +2337,9 @@ var dataStructureTyped = (() => {
2325
2337
  }
2326
2338
  return accumulator;
2327
2339
  }
2340
+ print() {
2341
+ console.log([...this]);
2342
+ }
2328
2343
  };
2329
2344
 
2330
2345
  // src/data-structures/linked-list/skip-linked-list.ts
@@ -2585,7 +2600,12 @@ var dataStructureTyped = (() => {
2585
2600
  */
2586
2601
  constructor(elements) {
2587
2602
  __publicField(this, "_elements");
2588
- this._elements = Array.isArray(elements) ? elements : [];
2603
+ this._elements = [];
2604
+ if (elements) {
2605
+ for (const el of elements) {
2606
+ this.push(el);
2607
+ }
2608
+ }
2589
2609
  }
2590
2610
  get elements() {
2591
2611
  return this._elements;
@@ -2708,7 +2728,7 @@ var dataStructureTyped = (() => {
2708
2728
  * @returns An iterator object.
2709
2729
  */
2710
2730
  *[Symbol.iterator]() {
2711
- for (let i = this.elements.length - 1; i >= 0; i--) {
2731
+ for (let i = 0; i < this.elements.length; i++) {
2712
2732
  yield this.elements[i];
2713
2733
  }
2714
2734
  }
@@ -2752,6 +2772,9 @@ var dataStructureTyped = (() => {
2752
2772
  }
2753
2773
  return accumulator;
2754
2774
  }
2775
+ print() {
2776
+ console.log([...this]);
2777
+ }
2755
2778
  };
2756
2779
 
2757
2780
  // src/data-structures/queue/queue.ts
@@ -3012,6 +3035,9 @@ var dataStructureTyped = (() => {
3012
3035
  clone() {
3013
3036
  return new _Queue(this.nodes.slice(this.offset));
3014
3037
  }
3038
+ print() {
3039
+ console.log([...this]);
3040
+ }
3015
3041
  *[Symbol.iterator]() {
3016
3042
  for (const item of this.nodes) {
3017
3043
  yield item;
@@ -3845,6 +3871,9 @@ var dataStructureTyped = (() => {
3845
3871
  }
3846
3872
  return accumulator;
3847
3873
  }
3874
+ print() {
3875
+ console.log([...this]);
3876
+ }
3848
3877
  /**
3849
3878
  * Time Complexity: O(n)
3850
3879
  * Space Complexity: O(n)
@@ -4075,21 +4104,32 @@ var dataStructureTyped = (() => {
4075
4104
 
4076
4105
  // src/data-structures/heap/heap.ts
4077
4106
  var Heap = class _Heap {
4078
- constructor(options) {
4107
+ constructor(elements, options) {
4108
+ __publicField(this, "options");
4079
4109
  __publicField(this, "_elements", []);
4080
- __publicField(this, "_comparator");
4081
- this._comparator = options.comparator;
4082
- if (options.elements && options.elements.length > 0) {
4083
- this._elements = options.elements;
4084
- this.fix();
4110
+ const defaultComparator = (a, b) => {
4111
+ if (!(typeof a === "number" && typeof b === "number")) {
4112
+ throw new Error("The a, b params of compare function must be number");
4113
+ } else {
4114
+ return a - b;
4115
+ }
4116
+ };
4117
+ if (options) {
4118
+ this.options = options;
4119
+ } else {
4120
+ this.options = {
4121
+ comparator: defaultComparator
4122
+ };
4123
+ }
4124
+ if (elements) {
4125
+ for (const el of elements) {
4126
+ this.push(el);
4127
+ }
4085
4128
  }
4086
4129
  }
4087
4130
  get elements() {
4088
4131
  return this._elements;
4089
4132
  }
4090
- get comparator() {
4091
- return this._comparator;
4092
- }
4093
4133
  /**
4094
4134
  * Get the size (number of elements) of the heap.
4095
4135
  */
@@ -4107,10 +4147,11 @@ var dataStructureTyped = (() => {
4107
4147
  /**
4108
4148
  * Static method that creates a binary heap from an array of elements and a comparison function.
4109
4149
  * @returns A new Heap instance.
4150
+ * @param elements
4110
4151
  * @param options
4111
4152
  */
4112
- static heapify(options) {
4113
- return new _Heap(options);
4153
+ static heapify(elements, options) {
4154
+ return new _Heap(elements, options);
4114
4155
  }
4115
4156
  /**
4116
4157
  * Time Complexity: O(log n), where n is the number of elements in the heap.
@@ -4319,7 +4360,7 @@ var dataStructureTyped = (() => {
4319
4360
  * @returns A new Heap instance containing the same elements.
4320
4361
  */
4321
4362
  clone() {
4322
- const clonedHeap = new _Heap({ comparator: this.comparator });
4363
+ const clonedHeap = new _Heap([], this.options);
4323
4364
  clonedHeap._elements = [...this.elements];
4324
4365
  return clonedHeap;
4325
4366
  }
@@ -4371,7 +4412,7 @@ var dataStructureTyped = (() => {
4371
4412
  }
4372
4413
  }
4373
4414
  filter(predicate) {
4374
- const filteredHeap = new _Heap({ comparator: this.comparator });
4415
+ const filteredHeap = new _Heap([], this.options);
4375
4416
  let index = 0;
4376
4417
  for (const el of this) {
4377
4418
  if (predicate(el, index, this)) {
@@ -4382,7 +4423,7 @@ var dataStructureTyped = (() => {
4382
4423
  return filteredHeap;
4383
4424
  }
4384
4425
  map(callback, comparator) {
4385
- const mappedHeap = new _Heap({ comparator });
4426
+ const mappedHeap = new _Heap([], { comparator });
4386
4427
  let index = 0;
4387
4428
  for (const el of this) {
4388
4429
  mappedHeap.add(callback(el, index, this));
@@ -4403,6 +4444,13 @@ var dataStructureTyped = (() => {
4403
4444
  * Time Complexity: O(log n)
4404
4445
  * Space Complexity: O(1)
4405
4446
  */
4447
+ print() {
4448
+ console.log([...this]);
4449
+ }
4450
+ /**
4451
+ * Time Complexity: O(n)
4452
+ * Space Complexity: O(1)
4453
+ */
4406
4454
  /**
4407
4455
  * Time Complexity: O(log n)
4408
4456
  * Space Complexity: O(1)
@@ -4415,17 +4463,13 @@ var dataStructureTyped = (() => {
4415
4463
  while (index > 0) {
4416
4464
  const parent = index - 1 >> 1;
4417
4465
  const parentItem = this.elements[parent];
4418
- if (this._comparator(parentItem, element) <= 0)
4466
+ if (this.options.comparator(parentItem, element) <= 0)
4419
4467
  break;
4420
4468
  this.elements[index] = parentItem;
4421
4469
  index = parent;
4422
4470
  }
4423
4471
  this.elements[index] = element;
4424
4472
  }
4425
- /**
4426
- * Time Complexity: O(n)
4427
- * Space Complexity: O(1)
4428
- */
4429
4473
  /**
4430
4474
  * Time Complexity: O(log n)
4431
4475
  * Space Complexity: O(1)
@@ -4440,11 +4484,11 @@ var dataStructureTyped = (() => {
4440
4484
  let left = index << 1 | 1;
4441
4485
  const right = left + 1;
4442
4486
  let minItem = this.elements[left];
4443
- if (right < this.elements.length && this._comparator(minItem, this.elements[right]) > 0) {
4487
+ if (right < this.elements.length && this.options.comparator(minItem, this.elements[right]) > 0) {
4444
4488
  left = right;
4445
4489
  minItem = this.elements[right];
4446
4490
  }
4447
- if (this._comparator(minItem, element) >= 0)
4491
+ if (this.options.comparator(minItem, element) >= 0)
4448
4492
  break;
4449
4493
  this.elements[index] = minItem;
4450
4494
  index = left;
@@ -4473,7 +4517,7 @@ var dataStructureTyped = (() => {
4473
4517
  __publicField(this, "_min");
4474
4518
  __publicField(this, "_comparator");
4475
4519
  this.clear();
4476
- this._comparator = comparator || this.defaultComparator;
4520
+ this._comparator = comparator || this._defaultComparator;
4477
4521
  if (typeof this.comparator !== "function") {
4478
4522
  throw new Error("FibonacciHeap constructor: given comparator should be a function.");
4479
4523
  }
@@ -4642,7 +4686,7 @@ var dataStructureTyped = (() => {
4642
4686
  this._root = void 0;
4643
4687
  } else {
4644
4688
  this._min = z.right;
4645
- this.consolidate();
4689
+ this._consolidate();
4646
4690
  }
4647
4691
  this._size--;
4648
4692
  return z.element;
@@ -4678,27 +4722,27 @@ var dataStructureTyped = (() => {
4678
4722
  this._size += heapToMerge.size;
4679
4723
  heapToMerge.clear();
4680
4724
  }
4725
+ /**
4726
+ * Create a new node.
4727
+ * @param element
4728
+ * @protected
4729
+ */
4730
+ createNode(element) {
4731
+ return new FibonacciHeapNode(element);
4732
+ }
4681
4733
  /**
4682
4734
  * Default comparator function used by the heap.
4683
4735
  * @param {E} a
4684
4736
  * @param {E} b
4685
4737
  * @protected
4686
4738
  */
4687
- defaultComparator(a, b) {
4739
+ _defaultComparator(a, b) {
4688
4740
  if (a < b)
4689
4741
  return -1;
4690
4742
  if (a > b)
4691
4743
  return 1;
4692
4744
  return 0;
4693
4745
  }
4694
- /**
4695
- * Create a new node.
4696
- * @param element
4697
- * @protected
4698
- */
4699
- createNode(element) {
4700
- return new FibonacciHeapNode(element);
4701
- }
4702
4746
  /**
4703
4747
  * Time Complexity: O(1)
4704
4748
  * Space Complexity: O(1)
@@ -4753,7 +4797,7 @@ var dataStructureTyped = (() => {
4753
4797
  * @param x
4754
4798
  * @protected
4755
4799
  */
4756
- link(y, x) {
4800
+ _link(y, x) {
4757
4801
  this.removeFromRoot(y);
4758
4802
  y.left = y;
4759
4803
  y.right = y;
@@ -4772,7 +4816,7 @@ var dataStructureTyped = (() => {
4772
4816
  * Remove and return the top element (smallest or largest element) from the heap.
4773
4817
  * @protected
4774
4818
  */
4775
- consolidate() {
4819
+ _consolidate() {
4776
4820
  const A = new Array(this.size);
4777
4821
  const elements = this.consumeLinkedList(this.root);
4778
4822
  let x, y, d, t;
@@ -4786,7 +4830,7 @@ var dataStructureTyped = (() => {
4786
4830
  x = y;
4787
4831
  y = t;
4788
4832
  }
4789
- this.link(y, x);
4833
+ this._link(y, x);
4790
4834
  A[d] = void 0;
4791
4835
  d++;
4792
4836
  }
@@ -4802,7 +4846,7 @@ var dataStructureTyped = (() => {
4802
4846
 
4803
4847
  // src/data-structures/heap/max-heap.ts
4804
4848
  var MaxHeap = class extends Heap {
4805
- constructor(options = {
4849
+ constructor(elements, options = {
4806
4850
  comparator: (a, b) => {
4807
4851
  if (!(typeof a === "number" && typeof b === "number")) {
4808
4852
  throw new Error("The a, b params of compare function must be number");
@@ -4811,13 +4855,13 @@ var dataStructureTyped = (() => {
4811
4855
  }
4812
4856
  }
4813
4857
  }) {
4814
- super(options);
4858
+ super(elements, options);
4815
4859
  }
4816
4860
  };
4817
4861
 
4818
4862
  // src/data-structures/heap/min-heap.ts
4819
4863
  var MinHeap = class extends Heap {
4820
- constructor(options = {
4864
+ constructor(elements, options = {
4821
4865
  comparator: (a, b) => {
4822
4866
  if (!(typeof a === "number" && typeof b === "number")) {
4823
4867
  throw new Error("The a, b params of compare function must be number");
@@ -4826,20 +4870,20 @@ var dataStructureTyped = (() => {
4826
4870
  }
4827
4871
  }
4828
4872
  }) {
4829
- super(options);
4873
+ super(elements, options);
4830
4874
  }
4831
4875
  };
4832
4876
 
4833
4877
  // src/data-structures/priority-queue/priority-queue.ts
4834
4878
  var PriorityQueue = class extends Heap {
4835
- constructor(options) {
4836
- super(options);
4879
+ constructor(elements, options) {
4880
+ super(elements, options);
4837
4881
  }
4838
4882
  };
4839
4883
 
4840
4884
  // src/data-structures/priority-queue/min-priority-queue.ts
4841
4885
  var MinPriorityQueue = class extends PriorityQueue {
4842
- constructor(options = {
4886
+ constructor(elements, options = {
4843
4887
  comparator: (a, b) => {
4844
4888
  if (!(typeof a === "number" && typeof b === "number")) {
4845
4889
  throw new Error("The a, b params of compare function must be number");
@@ -4848,13 +4892,13 @@ var dataStructureTyped = (() => {
4848
4892
  }
4849
4893
  }
4850
4894
  }) {
4851
- super(options);
4895
+ super(elements, options);
4852
4896
  }
4853
4897
  };
4854
4898
 
4855
4899
  // src/data-structures/priority-queue/max-priority-queue.ts
4856
4900
  var MaxPriorityQueue = class extends PriorityQueue {
4857
- constructor(options = {
4901
+ constructor(elements, options = {
4858
4902
  comparator: (a, b) => {
4859
4903
  if (!(typeof a === "number" && typeof b === "number")) {
4860
4904
  throw new Error("The a, b params of compare function must be number");
@@ -4863,7 +4907,7 @@ var dataStructureTyped = (() => {
4863
4907
  }
4864
4908
  }
4865
4909
  }) {
4866
- super(options);
4910
+ super(elements, options);
4867
4911
  }
4868
4912
  };
4869
4913
 
@@ -5446,7 +5490,7 @@ var dataStructureTyped = (() => {
5446
5490
  if (vertexOrKey instanceof AbstractVertex)
5447
5491
  distMap.set(vertexOrKey, Infinity);
5448
5492
  }
5449
- const heap = new PriorityQueue({ comparator: (a, b) => a.key - b.key });
5493
+ const heap = new PriorityQueue([], { comparator: (a, b) => a.key - b.key });
5450
5494
  heap.add({ key: 0, value: srcVertex });
5451
5495
  distMap.set(srcVertex, 0);
5452
5496
  preMap.set(srcVertex, null);
@@ -6772,10 +6816,10 @@ var dataStructureTyped = (() => {
6772
6816
  };
6773
6817
 
6774
6818
  // src/types/data-structures/binary-tree/binary-tree.ts
6775
- var IterationType = /* @__PURE__ */ ((IterationType2) => {
6776
- IterationType2["ITERATIVE"] = "ITERATIVE";
6777
- IterationType2["RECURSIVE"] = "RECURSIVE";
6778
- return IterationType2;
6819
+ var IterationType = /* @__PURE__ */ ((IterationType3) => {
6820
+ IterationType3["ITERATIVE"] = "ITERATIVE";
6821
+ IterationType3["RECURSIVE"] = "RECURSIVE";
6822
+ return IterationType3;
6779
6823
  })(IterationType || {});
6780
6824
  var FamilyPosition = /* @__PURE__ */ ((FamilyPosition2) => {
6781
6825
  FamilyPosition2["ROOT"] = "ROOT";
@@ -6882,17 +6926,20 @@ var dataStructureTyped = (() => {
6882
6926
  * Creates a new instance of BinaryTree.
6883
6927
  * @param {BinaryTreeOptions} [options] - The options for the binary tree.
6884
6928
  */
6885
- constructor(options) {
6886
- __publicField(this, "options");
6929
+ constructor(elements, options) {
6930
+ __publicField(this, "iterationType", "ITERATIVE" /* ITERATIVE */);
6887
6931
  __publicField(this, "_root");
6888
6932
  __publicField(this, "_size");
6889
6933
  __publicField(this, "_defaultOneParamCallback", (node) => node.key);
6890
6934
  if (options) {
6891
- this.options = __spreadValues({ iterationType: "ITERATIVE" /* ITERATIVE */ }, options);
6892
- } else {
6893
- this.options = { iterationType: "ITERATIVE" /* ITERATIVE */ };
6935
+ const { iterationType } = options;
6936
+ if (iterationType) {
6937
+ this.iterationType = iterationType;
6938
+ }
6894
6939
  }
6895
6940
  this._size = 0;
6941
+ if (elements)
6942
+ this.init(elements);
6896
6943
  }
6897
6944
  /**
6898
6945
  * Get the root node of the binary tree.
@@ -6916,13 +6963,8 @@ var dataStructureTyped = (() => {
6916
6963
  return new BinaryTreeNode(key, value);
6917
6964
  }
6918
6965
  createTree(options) {
6919
- return new _BinaryTree(__spreadValues(__spreadValues({}, this.options), options));
6966
+ return new _BinaryTree([], __spreadValues({ iterationType: this.iterationType }, options));
6920
6967
  }
6921
- /**
6922
- * Time Complexity: O(n)
6923
- * Space Complexity: O(1)
6924
- * Comments: The time complexity for adding a node depends on the depth of the tree. In the best case (when the tree is empty), it's O(1). In the worst case (when the tree is a degenerate tree), it's O(n). The space complexity is constant.
6925
- */
6926
6968
  /**
6927
6969
  * Time Complexity: O(n)
6928
6970
  * Space Complexity: O(1)
@@ -6978,8 +7020,9 @@ var dataStructureTyped = (() => {
6978
7020
  return inserted;
6979
7021
  }
6980
7022
  /**
6981
- * Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
7023
+ * Time Complexity: O(n)
6982
7024
  * Space Complexity: O(1)
7025
+ * Comments: The time complexity for adding a node depends on the depth of the tree. In the best case (when the tree is empty), it's O(1). In the worst case (when the tree is a degenerate tree), it's O(n). The space complexity is constant.
6983
7026
  */
6984
7027
  /**
6985
7028
  * Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
@@ -7027,10 +7070,6 @@ var dataStructureTyped = (() => {
7027
7070
  this.clear();
7028
7071
  return keysOrNodes.length === this.addMany(keysOrNodes, values).length;
7029
7072
  }
7030
- /**
7031
- * Time Complexity: O(n)
7032
- * Space Complexity: O(1)
7033
- */
7034
7073
  /**
7035
7074
  * Time Complexity: O(n)
7036
7075
  * Space Complexity: O(1)
@@ -7122,8 +7161,7 @@ var dataStructureTyped = (() => {
7122
7161
  }
7123
7162
  /**
7124
7163
  * Time Complexity: O(n)
7125
- * Space Complexity: O(log n)
7126
- * Best Case - O(log n) (when using recursive iterationType), Worst Case - O(n) (when using iterative iterationType)
7164
+ * Space Complexity: O(1)
7127
7165
  */
7128
7166
  /**
7129
7167
  * Time Complexity: O(n)
@@ -7139,7 +7177,7 @@ var dataStructureTyped = (() => {
7139
7177
  * values:
7140
7178
  * @returns the height of the binary tree.
7141
7179
  */
7142
- getHeight(beginRoot = this.root, iterationType = this.options.iterationType) {
7180
+ getHeight(beginRoot = this.root, iterationType = this.iterationType) {
7143
7181
  beginRoot = this.ensureNotKey(beginRoot);
7144
7182
  if (!beginRoot)
7145
7183
  return -1;
@@ -7184,7 +7222,7 @@ var dataStructureTyped = (() => {
7184
7222
  * to calculate the minimum height of a binary tree. It can have two possible values:
7185
7223
  * @returns The function `getMinHeight` returns the minimum height of a binary tree.
7186
7224
  */
7187
- getMinHeight(beginRoot = this.root, iterationType = this.options.iterationType) {
7225
+ getMinHeight(beginRoot = this.root, iterationType = this.iterationType) {
7188
7226
  var _a, _b, _c;
7189
7227
  beginRoot = this.ensureNotKey(beginRoot);
7190
7228
  if (!beginRoot)
@@ -7229,6 +7267,7 @@ var dataStructureTyped = (() => {
7229
7267
  /**
7230
7268
  * Time Complexity: O(n)
7231
7269
  * Space Complexity: O(log n)
7270
+ * Best Case - O(log n) (when using recursive iterationType), Worst Case - O(n) (when using iterative iterationType)
7232
7271
  */
7233
7272
  /**
7234
7273
  * Time Complexity: O(n)
@@ -7244,10 +7283,6 @@ var dataStructureTyped = (() => {
7244
7283
  isPerfectlyBalanced(beginRoot = this.root) {
7245
7284
  return this.getMinHeight(beginRoot) + 1 >= this.getHeight(beginRoot);
7246
7285
  }
7247
- /**
7248
- * Time Complexity: O(n)
7249
- * Space Complexity: O(log n).
7250
- */
7251
7286
  /**
7252
7287
  * Time Complexity: O(n)
7253
7288
  * Space Complexity: O(log n).
@@ -7273,7 +7308,7 @@ var dataStructureTyped = (() => {
7273
7308
  * traverse the binary tree. It can have two possible values:
7274
7309
  * @returns an array of nodes of type `N`.
7275
7310
  */
7276
- getNodes(identifier, callback = this._defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.options.iterationType) {
7311
+ getNodes(identifier, callback = this._defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
7277
7312
  if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
7278
7313
  callback = (node) => node;
7279
7314
  beginRoot = this.ensureNotKey(beginRoot);
@@ -7310,10 +7345,6 @@ var dataStructureTyped = (() => {
7310
7345
  }
7311
7346
  return ans;
7312
7347
  }
7313
- /**
7314
- * Time Complexity: O(n)
7315
- * Space Complexity: O(log n).
7316
- */
7317
7348
  /**
7318
7349
  * Time Complexity: O(n)
7319
7350
  *
@@ -7334,15 +7365,11 @@ var dataStructureTyped = (() => {
7334
7365
  * be performed in a pre-order, in-order, or post-order manner.
7335
7366
  * @returns a boolean value.
7336
7367
  */
7337
- has(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.options.iterationType) {
7368
+ has(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
7338
7369
  if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
7339
7370
  callback = (node) => node;
7340
7371
  return this.getNodes(identifier, callback, true, beginRoot, iterationType).length > 0;
7341
7372
  }
7342
- /**
7343
- * Time Complexity: O(n)
7344
- * Space Complexity: O(log n)
7345
- */
7346
7373
  /**
7347
7374
  * Time Complexity: O(n)
7348
7375
  * Space Complexity: O(log n)
@@ -7364,7 +7391,7 @@ var dataStructureTyped = (() => {
7364
7391
  * nodes are visited during the search.
7365
7392
  * @returns a value of type `N | null | undefined`.
7366
7393
  */
7367
- getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.options.iterationType) {
7394
+ getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
7368
7395
  var _a;
7369
7396
  if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
7370
7397
  callback = (node) => node;
@@ -7416,6 +7443,10 @@ var dataStructureTyped = (() => {
7416
7443
  }
7417
7444
  }
7418
7445
  }
7446
+ /**
7447
+ * Time Complexity: O(n)
7448
+ * Space Complexity: O(log n)
7449
+ */
7419
7450
  /**
7420
7451
  * The function `ensureNotKey` returns the node corresponding to the given key if it is a valid node
7421
7452
  * key, otherwise it returns the key itself.
@@ -7430,10 +7461,6 @@ var dataStructureTyped = (() => {
7430
7461
  ensureNotKey(key, iterationType = "ITERATIVE" /* ITERATIVE */) {
7431
7462
  return this.isNodeKey(key) ? this.getNodeByKey(key, iterationType) : key;
7432
7463
  }
7433
- /**
7434
- * Time Complexity: O(n)
7435
- * Space Complexity: O(log n)
7436
- */
7437
7464
  /**
7438
7465
  * Time Complexity: O(n)
7439
7466
  * Space Complexity: O(log n)
@@ -7456,12 +7483,16 @@ var dataStructureTyped = (() => {
7456
7483
  * @returns The value of the node with the given identifier is being returned. If the node is not
7457
7484
  * found, `undefined` is returned.
7458
7485
  */
7459
- get(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.options.iterationType) {
7486
+ get(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
7460
7487
  var _a, _b;
7461
7488
  if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
7462
7489
  callback = (node) => node;
7463
7490
  return (_b = (_a = this.getNode(identifier, callback, beginRoot, iterationType)) == null ? void 0 : _a.value) != null ? _b : void 0;
7464
7491
  }
7492
+ /**
7493
+ * Time Complexity: O(n)
7494
+ * Space Complexity: O(log n)
7495
+ */
7465
7496
  /**
7466
7497
  * Clear the binary tree, removing all nodes.
7467
7498
  */
@@ -7476,10 +7507,6 @@ var dataStructureTyped = (() => {
7476
7507
  isEmpty() {
7477
7508
  return this.size === 0;
7478
7509
  }
7479
- /**
7480
- * Time Complexity: O(log n)
7481
- * Space Complexity: O(log n)
7482
- */
7483
7510
  /**
7484
7511
  * Time Complexity: O(log n)
7485
7512
  * Space Complexity: O(log n)
@@ -7508,7 +7535,7 @@ var dataStructureTyped = (() => {
7508
7535
  }
7509
7536
  /**
7510
7537
  * Time Complexity: O(log n)
7511
- * Space Complexity: O(1)
7538
+ * Space Complexity: O(log n)
7512
7539
  */
7513
7540
  /**
7514
7541
  * Time Complexity: O(log n)
@@ -7524,7 +7551,7 @@ var dataStructureTyped = (() => {
7524
7551
  * @returns The function `getLeftMost` returns the leftmost node (`N`) in the binary tree. If there
7525
7552
  * is no leftmost node, it returns `null` or `undefined` depending on the input.
7526
7553
  */
7527
- getLeftMost(beginRoot = this.root, iterationType = this.options.iterationType) {
7554
+ getLeftMost(beginRoot = this.root, iterationType = this.iterationType) {
7528
7555
  beginRoot = this.ensureNotKey(beginRoot);
7529
7556
  if (!beginRoot)
7530
7557
  return beginRoot;
@@ -7563,7 +7590,7 @@ var dataStructureTyped = (() => {
7563
7590
  * @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If there
7564
7591
  * is no rightmost node, it returns `null` or `undefined`, depending on the input.
7565
7592
  */
7566
- getRightMost(beginRoot = this.root, iterationType = this.options.iterationType) {
7593
+ getRightMost(beginRoot = this.root, iterationType = this.iterationType) {
7567
7594
  beginRoot = this.ensureNotKey(beginRoot);
7568
7595
  if (!beginRoot)
7569
7596
  return beginRoot;
@@ -7584,7 +7611,7 @@ var dataStructureTyped = (() => {
7584
7611
  }
7585
7612
  }
7586
7613
  /**
7587
- * Time Complexity: O(n)
7614
+ * Time Complexity: O(log n)
7588
7615
  * Space Complexity: O(1)
7589
7616
  */
7590
7617
  /**
@@ -7599,7 +7626,7 @@ var dataStructureTyped = (() => {
7599
7626
  * possible values:
7600
7627
  * @returns a boolean value.
7601
7628
  */
7602
- isSubtreeBST(beginRoot, iterationType = this.options.iterationType) {
7629
+ isSubtreeBST(beginRoot, iterationType = this.iterationType) {
7603
7630
  beginRoot = this.ensureNotKey(beginRoot);
7604
7631
  if (!beginRoot)
7605
7632
  return true;
@@ -7644,15 +7671,11 @@ var dataStructureTyped = (() => {
7644
7671
  * expected to be
7645
7672
  * @returns a boolean value.
7646
7673
  */
7647
- isBST(iterationType = this.options.iterationType) {
7674
+ isBST(iterationType = this.iterationType) {
7648
7675
  if (this.root === null)
7649
7676
  return true;
7650
7677
  return this.isSubtreeBST(this.root, iterationType);
7651
7678
  }
7652
- /**
7653
- * Time complexity: O(n)
7654
- * Space complexity: O(log n)
7655
- */
7656
7679
  /**
7657
7680
  * Time complexity: O(n)
7658
7681
  * Space complexity: O(log n)
@@ -7675,7 +7698,7 @@ var dataStructureTyped = (() => {
7675
7698
  * the `callback` function on each node in the subtree. The type of the array elements is determined
7676
7699
  * by the return type of the `callback` function.
7677
7700
  */
7678
- subTreeTraverse(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.options.iterationType, includeNull = false) {
7701
+ subTreeTraverse(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType, includeNull = false) {
7679
7702
  beginRoot = this.ensureNotKey(beginRoot);
7680
7703
  const ans = [];
7681
7704
  if (!beginRoot)
@@ -7712,6 +7735,10 @@ var dataStructureTyped = (() => {
7712
7735
  }
7713
7736
  return ans;
7714
7737
  }
7738
+ /**
7739
+ * Time complexity: O(n)
7740
+ * Space complexity: O(log n)
7741
+ */
7715
7742
  /**
7716
7743
  * The function checks if a given node is a real node by verifying if it is an instance of
7717
7744
  * BinaryTreeNode and its key is not NaN.
@@ -7746,10 +7773,6 @@ var dataStructureTyped = (() => {
7746
7773
  isNodeKey(potentialKey) {
7747
7774
  return typeof potentialKey === "number";
7748
7775
  }
7749
- /**
7750
- * Time complexity: O(n)
7751
- * Space complexity: O(n)
7752
- */
7753
7776
  /**
7754
7777
  * Time complexity: O(n)
7755
7778
  * Space complexity: O(n)
@@ -7872,10 +7895,6 @@ var dataStructureTyped = (() => {
7872
7895
  }
7873
7896
  return ans;
7874
7897
  }
7875
- /**
7876
- * Time complexity: O(n)
7877
- * Space complexity: O(n)
7878
- */
7879
7898
  /**
7880
7899
  * Time complexity: O(n)
7881
7900
  * Space complexity: O(n)
@@ -7897,7 +7916,7 @@ var dataStructureTyped = (() => {
7897
7916
  * @returns an array of values that are the result of invoking the callback function on each node in
7898
7917
  * the breadth-first traversal of a binary tree.
7899
7918
  */
7900
- bfs(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.options.iterationType, includeNull = false) {
7919
+ bfs(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType, includeNull = false) {
7901
7920
  beginRoot = this.ensureNotKey(beginRoot);
7902
7921
  if (!beginRoot)
7903
7922
  return [];
@@ -7946,10 +7965,6 @@ var dataStructureTyped = (() => {
7946
7965
  }
7947
7966
  return ans;
7948
7967
  }
7949
- /**
7950
- * Time complexity: O(n)
7951
- * Space complexity: O(n)
7952
- */
7953
7968
  /**
7954
7969
  * Time complexity: O(n)
7955
7970
  * Space complexity: O(n)
@@ -7971,7 +7986,7 @@ var dataStructureTyped = (() => {
7971
7986
  * be excluded
7972
7987
  * @returns The function `listLevels` returns a two-dimensional array of type `ReturnType<C>[][]`.
7973
7988
  */
7974
- listLevels(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.options.iterationType, includeNull = false) {
7989
+ listLevels(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType, includeNull = false) {
7975
7990
  beginRoot = this.ensureNotKey(beginRoot);
7976
7991
  const levelsNodes = [];
7977
7992
  if (!beginRoot)
@@ -8059,10 +8074,6 @@ var dataStructureTyped = (() => {
8059
8074
  }
8060
8075
  return y;
8061
8076
  }
8062
- /**
8063
- * Time complexity: O(n)
8064
- * Space complexity: O(1)
8065
- */
8066
8077
  /**
8067
8078
  * Time complexity: O(n)
8068
8079
  * Space complexity: O(1)
@@ -8162,6 +8173,10 @@ var dataStructureTyped = (() => {
8162
8173
  }
8163
8174
  return ans;
8164
8175
  }
8176
+ /**
8177
+ * Time complexity: O(n)
8178
+ * Space complexity: O(1)
8179
+ */
8165
8180
  /**
8166
8181
  * The `forEach` function iterates over each entry in a tree and calls a callback function with the
8167
8182
  * entry and the tree as arguments.
@@ -8190,14 +8205,6 @@ var dataStructureTyped = (() => {
8190
8205
  }
8191
8206
  return newTree;
8192
8207
  }
8193
- // TODO Type error, need to return a TREE<NV> that is a value type only for callback function.
8194
- // map<NV>(callback: (entry: [BTNKey, V | undefined], tree: this) => NV) {
8195
- // const newTree = this.createTree();
8196
- // for (const [key, value] of this) {
8197
- // newTree.add(key, callback([key, value], this));
8198
- // }
8199
- // return newTree;
8200
- // }
8201
8208
  /**
8202
8209
  * The `map` function creates a new tree by applying a callback function to each entry in the current
8203
8210
  * tree.
@@ -8211,6 +8218,14 @@ var dataStructureTyped = (() => {
8211
8218
  }
8212
8219
  return newTree;
8213
8220
  }
8221
+ // TODO Type error, need to return a TREE<NV> that is a value type only for callback function.
8222
+ // map<NV>(callback: (entry: [BTNKey, V | undefined], tree: this) => NV) {
8223
+ // const newTree = this.createTree();
8224
+ // for (const [key, value] of this) {
8225
+ // newTree.add(key, callback([key, value], this));
8226
+ // }
8227
+ // return newTree;
8228
+ // }
8214
8229
  /**
8215
8230
  * The `reduce` function iterates over the entries of a tree and applies a callback function to each
8216
8231
  * entry, accumulating a single value.
@@ -8242,7 +8257,7 @@ var dataStructureTyped = (() => {
8242
8257
  *[Symbol.iterator](node = this.root) {
8243
8258
  if (!node)
8244
8259
  return;
8245
- if (this.options.iterationType === "ITERATIVE" /* ITERATIVE */) {
8260
+ if (this.iterationType === "ITERATIVE" /* ITERATIVE */) {
8246
8261
  const stack = [];
8247
8262
  let current = node;
8248
8263
  while (current || stack.length > 0) {
@@ -8295,6 +8310,18 @@ var dataStructureTyped = (() => {
8295
8310
  };
8296
8311
  display(beginRoot);
8297
8312
  }
8313
+ init(elements) {
8314
+ if (elements) {
8315
+ for (const entryOrKey of elements) {
8316
+ if (Array.isArray(entryOrKey)) {
8317
+ const [key, value] = entryOrKey;
8318
+ this.add(key, value);
8319
+ } else {
8320
+ this.add(entryOrKey);
8321
+ }
8322
+ }
8323
+ }
8324
+ }
8298
8325
  _displayAux(node, options) {
8299
8326
  const { isShowNull, isShowUndefined, isShowRedBlackNIL } = options;
8300
8327
  const emptyDisplayLayout = [["\u2500"], 1, 0, 0];
@@ -8445,16 +8472,19 @@ var dataStructureTyped = (() => {
8445
8472
  * @param {BSTOptions} [options] - An optional object that contains additional configuration options
8446
8473
  * for the binary search tree.
8447
8474
  */
8448
- constructor(options) {
8449
- super(options);
8450
- __publicField(this, "options");
8475
+ constructor(elements, options) {
8476
+ super([], options);
8451
8477
  __publicField(this, "_root");
8478
+ __publicField(this, "comparator", (a, b) => a - b);
8452
8479
  if (options) {
8453
- this.options = __spreadValues({ iterationType: "ITERATIVE" /* ITERATIVE */, comparator: (a, b) => a - b }, options);
8454
- } else {
8455
- this.options = { iterationType: "ITERATIVE" /* ITERATIVE */, comparator: (a, b) => a - b };
8480
+ const { comparator } = options;
8481
+ if (comparator) {
8482
+ this.comparator = comparator;
8483
+ }
8456
8484
  }
8457
8485
  this._root = void 0;
8486
+ if (elements)
8487
+ this.init(elements);
8458
8488
  }
8459
8489
  /**
8460
8490
  * Get the root node of the binary tree.
@@ -8474,12 +8504,11 @@ var dataStructureTyped = (() => {
8474
8504
  return new BSTNode(key, value);
8475
8505
  }
8476
8506
  createTree(options) {
8477
- return new _BST(__spreadValues(__spreadValues({}, this.options), options));
8507
+ return new _BST([], __spreadValues({
8508
+ iterationType: this.iterationType,
8509
+ comparator: this.comparator
8510
+ }, options));
8478
8511
  }
8479
- /**
8480
- * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
8481
- * Space Complexity: O(1) - Constant space is used.
8482
- */
8483
8512
  /**
8484
8513
  * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
8485
8514
  * Space Complexity: O(1) - Constant space is used.
@@ -8554,8 +8583,8 @@ var dataStructureTyped = (() => {
8554
8583
  return inserted;
8555
8584
  }
8556
8585
  /**
8557
- * Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
8558
- * Space Complexity: O(n) - Additional space is required for the sorted array.
8586
+ * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
8587
+ * Space Complexity: O(1) - Constant space is used.
8559
8588
  */
8560
8589
  /**
8561
8590
  * Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
@@ -8577,7 +8606,7 @@ var dataStructureTyped = (() => {
8577
8606
  * current instance of the binary search tree
8578
8607
  * @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
8579
8608
  */
8580
- addMany(keysOrNodes, data, isBalanceAdd = true, iterationType = this.options.iterationType) {
8609
+ addMany(keysOrNodes, data, isBalanceAdd = true, iterationType = this.iterationType) {
8581
8610
  function hasNoUndefined(arr) {
8582
8611
  return arr.indexOf(void 0) === -1;
8583
8612
  }
@@ -8645,8 +8674,8 @@ var dataStructureTyped = (() => {
8645
8674
  return inserted;
8646
8675
  }
8647
8676
  /**
8648
- * Time Complexity: O(log n) - Average case for a balanced tree.
8649
- * Space Complexity: O(1) - Constant space is used.
8677
+ * Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
8678
+ * Space Complexity: O(n) - Additional space is required for the sorted array.
8650
8679
  */
8651
8680
  /**
8652
8681
  * Time Complexity: O(log n) - Average case for a balanced tree.
@@ -8663,7 +8692,7 @@ var dataStructureTyped = (() => {
8663
8692
  * the key of the leftmost node if the comparison result is greater than, and the key of the
8664
8693
  * rightmost node otherwise. If no node is found, it returns 0.
8665
8694
  */
8666
- lastKey(beginRoot = this.root, iterationType = this.options.iterationType) {
8695
+ lastKey(beginRoot = this.root, iterationType = this.iterationType) {
8667
8696
  var _a, _b, _c, _d, _e, _f;
8668
8697
  if (this._compare(0, 1) === "lt" /* lt */)
8669
8698
  return (_b = (_a = this.getRightMost(beginRoot, iterationType)) == null ? void 0 : _a.key) != null ? _b : 0;
@@ -8674,7 +8703,7 @@ var dataStructureTyped = (() => {
8674
8703
  }
8675
8704
  /**
8676
8705
  * Time Complexity: O(log n) - Average case for a balanced tree.
8677
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
8706
+ * Space Complexity: O(1) - Constant space is used.
8678
8707
  */
8679
8708
  /**
8680
8709
  * Time Complexity: O(log n) - Average case for a balanced tree.
@@ -8720,6 +8749,10 @@ var dataStructureTyped = (() => {
8720
8749
  }
8721
8750
  }
8722
8751
  }
8752
+ /**
8753
+ * Time Complexity: O(log n) - Average case for a balanced tree.
8754
+ * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
8755
+ */
8723
8756
  /**
8724
8757
  * The function `ensureNotKey` returns the node corresponding to the given key if it is a node key,
8725
8758
  * otherwise it returns the key itself.
@@ -8732,10 +8765,6 @@ var dataStructureTyped = (() => {
8732
8765
  ensureNotKey(key, iterationType = "ITERATIVE" /* ITERATIVE */) {
8733
8766
  return this.isNodeKey(key) ? this.getNodeByKey(key, iterationType) : key;
8734
8767
  }
8735
- /**
8736
- * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
8737
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
8738
- */
8739
8768
  /**
8740
8769
  * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
8741
8770
  * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
@@ -8759,7 +8788,7 @@ var dataStructureTyped = (() => {
8759
8788
  * performed on the binary tree. It can have two possible values:
8760
8789
  * @returns The method returns an array of nodes (`N[]`).
8761
8790
  */
8762
- getNodes(identifier, callback = this._defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.options.iterationType) {
8791
+ getNodes(identifier, callback = this._defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
8763
8792
  beginRoot = this.ensureNotKey(beginRoot);
8764
8793
  if (!beginRoot)
8765
8794
  return [];
@@ -8835,7 +8864,7 @@ var dataStructureTyped = (() => {
8835
8864
  * @returns The function `lesserOrGreaterTraverse` returns an array of values of type
8836
8865
  * `ReturnType<C>`, which is the return type of the callback function passed as an argument.
8837
8866
  */
8838
- lesserOrGreaterTraverse(callback = this._defaultOneParamCallback, lesserOrGreater = "lt" /* lt */, targetNode = this.root, iterationType = this.options.iterationType) {
8867
+ lesserOrGreaterTraverse(callback = this._defaultOneParamCallback, lesserOrGreater = "lt" /* lt */, targetNode = this.root, iterationType = this.iterationType) {
8839
8868
  targetNode = this.ensureNotKey(targetNode);
8840
8869
  const ans = [];
8841
8870
  if (!targetNode)
@@ -8875,17 +8904,8 @@ var dataStructureTyped = (() => {
8875
8904
  }
8876
8905
  }
8877
8906
  /**
8878
- * Balancing Adjustment:
8879
- * Perfectly Balanced Binary Tree: Since the balance of a perfectly balanced binary tree is already fixed, no additional balancing adjustment is needed. Any insertion or deletion operation will disrupt the perfect balance, often requiring a complete reconstruction of the tree.
8880
- * AVL Tree: After insertion or deletion operations, an AVL tree performs rotation adjustments based on the balance factor of nodes to restore the tree's balance. These rotations can be left rotations, right rotations, left-right rotations, or right-left rotations, performed as needed.
8881
- *
8882
- * Use Cases and Efficiency:
8883
- * Perfectly Balanced Binary Tree: Perfectly balanced binary trees are typically used in specific scenarios such as complete binary heaps in heap sort or certain types of Huffman trees. However, they are not suitable for dynamic operations requiring frequent insertions and deletions, as these operations often necessitate full tree reconstruction.
8884
- * AVL Tree: AVL trees are well-suited for scenarios involving frequent searching, insertion, and deletion operations. Through rotation adjustments, AVL trees maintain their balance, ensuring average and worst-case time complexity of O(log n).
8885
- */
8886
- /**
8887
- * Time Complexity: O(n) - Building a balanced tree from a sorted array.
8888
- * Space Complexity: O(n) - Additional space is required for the sorted array.
8907
+ * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
8908
+ * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
8889
8909
  */
8890
8910
  /**
8891
8911
  * Time Complexity: O(n) - Building a balanced tree from a sorted array.
@@ -8898,7 +8918,7 @@ var dataStructureTyped = (() => {
8898
8918
  * values:
8899
8919
  * @returns The function `perfectlyBalance` returns a boolean value.
8900
8920
  */
8901
- perfectlyBalance(iterationType = this.options.iterationType) {
8921
+ perfectlyBalance(iterationType = this.iterationType) {
8902
8922
  const sorted = this.dfs((node) => node, "in"), n = sorted.length;
8903
8923
  this.clear();
8904
8924
  if (sorted.length < 1)
@@ -8935,8 +8955,17 @@ var dataStructureTyped = (() => {
8935
8955
  }
8936
8956
  }
8937
8957
  /**
8938
- * Time Complexity: O(n) - Visiting each node once.
8939
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
8958
+ * Balancing Adjustment:
8959
+ * Perfectly Balanced Binary Tree: Since the balance of a perfectly balanced binary tree is already fixed, no additional balancing adjustment is needed. Any insertion or deletion operation will disrupt the perfect balance, often requiring a complete reconstruction of the tree.
8960
+ * AVL Tree: After insertion or deletion operations, an AVL tree performs rotation adjustments based on the balance factor of nodes to restore the tree's balance. These rotations can be left rotations, right rotations, left-right rotations, or right-left rotations, performed as needed.
8961
+ *
8962
+ * Use Cases and Efficiency:
8963
+ * Perfectly Balanced Binary Tree: Perfectly balanced binary trees are typically used in specific scenarios such as complete binary heaps in heap sort or certain types of Huffman trees. However, they are not suitable for dynamic operations requiring frequent insertions and deletions, as these operations often necessitate full tree reconstruction.
8964
+ * AVL Tree: AVL trees are well-suited for scenarios involving frequent searching, insertion, and deletion operations. Through rotation adjustments, AVL trees maintain their balance, ensuring average and worst-case time complexity of O(log n).
8965
+ */
8966
+ /**
8967
+ * Time Complexity: O(n) - Building a balanced tree from a sorted array.
8968
+ * Space Complexity: O(n) - Additional space is required for the sorted array.
8940
8969
  */
8941
8970
  /**
8942
8971
  * Time Complexity: O(n) - Visiting each node once.
@@ -8947,7 +8976,7 @@ var dataStructureTyped = (() => {
8947
8976
  * to check if the AVL tree is balanced. It can have two possible values:
8948
8977
  * @returns a boolean value.
8949
8978
  */
8950
- isAVLBalanced(iterationType = this.options.iterationType) {
8979
+ isAVLBalanced(iterationType = this.iterationType) {
8951
8980
  var _a, _b;
8952
8981
  if (!this.root)
8953
8982
  return true;
@@ -8990,6 +9019,22 @@ var dataStructureTyped = (() => {
8990
9019
  }
8991
9020
  return balanced;
8992
9021
  }
9022
+ /**
9023
+ * Time Complexity: O(n) - Visiting each node once.
9024
+ * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
9025
+ */
9026
+ init(elements) {
9027
+ if (elements) {
9028
+ for (const entryOrKey of elements) {
9029
+ if (Array.isArray(entryOrKey)) {
9030
+ const [key, value] = entryOrKey;
9031
+ this.add(key, value);
9032
+ } else {
9033
+ this.add(entryOrKey);
9034
+ }
9035
+ }
9036
+ }
9037
+ }
8993
9038
  _setRoot(v) {
8994
9039
  if (v) {
8995
9040
  v.parent = void 0;
@@ -9005,7 +9050,7 @@ var dataStructureTyped = (() => {
9005
9050
  * than), CP.lt (less than), or CP.eq (equal).
9006
9051
  */
9007
9052
  _compare(a, b) {
9008
- const compared = this.options.comparator(a, b);
9053
+ const compared = this.comparator(a, b);
9009
9054
  if (compared > 0)
9010
9055
  return "gt" /* gt */;
9011
9056
  else if (compared < 0)
@@ -9456,14 +9501,10 @@ var dataStructureTyped = (() => {
9456
9501
  * constructor of the AVLTree class. It allows you to customize the behavior of the AVL tree by providing different
9457
9502
  * options.
9458
9503
  */
9459
- constructor(options) {
9460
- super(options);
9461
- __publicField(this, "options");
9462
- if (options) {
9463
- this.options = __spreadValues({ iterationType: "ITERATIVE" /* ITERATIVE */, comparator: (a, b) => a - b }, options);
9464
- } else {
9465
- this.options = { iterationType: "ITERATIVE" /* ITERATIVE */, comparator: (a, b) => a - b };
9466
- }
9504
+ constructor(elements, options) {
9505
+ super([], options);
9506
+ if (elements)
9507
+ this.init(elements);
9467
9508
  }
9468
9509
  /**
9469
9510
  * The function creates a new AVL tree node with the specified key and value.
@@ -9478,12 +9519,11 @@ var dataStructureTyped = (() => {
9478
9519
  return new AVLTreeNode(key, value);
9479
9520
  }
9480
9521
  createTree(options) {
9481
- return new _AVLTree(__spreadValues(__spreadValues({}, this.options), options));
9522
+ return new _AVLTree([], __spreadValues({
9523
+ iterationType: this.iterationType,
9524
+ comparator: this.comparator
9525
+ }, options));
9482
9526
  }
9483
- /**
9484
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
9485
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
9486
- */
9487
9527
  /**
9488
9528
  * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
9489
9529
  * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
@@ -9505,7 +9545,7 @@ var dataStructureTyped = (() => {
9505
9545
  return inserted;
9506
9546
  }
9507
9547
  /**
9508
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (BST) has logarithmic time complexity.
9548
+ * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
9509
9549
  * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
9510
9550
  */
9511
9551
  /**
@@ -9534,6 +9574,22 @@ var dataStructureTyped = (() => {
9534
9574
  }
9535
9575
  return deletedResults;
9536
9576
  }
9577
+ /**
9578
+ * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (BST) has logarithmic time complexity.
9579
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
9580
+ */
9581
+ init(elements) {
9582
+ if (elements) {
9583
+ for (const entryOrKey of elements) {
9584
+ if (Array.isArray(entryOrKey)) {
9585
+ const [key, value] = entryOrKey;
9586
+ this.add(key, value);
9587
+ } else {
9588
+ this.add(entryOrKey);
9589
+ }
9590
+ }
9591
+ }
9592
+ }
9537
9593
  /**
9538
9594
  * The `_swap` function swaps the key, value, and height properties between two nodes in a binary
9539
9595
  * tree.
@@ -9849,18 +9905,14 @@ var dataStructureTyped = (() => {
9849
9905
  * @param {RBTreeOptions} [options] - The `options` parameter is an optional object that can be
9850
9906
  * passed to the constructor. It is used to configure the RBTree object with specific options.
9851
9907
  */
9852
- constructor(options) {
9853
- super(options);
9908
+ constructor(elements, options) {
9909
+ super([], options);
9854
9910
  __publicField(this, "Sentinel", new RedBlackTreeNode(NaN));
9855
- __publicField(this, "options");
9856
9911
  __publicField(this, "_root");
9857
9912
  __publicField(this, "_size", 0);
9858
- if (options) {
9859
- this.options = __spreadValues({ iterationType: "ITERATIVE" /* ITERATIVE */, comparator: (a, b) => a - b }, options);
9860
- } else {
9861
- this.options = { iterationType: "ITERATIVE" /* ITERATIVE */, comparator: (a, b) => a - b };
9862
- }
9863
9913
  this._root = this.Sentinel;
9914
+ if (elements)
9915
+ this.init(elements);
9864
9916
  }
9865
9917
  get root() {
9866
9918
  return this._root;
@@ -9872,12 +9924,11 @@ var dataStructureTyped = (() => {
9872
9924
  return new RedBlackTreeNode(key, value, color);
9873
9925
  }
9874
9926
  createTree(options) {
9875
- return new _RedBlackTree(__spreadValues(__spreadValues({}, this.options), options));
9927
+ return new _RedBlackTree([], __spreadValues({
9928
+ iterationType: this.iterationType,
9929
+ comparator: this.comparator
9930
+ }, options));
9876
9931
  }
9877
- /**
9878
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
9879
- * Space Complexity: O(1)
9880
- */
9881
9932
  /**
9882
9933
  * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
9883
9934
  * Space Complexity: O(1)
@@ -10010,13 +10061,13 @@ var dataStructureTyped = (() => {
10010
10061
  helper(this.root);
10011
10062
  return ans;
10012
10063
  }
10013
- isRealNode(node) {
10014
- return node !== this.Sentinel && node !== void 0;
10015
- }
10016
10064
  /**
10017
10065
  * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
10018
10066
  * Space Complexity: O(1)
10019
10067
  */
10068
+ isRealNode(node) {
10069
+ return node !== this.Sentinel && node !== void 0;
10070
+ }
10020
10071
  /**
10021
10072
  * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
10022
10073
  * Space Complexity: O(1)
@@ -10038,7 +10089,7 @@ var dataStructureTyped = (() => {
10038
10089
  * `getNodes` method, which is called within the `getNode` method.
10039
10090
  * @returns a value of type `N`, `null`, or `undefined`.
10040
10091
  */
10041
- getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.options.iterationType) {
10092
+ getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
10042
10093
  var _a;
10043
10094
  if (identifier instanceof BinaryTreeNode)
10044
10095
  callback = (node) => node;
@@ -10093,10 +10144,26 @@ var dataStructureTyped = (() => {
10093
10144
  }
10094
10145
  return y;
10095
10146
  }
10147
+ /**
10148
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
10149
+ * Space Complexity: O(1)
10150
+ */
10096
10151
  clear() {
10097
10152
  this._root = this.Sentinel;
10098
10153
  this._size = 0;
10099
10154
  }
10155
+ init(elements) {
10156
+ if (elements) {
10157
+ for (const entryOrKey of elements) {
10158
+ if (Array.isArray(entryOrKey)) {
10159
+ const [key, value] = entryOrKey;
10160
+ this.add(key, value);
10161
+ } else {
10162
+ this.add(entryOrKey);
10163
+ }
10164
+ }
10165
+ }
10166
+ }
10100
10167
  _setRoot(v) {
10101
10168
  if (v) {
10102
10169
  v.parent = void 0;
@@ -10341,15 +10408,11 @@ var dataStructureTyped = (() => {
10341
10408
  * @param {TreeMultimapOptions} [options] - An optional object that contains additional configuration options for the
10342
10409
  * TreeMultimap.
10343
10410
  */
10344
- constructor(options = { iterationType: "ITERATIVE" /* ITERATIVE */ }) {
10345
- super(options);
10346
- __publicField(this, "options");
10411
+ constructor(elements, options) {
10412
+ super([], options);
10347
10413
  __publicField(this, "_count", 0);
10348
- if (options) {
10349
- this.options = __spreadValues({ iterationType: "ITERATIVE" /* ITERATIVE */, comparator: (a, b) => a - b }, options);
10350
- } else {
10351
- this.options = { iterationType: "ITERATIVE" /* ITERATIVE */, comparator: (a, b) => a - b };
10352
- }
10414
+ if (elements)
10415
+ this.init(elements);
10353
10416
  }
10354
10417
  get count() {
10355
10418
  return this._count;
@@ -10367,12 +10430,11 @@ var dataStructureTyped = (() => {
10367
10430
  return new TreeMultimapNode(key, value, count);
10368
10431
  }
10369
10432
  createTree(options) {
10370
- return new _TreeMultimap(__spreadValues(__spreadValues({}, this.options), options));
10433
+ return new _TreeMultimap([], __spreadValues({
10434
+ iterationType: this.iterationType,
10435
+ comparator: this.comparator
10436
+ }, options));
10371
10437
  }
10372
- /**
10373
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
10374
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
10375
- */
10376
10438
  /**
10377
10439
  * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
10378
10440
  * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
@@ -10451,8 +10513,8 @@ var dataStructureTyped = (() => {
10451
10513
  return inserted;
10452
10514
  }
10453
10515
  /**
10454
- * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
10455
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
10516
+ * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
10517
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
10456
10518
  */
10457
10519
  /**
10458
10520
  * Time Complexity: O(k log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each.
@@ -10484,8 +10546,8 @@ var dataStructureTyped = (() => {
10484
10546
  return inserted;
10485
10547
  }
10486
10548
  /**
10487
- * Time Complexity: O(k log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each.
10488
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
10549
+ * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
10550
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
10489
10551
  */
10490
10552
  /**
10491
10553
  * Time Complexity: O(n log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node.
@@ -10498,7 +10560,7 @@ var dataStructureTyped = (() => {
10498
10560
  * values:
10499
10561
  * @returns a boolean value.
10500
10562
  */
10501
- perfectlyBalance(iterationType = this.options.iterationType) {
10563
+ perfectlyBalance(iterationType = this.iterationType) {
10502
10564
  const sorted = this.dfs((node) => node, "in"), n = sorted.length;
10503
10565
  if (sorted.length < 1)
10504
10566
  return false;
@@ -10534,8 +10596,8 @@ var dataStructureTyped = (() => {
10534
10596
  }
10535
10597
  }
10536
10598
  /**
10537
- * Time Complexity: O(n log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node.
10538
- * Space Complexity: O(n) - linear space, as it creates an array to store the sorted nodes.
10599
+ * Time Complexity: O(k log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each.
10600
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
10539
10601
  */
10540
10602
  /**
10541
10603
  * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (AVLTree) has logarithmic time complexity.
@@ -10609,8 +10671,8 @@ var dataStructureTyped = (() => {
10609
10671
  return deletedResult;
10610
10672
  }
10611
10673
  /**
10612
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (AVLTree) has logarithmic time complexity.
10613
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
10674
+ * Time Complexity: O(n log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node.
10675
+ * Space Complexity: O(n) - linear space, as it creates an array to store the sorted nodes.
10614
10676
  */
10615
10677
  /**
10616
10678
  * The clear() function clears the contents of a data structure and sets the count to zero.
@@ -10619,6 +10681,22 @@ var dataStructureTyped = (() => {
10619
10681
  super.clear();
10620
10682
  this._count = 0;
10621
10683
  }
10684
+ /**
10685
+ * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (AVLTree) has logarithmic time complexity.
10686
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
10687
+ */
10688
+ init(elements) {
10689
+ if (elements) {
10690
+ for (const entryOrKey of elements) {
10691
+ if (Array.isArray(entryOrKey)) {
10692
+ const [key, value] = entryOrKey;
10693
+ this.add(key, value);
10694
+ } else {
10695
+ this.add(entryOrKey);
10696
+ }
10697
+ }
10698
+ }
10699
+ }
10622
10700
  /**
10623
10701
  * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
10624
10702
  * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.