data-structure-typed 1.46.1 → 1.46.2

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.
@@ -3162,6 +3162,20 @@ var dataStructureTyped = (() => {
3162
3162
 
3163
3163
  // src/data-structures/queue/deque.ts
3164
3164
  var DequeIterator = class _DequeIterator {
3165
+ /**
3166
+ * The constructor initializes the index, iterate direction, and prev/next functions for a
3167
+ * DequeIterator object.
3168
+ * @param {number} index - The index parameter represents the current index position of the iterator
3169
+ * within the deque. It is a number that indicates the position of the element that the iterator is
3170
+ * currently pointing to.
3171
+ * @param deque - The `deque` parameter is an instance of the `Deque` class. It represents a
3172
+ * double-ended queue data structure, which allows elements to be added or removed from both ends.
3173
+ * @param iterateDirection - The `iterateDirection` parameter is an optional parameter that specifies
3174
+ * the direction in which the iterator should iterate over the elements of the `deque`. It has a
3175
+ * default value of `IterateDirection.DEFAULT`.
3176
+ * @returns The constructor is not returning anything. It is used to initialize the properties of the
3177
+ * object being created.
3178
+ */
3165
3179
  constructor(index, deque, iterateDirection = 0 /* DEFAULT */) {
3166
3180
  __publicField(this, "iterateDirection");
3167
3181
  __publicField(this, "index");
@@ -3221,6 +3235,15 @@ var dataStructureTyped = (() => {
3221
3235
  }
3222
3236
  };
3223
3237
  var Deque = class _Deque {
3238
+ /**
3239
+ * The constructor initializes a data structure with a specified bucket size and populates it with
3240
+ * elements from an iterable.
3241
+ * @param elements - The `elements` parameter is an iterable object (such as an array or a Set) that
3242
+ * contains the initial elements to be stored in the data structure. It can also be an object with a
3243
+ * `length` property or a `size` property, which represents the number of elements in the iterable.
3244
+ * @param bucketSize - The `bucketSize` parameter is the maximum number of elements that can be
3245
+ * stored in each bucket. It determines the size of each bucket in the data structure.
3246
+ */
3224
3247
  constructor(elements = [], bucketSize = 1 << 12) {
3225
3248
  __publicField(this, "_bucketFirst", 0);
3226
3249
  __publicField(this, "_firstInBucket", 0);
@@ -3232,9 +3255,15 @@ var dataStructureTyped = (() => {
3232
3255
  __publicField(this, "_size", 0);
3233
3256
  let _size;
3234
3257
  if ("length" in elements) {
3235
- _size = elements.length;
3258
+ if (elements.length instanceof Function)
3259
+ _size = elements.length();
3260
+ else
3261
+ _size = elements.length;
3236
3262
  } else {
3237
- _size = elements.size;
3263
+ if (elements.size instanceof Function)
3264
+ _size = elements.size();
3265
+ else
3266
+ _size = elements.size;
3238
3267
  }
3239
3268
  this._bucketSize = bucketSize;
3240
3269
  this._bucketCount = calcMinUnitsRequired(_size, this._bucketSize) || 1;
@@ -3254,6 +3283,11 @@ var dataStructureTyped = (() => {
3254
3283
  get size() {
3255
3284
  return this._size;
3256
3285
  }
3286
+ /**
3287
+ * The function returns the first element in a collection if it exists, otherwise it returns
3288
+ * undefined.
3289
+ * @returns The first element of the collection, of type E, is being returned.
3290
+ */
3257
3291
  get first() {
3258
3292
  if (this.size === 0)
3259
3293
  return;
@@ -3264,13 +3298,6 @@ var dataStructureTyped = (() => {
3264
3298
  return;
3265
3299
  return this._buckets[this._bucketLast][this._lastInBucket];
3266
3300
  }
3267
- /**
3268
- * Time Complexity: Amortized O(1) - Generally constant time, but resizing when the deque is full leads to O(n).
3269
- * Space Complexity: O(n) - In worst case, resizing doubles the array size.
3270
- */
3271
- empty() {
3272
- return this._size === 0;
3273
- }
3274
3301
  /**
3275
3302
  * Time Complexity: O(1) - Removes the last element.
3276
3303
  * Space Complexity: O(1) - Operates in-place.
@@ -3329,24 +3356,60 @@ var dataStructureTyped = (() => {
3329
3356
  popFirst() {
3330
3357
  return this.shift();
3331
3358
  }
3359
+ /**
3360
+ * The clear() function resets the state of the object by initializing all variables to their default
3361
+ * values.
3362
+ */
3332
3363
  clear() {
3333
3364
  this._buckets = [new Array(this._bucketSize)];
3334
3365
  this._bucketCount = 1;
3335
3366
  this._bucketFirst = this._bucketLast = this._size = 0;
3336
3367
  this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
3337
3368
  }
3369
+ /**
3370
+ * The `begin()` function returns a new iterator for a deque starting from the first element.
3371
+ * @returns A new instance of the DequeIterator class is being returned.
3372
+ */
3338
3373
  begin() {
3339
3374
  return new DequeIterator(0, this);
3340
3375
  }
3376
+ /**
3377
+ * The `end()` function returns a new `DequeIterator` object with the size and reference to the
3378
+ * current deque.
3379
+ * @returns A new instance of the DequeIterator class is being returned.
3380
+ */
3341
3381
  end() {
3342
3382
  return new DequeIterator(this.size, this);
3343
3383
  }
3384
+ /**
3385
+ * The reverseBegin function returns a new DequeIterator object that starts at the last element of
3386
+ * the deque and iterates in reverse direction.
3387
+ * @returns A new instance of the DequeIterator class is being returned.
3388
+ */
3344
3389
  reverseBegin() {
3345
3390
  return new DequeIterator(this.size - 1, this, 1 /* REVERSE */);
3346
3391
  }
3392
+ /**
3393
+ * The reverseEnd() function returns a new DequeIterator object that iterates over the elements of a
3394
+ * Deque in reverse order.
3395
+ * @returns A new instance of the DequeIterator class is being returned.
3396
+ */
3347
3397
  reverseEnd() {
3348
3398
  return new DequeIterator(-1, this, 1 /* REVERSE */);
3349
3399
  }
3400
+ /**
3401
+ * Time Complexity - Amortized O(1) (possible reallocation)
3402
+ * Space Complexity - O(n) (due to potential resizing).
3403
+ */
3404
+ /**
3405
+ * Time Complexity - Amortized O(1) (possible reallocation),
3406
+ * Space Complexity - O(n) (due to potential resizing).
3407
+ *
3408
+ * The push function adds an element to a data structure and reallocates memory if necessary.
3409
+ * @param {E} element - The `element` parameter represents the value that you want to add to the data
3410
+ * structure.
3411
+ * @returns The size of the data structure after the element has been pushed.
3412
+ */
3350
3413
  push(element) {
3351
3414
  if (this.size) {
3352
3415
  if (this._lastInBucket < this._bucketSize - 1) {
@@ -3365,6 +3428,18 @@ var dataStructureTyped = (() => {
3365
3428
  this._buckets[this._bucketLast][this._lastInBucket] = element;
3366
3429
  return this.size;
3367
3430
  }
3431
+ /**
3432
+ * Time Complexity: O(1)
3433
+ * Space Complexity: O(1)
3434
+ */
3435
+ /**
3436
+ * Time Complexity: O(1)
3437
+ * Space Complexity: O(1)
3438
+ *
3439
+ * The `pop()` function removes and returns the last element from a data structure, updating the
3440
+ * internal state variables accordingly.
3441
+ * @returns The element that was removed from the data structure is being returned.
3442
+ */
3368
3443
  pop() {
3369
3444
  if (this.size === 0)
3370
3445
  return;
@@ -3383,6 +3458,20 @@ var dataStructureTyped = (() => {
3383
3458
  this._size -= 1;
3384
3459
  return element;
3385
3460
  }
3461
+ /**
3462
+ * Time Complexity: Amortized O(1)
3463
+ * Space Complexity: O(n)
3464
+ */
3465
+ /**
3466
+ * Time Complexity: Amortized O(1)
3467
+ * Space Complexity: O(n)
3468
+ *
3469
+ * The `unshift` function adds an element to the beginning of an array-like data structure and
3470
+ * returns the new size of the structure.
3471
+ * @param {E} element - The `element` parameter represents the element that you want to add to the
3472
+ * beginning of the data structure.
3473
+ * @returns The size of the data structure after the element has been added.
3474
+ */
3386
3475
  unshift(element) {
3387
3476
  if (this.size) {
3388
3477
  if (this._firstInBucket > 0) {
@@ -3401,6 +3490,19 @@ var dataStructureTyped = (() => {
3401
3490
  this._buckets[this._bucketFirst][this._firstInBucket] = element;
3402
3491
  return this.size;
3403
3492
  }
3493
+ /**
3494
+ * Time Complexity: O(1)
3495
+ * Space Complexity: O(1)
3496
+ */
3497
+ /**
3498
+ * Time Complexity: O(1)
3499
+ * Space Complexity: O(1)
3500
+ *
3501
+ * The `shift()` function removes and returns the first element from a data structure, updating the
3502
+ * internal state variables accordingly.
3503
+ * @returns The element that is being removed from the beginning of the data structure is being
3504
+ * returned.
3505
+ */
3404
3506
  shift() {
3405
3507
  if (this.size === 0)
3406
3508
  return;
@@ -3419,6 +3521,20 @@ var dataStructureTyped = (() => {
3419
3521
  this._size -= 1;
3420
3522
  return element;
3421
3523
  }
3524
+ /**
3525
+ * Time Complexity: O(1)
3526
+ * Space Complexity: O(1)
3527
+ */
3528
+ /**
3529
+ * Time Complexity: O(1)
3530
+ * Space Complexity: O(1)
3531
+ *
3532
+ * The `getAt` function retrieves an element at a specified position in an array-like data structure.
3533
+ * @param {number} pos - The `pos` parameter represents the position of the element that you want to
3534
+ * retrieve from the data structure. It is of type `number` and should be a valid index within the
3535
+ * range of the data structure.
3536
+ * @returns The element at the specified position in the data structure is being returned.
3537
+ */
3422
3538
  getAt(pos) {
3423
3539
  rangeCheck(pos, 0, this.size - 1);
3424
3540
  const {
@@ -3427,6 +3543,20 @@ var dataStructureTyped = (() => {
3427
3543
  } = this._getBucketAndPosition(pos);
3428
3544
  return this._buckets[bucketIndex][indexInBucket];
3429
3545
  }
3546
+ /**
3547
+ * Time Complexity: O(1)
3548
+ * Space Complexity: O(1)
3549
+ */
3550
+ /**
3551
+ * Time Complexity: O(1)
3552
+ * Space Complexity: O(1)
3553
+ *
3554
+ * The `setAt` function sets an element at a specific position in an array-like data structure.
3555
+ * @param {number} pos - The `pos` parameter represents the position at which the element needs to be
3556
+ * set. It is of type `number`.
3557
+ * @param {E} element - The `element` parameter is the value that you want to set at the specified
3558
+ * position in the data structure.
3559
+ */
3430
3560
  setAt(pos, element) {
3431
3561
  rangeCheck(pos, 0, this.size - 1);
3432
3562
  const {
@@ -3435,6 +3565,25 @@ var dataStructureTyped = (() => {
3435
3565
  } = this._getBucketAndPosition(pos);
3436
3566
  this._buckets[bucketIndex][indexInBucket] = element;
3437
3567
  }
3568
+ /**
3569
+ * Time Complexity: O(n)
3570
+ * Space Complexity: O(n)
3571
+ */
3572
+ /**
3573
+ * Time Complexity: O(n)
3574
+ * Space Complexity: O(n)
3575
+ *
3576
+ * The `insertAt` function inserts one or more elements at a specified position in an array-like data
3577
+ * structure.
3578
+ * @param {number} pos - The `pos` parameter represents the position at which the element(s) should
3579
+ * be inserted. It is of type `number`.
3580
+ * @param {E} element - The `element` parameter represents the element that you want to insert into
3581
+ * the array at the specified position.
3582
+ * @param [num=1] - The `num` parameter represents the number of times the `element` should be
3583
+ * inserted at the specified position (`pos`). By default, it is set to 1, meaning that the `element`
3584
+ * will be inserted once. However, you can provide a different value for `num` if you want
3585
+ * @returns The size of the array after the insertion is being returned.
3586
+ */
3438
3587
  insertAt(pos, element, num = 1) {
3439
3588
  const length = this.size;
3440
3589
  rangeCheck(pos, 0, length);
@@ -3457,6 +3606,20 @@ var dataStructureTyped = (() => {
3457
3606
  }
3458
3607
  return this.size;
3459
3608
  }
3609
+ /**
3610
+ * Time Complexity: O(1)
3611
+ * Space Complexity: O(1)
3612
+ */
3613
+ /**
3614
+ * Time Complexity: O(1)
3615
+ * Space Complexity: O(1)
3616
+ *
3617
+ * The `cut` function updates the state of the object based on the given position and returns the
3618
+ * updated size.
3619
+ * @param {number} pos - The `pos` parameter represents the position at which the string should be
3620
+ * cut. It is a number that indicates the index of the character where the cut should be made.
3621
+ * @returns The method is returning the updated size of the data structure.
3622
+ */
3460
3623
  cut(pos) {
3461
3624
  if (pos < 0) {
3462
3625
  this.clear();
@@ -3471,6 +3634,21 @@ var dataStructureTyped = (() => {
3471
3634
  this._size = pos + 1;
3472
3635
  return this.size;
3473
3636
  }
3637
+ /**
3638
+ * Time Complexity: O(n)
3639
+ * Space Complexity: O(1)
3640
+ */
3641
+ /**
3642
+ * Time Complexity: O(n)
3643
+ * Space Complexity: O(1)
3644
+ *
3645
+ * The `deleteAt` function removes an element at a specified position in an array-like data
3646
+ * structure.
3647
+ * @param {number} pos - The `pos` parameter in the `deleteAt` function represents the position at
3648
+ * which an element needs to be deleted from the data structure. It is of type `number` and indicates
3649
+ * the index of the element to be deleted.
3650
+ * @returns The size of the data structure after the deletion operation is performed.
3651
+ */
3474
3652
  deleteAt(pos) {
3475
3653
  rangeCheck(pos, 0, this.size - 1);
3476
3654
  if (pos === 0)
@@ -3496,6 +3674,20 @@ var dataStructureTyped = (() => {
3496
3674
  }
3497
3675
  return this.size;
3498
3676
  }
3677
+ /**
3678
+ * Time Complexity: O(n)
3679
+ * Space Complexity: O(1)
3680
+ */
3681
+ /**
3682
+ * Time Complexity: O(n)
3683
+ * Space Complexity: O(1)
3684
+ *
3685
+ * The `delete` function removes all occurrences of a specified element from an array-like data
3686
+ * structure.
3687
+ * @param {E} element - The `element` parameter represents the element that you want to delete from
3688
+ * the data structure.
3689
+ * @returns The size of the data structure after the element has been deleted.
3690
+ */
3499
3691
  delete(element) {
3500
3692
  const size = this.size;
3501
3693
  if (size === 0)
@@ -3513,12 +3705,38 @@ var dataStructureTyped = (() => {
3513
3705
  this.cut(index - 1);
3514
3706
  return this.size;
3515
3707
  }
3708
+ /**
3709
+ * Time Complexity: O(n)
3710
+ * Space Complexity: O(1)
3711
+ */
3712
+ /**
3713
+ * Time Complexity: O(n)
3714
+ * Space Complexity: O(1)
3715
+ *
3716
+ * The function deletes an element from a deque using an iterator and returns the next iterator.
3717
+ * @param iter - The parameter `iter` is of type `DequeIterator<E>`. It represents an iterator object
3718
+ * that is used to iterate over elements in a deque (double-ended queue).
3719
+ * @returns the updated iterator after deleting an element from the deque.
3720
+ */
3516
3721
  deleteByIterator(iter) {
3517
3722
  const index = iter.index;
3518
3723
  this.deleteAt(index);
3519
3724
  iter = iter.next();
3520
3725
  return iter;
3521
3726
  }
3727
+ /**
3728
+ * Time Complexity: O(n)
3729
+ * Space Complexity: O(1)
3730
+ */
3731
+ /**
3732
+ * Time Complexity: O(n)
3733
+ * Space Complexity: O(1)
3734
+ *
3735
+ * The function `findIterator` searches for an element in a deque and returns an iterator pointing to
3736
+ * the element if found, otherwise it returns an iterator pointing to the end of the deque.
3737
+ * @param {E} element - The `element` parameter is the element that you want to find in the deque.
3738
+ * @returns The method `findIterator(element: E)` returns a `DequeIterator<E>` object.
3739
+ */
3522
3740
  findIterator(element) {
3523
3741
  for (let i = 0; i < this.size; ++i) {
3524
3742
  if (this.getAt(i) === element) {
@@ -3527,6 +3745,19 @@ var dataStructureTyped = (() => {
3527
3745
  }
3528
3746
  return this.end();
3529
3747
  }
3748
+ /**
3749
+ * Time Complexity: O(n)
3750
+ * Space Complexity: O(1)
3751
+ */
3752
+ /**
3753
+ * Time Complexity: O(n)
3754
+ * Space Complexity: O(1)
3755
+ *
3756
+ * The reverse() function reverses the order of the buckets and the elements within each bucket in a
3757
+ * data structure.
3758
+ * @returns The reverse() method is returning the object itself (this) after performing the reverse
3759
+ * operation on the buckets and updating the relevant properties.
3760
+ */
3530
3761
  reverse() {
3531
3762
  this._buckets.reverse().forEach(function(bucket) {
3532
3763
  bucket.reverse();
@@ -3538,6 +3769,18 @@ var dataStructureTyped = (() => {
3538
3769
  this._lastInBucket = this._bucketSize - _firstInBucket - 1;
3539
3770
  return this;
3540
3771
  }
3772
+ /**
3773
+ * Time Complexity: O(n)
3774
+ * Space Complexity: O(1)
3775
+ */
3776
+ /**
3777
+ * Time Complexity: O(n)
3778
+ * Space Complexity: O(1)
3779
+ *
3780
+ * The `unique()` function removes duplicate elements from an array-like data structure and returns
3781
+ * the number of unique elements.
3782
+ * @returns The size of the modified array is being returned.
3783
+ */
3541
3784
  unique() {
3542
3785
  if (this.size <= 1) {
3543
3786
  return this.size;
@@ -3554,6 +3797,20 @@ var dataStructureTyped = (() => {
3554
3797
  this.cut(index - 1);
3555
3798
  return this.size;
3556
3799
  }
3800
+ /**
3801
+ * Time Complexity: O(n log n)
3802
+ * Space Complexity: O(n)
3803
+ */
3804
+ /**
3805
+ * Time Complexity: O(n log n)
3806
+ * Space Complexity: O(n)
3807
+ *
3808
+ * The `sort` function sorts the elements in a data structure using a provided comparator function.
3809
+ * @param [comparator] - The `comparator` parameter is a function that takes in two elements `x` and
3810
+ * `y` of type `E` and returns a number. The comparator function is used to determine the order of
3811
+ * the elements in the sorted array.
3812
+ * @returns The method is returning the sorted instance of the object on which the method is called.
3813
+ */
3557
3814
  sort(comparator) {
3558
3815
  const arr = [];
3559
3816
  for (let i = 0; i < this.size; ++i) {
@@ -3565,6 +3822,19 @@ var dataStructureTyped = (() => {
3565
3822
  }
3566
3823
  return this;
3567
3824
  }
3825
+ /**
3826
+ * Time Complexity: O(n)
3827
+ * Space Complexity: O(n)
3828
+ */
3829
+ /**
3830
+ * Time Complexity: O(n)
3831
+ * Space Complexity: O(n)
3832
+ *
3833
+ * The `shrinkToFit` function reorganizes the elements in an array-like data structure to minimize
3834
+ * memory usage.
3835
+ * @returns Nothing is being returned. The function is using the `return` statement to exit early if
3836
+ * `this.size` is 0, but it does not return any value.
3837
+ */
3568
3838
  shrinkToFit() {
3569
3839
  if (this.size === 0)
3570
3840
  return;
@@ -3587,11 +3857,39 @@ var dataStructureTyped = (() => {
3587
3857
  this._bucketLast = newBuckets.length - 1;
3588
3858
  this._buckets = newBuckets;
3589
3859
  }
3860
+ /**
3861
+ * Time Complexity: O(n)
3862
+ * Space Complexity: O(1)
3863
+ */
3864
+ /**
3865
+ * Time Complexity: O(n)
3866
+ * Space Complexity: O(1)
3867
+ *
3868
+ * The `forEach` function iterates over each element in a deque and applies a callback function to
3869
+ * each element.
3870
+ * @param callback - The callback parameter is a function that will be called for each element in the
3871
+ * deque. It takes three parameters:
3872
+ */
3590
3873
  forEach(callback) {
3591
3874
  for (let i = 0; i < this.size; ++i) {
3592
3875
  callback(this.getAt(i), i, this);
3593
3876
  }
3594
3877
  }
3878
+ /**
3879
+ * Time Complexity: O(n)
3880
+ * Space Complexity: O(1)
3881
+ */
3882
+ /**
3883
+ * Time Complexity: O(n)
3884
+ * Space Complexity: O(1)
3885
+ *
3886
+ * The `find` function iterates over the elements in a deque and returns the first element for which
3887
+ * the callback function returns true, or undefined if no such element is found.
3888
+ * @param callback - A function that takes three parameters: element, index, and deque. It should
3889
+ * return a boolean value indicating whether the element satisfies a certain condition.
3890
+ * @returns The method `find` returns the first element in the deque that satisfies the condition
3891
+ * specified by the callback function. If no element satisfies the condition, it returns `undefined`.
3892
+ */
3595
3893
  find(callback) {
3596
3894
  for (let i = 0; i < this.size; ++i) {
3597
3895
  const element = this.getAt(i);
@@ -3601,6 +3899,17 @@ var dataStructureTyped = (() => {
3601
3899
  }
3602
3900
  return void 0;
3603
3901
  }
3902
+ /**
3903
+ * Time Complexity: O(n)
3904
+ * Space Complexity: O(n)
3905
+ */
3906
+ /**
3907
+ * Time Complexity: O(n)
3908
+ * Space Complexity: O(n)
3909
+ *
3910
+ * The `toArray` function converts the elements of a data structure into an array.
3911
+ * @returns The `toArray()` method is returning an array of elements of type `E`.
3912
+ */
3604
3913
  toArray() {
3605
3914
  const arr = [];
3606
3915
  for (let i = 0; i < this.size; ++i) {
@@ -3608,6 +3917,19 @@ var dataStructureTyped = (() => {
3608
3917
  }
3609
3918
  return arr;
3610
3919
  }
3920
+ /**
3921
+ * Time Complexity: O(n)
3922
+ * Space Complexity: O(n)
3923
+ */
3924
+ /**
3925
+ * Time Complexity: O(n)
3926
+ * Space Complexity: O(n)
3927
+ *
3928
+ * The `map` function takes a callback function and applies it to each element in the deque,
3929
+ * returning a new deque with the results.
3930
+ * @param callback - The `callback` parameter is a function that takes three arguments:
3931
+ * @returns The `map` method is returning a new `Deque` object with the transformed elements.
3932
+ */
3611
3933
  map(callback) {
3612
3934
  const newDeque = new _Deque([], this._bucketSize);
3613
3935
  for (let i = 0; i < this.size; ++i) {
@@ -3615,6 +3937,21 @@ var dataStructureTyped = (() => {
3615
3937
  }
3616
3938
  return newDeque;
3617
3939
  }
3940
+ /**
3941
+ * Time Complexity: O(n)
3942
+ * Space Complexity: O(n)
3943
+ */
3944
+ /**
3945
+ * Time Complexity: O(n)
3946
+ * Space Complexity: O(n)
3947
+ *
3948
+ * The `filter` function creates a new deque containing only the elements that satisfy the given
3949
+ * predicate function.
3950
+ * @param predicate - The `predicate` parameter is a function that takes three arguments: `element`,
3951
+ * `index`, and `deque`.
3952
+ * @returns The `filter` method is returning a new `Deque` object that contains only the elements
3953
+ * that satisfy the given `predicate` function.
3954
+ */
3618
3955
  filter(predicate) {
3619
3956
  const newDeque = new _Deque([], this._bucketSize);
3620
3957
  for (let i = 0; i < this.size; ++i) {
@@ -3625,6 +3962,23 @@ var dataStructureTyped = (() => {
3625
3962
  }
3626
3963
  return newDeque;
3627
3964
  }
3965
+ /**
3966
+ * Time Complexity: O(n)
3967
+ * Space Complexity: O(1)
3968
+ */
3969
+ /**
3970
+ * Time Complexity: O(n)
3971
+ * Space Complexity: O(1)
3972
+ *
3973
+ * The `reduce` function iterates over the elements of a deque and applies a callback function to
3974
+ * each element, accumulating a single value.
3975
+ * @param callback - The `callback` parameter is a function that takes four arguments:
3976
+ * @param {T} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
3977
+ * is the value that will be passed as the first argument to the `callback` function when reducing
3978
+ * the elements of the deque.
3979
+ * @returns the final value of the accumulator after iterating over all elements in the deque and
3980
+ * applying the callback function to each element.
3981
+ */
3628
3982
  reduce(callback, initialValue) {
3629
3983
  let accumulator = initialValue;
3630
3984
  for (let i = 0; i < this.size; ++i) {
@@ -3632,6 +3986,21 @@ var dataStructureTyped = (() => {
3632
3986
  }
3633
3987
  return accumulator;
3634
3988
  }
3989
+ /**
3990
+ * Time Complexity: O(n)
3991
+ * Space Complexity: O(1)
3992
+ */
3993
+ /**
3994
+ * Time Complexity: O(n)
3995
+ * Space Complexity: O(1)
3996
+ *
3997
+ * The function "indexOf" returns the index of the first occurrence of a given element in an array,
3998
+ * or -1 if the element is not found.
3999
+ * @param {E} element - The "element" parameter represents the element that you want to find the
4000
+ * index of in the data structure.
4001
+ * @returns The indexOf function returns the index of the first occurrence of the specified element
4002
+ * in the data structure. If the element is not found, it returns -1.
4003
+ */
3635
4004
  indexOf(element) {
3636
4005
  for (let i = 0; i < this.size; ++i) {
3637
4006
  if (this.getAt(i) === element) {
@@ -3640,11 +4009,35 @@ var dataStructureTyped = (() => {
3640
4009
  }
3641
4010
  return -1;
3642
4011
  }
4012
+ /**
4013
+ * Time Complexity: O(n)
4014
+ * Space Complexity: O(1)
4015
+ */
4016
+ /**
4017
+ * Time Complexity: O(n)
4018
+ * Space Complexity: O(1)
4019
+ *
4020
+ * The above function is an implementation of the iterator protocol in TypeScript, allowing the
4021
+ * object to be iterated over using a for...of loop.
4022
+ */
3643
4023
  *[Symbol.iterator]() {
3644
4024
  for (let i = 0; i < this.size; ++i) {
3645
4025
  yield this.getAt(i);
3646
4026
  }
3647
4027
  }
4028
+ /**
4029
+ * Time Complexity: O(n)
4030
+ * Space Complexity: O(n)
4031
+ */
4032
+ /**
4033
+ * Time Complexity: O(n)
4034
+ * Space Complexity: O(n)
4035
+ *
4036
+ * The `_reallocate` function reallocates the buckets in an array, adding new buckets if needed.
4037
+ * @param {number} [needBucketNum] - The `needBucketNum` parameter is an optional number that
4038
+ * specifies the number of new buckets needed. If not provided, it will default to half of the
4039
+ * current bucket count (`this._bucketCount >> 1`) or 1 if the current bucket count is less than 2.
4040
+ */
3648
4041
  _reallocate(needBucketNum) {
3649
4042
  const newBuckets = [];
3650
4043
  const addBucketNum = needBucketNum || this._bucketCount >> 1 || 1;
@@ -3666,6 +4059,19 @@ var dataStructureTyped = (() => {
3666
4059
  this._buckets = newBuckets;
3667
4060
  this._bucketCount = newBuckets.length;
3668
4061
  }
4062
+ /**
4063
+ * Time Complexity: O(1)
4064
+ * Space Complexity: O(1)
4065
+ */
4066
+ /**
4067
+ * Time Complexity: O(1)
4068
+ * Space Complexity: O(1)
4069
+ *
4070
+ * The function calculates the bucket index and index within the bucket based on the given position.
4071
+ * @param {number} pos - The `pos` parameter represents the position within the data structure. It is
4072
+ * a number that indicates the index or position of an element within the structure.
4073
+ * @returns an object with two properties: "bucketIndex" and "indexInBucket".
4074
+ */
3669
4075
  _getBucketAndPosition(pos) {
3670
4076
  let bucketIndex;
3671
4077
  let indexInBucket;