data-structure-typed 1.50.0 → 1.50.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.
Files changed (156) hide show
  1. package/CHANGELOG.md +2 -1
  2. package/README.md +204 -212
  3. package/benchmark/report.html +37 -1
  4. package/benchmark/report.json +370 -22
  5. package/dist/cjs/data-structures/base/iterable-base.d.ts +114 -9
  6. package/dist/cjs/data-structures/base/iterable-base.js +143 -7
  7. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +43 -46
  9. package/dist/cjs/data-structures/binary-tree/avl-tree.js +68 -71
  10. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.js +484 -376
  13. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/bst.d.ts +54 -74
  15. package/dist/cjs/data-structures/binary-tree/bst.js +30 -71
  16. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +78 -60
  18. package/dist/cjs/data-structures/binary-tree/rb-tree.js +84 -89
  19. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +37 -56
  21. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +64 -85
  22. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -0
  24. package/dist/cjs/data-structures/graph/abstract-graph.js +3 -0
  25. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  26. package/dist/cjs/data-structures/graph/directed-graph.d.ts +14 -0
  27. package/dist/cjs/data-structures/graph/directed-graph.js +26 -0
  28. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  29. package/dist/cjs/data-structures/graph/map-graph.d.ts +8 -0
  30. package/dist/cjs/data-structures/graph/map-graph.js +14 -0
  31. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  32. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +16 -0
  33. package/dist/cjs/data-structures/graph/undirected-graph.js +25 -0
  34. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  35. package/dist/cjs/data-structures/hash/hash-map.d.ts +121 -15
  36. package/dist/cjs/data-structures/hash/hash-map.js +160 -25
  37. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  38. package/dist/cjs/data-structures/heap/heap.d.ts +66 -6
  39. package/dist/cjs/data-structures/heap/heap.js +66 -6
  40. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  41. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
  42. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +70 -64
  43. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  44. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +128 -103
  45. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +130 -112
  46. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  47. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  48. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +63 -36
  49. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  50. package/dist/cjs/data-structures/matrix/matrix.d.ts +35 -4
  51. package/dist/cjs/data-structures/matrix/matrix.js +50 -11
  52. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  53. package/dist/cjs/data-structures/queue/deque.d.ts +49 -19
  54. package/dist/cjs/data-structures/queue/deque.js +101 -47
  55. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  56. package/dist/cjs/data-structures/queue/queue.d.ts +39 -5
  57. package/dist/cjs/data-structures/queue/queue.js +47 -5
  58. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  59. package/dist/cjs/data-structures/stack/stack.d.ts +16 -0
  60. package/dist/cjs/data-structures/stack/stack.js +22 -0
  61. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  62. package/dist/cjs/data-structures/trie/trie.d.ts +38 -1
  63. package/dist/cjs/data-structures/trie/trie.js +41 -0
  64. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  65. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  66. package/dist/cjs/types/data-structures/hash/hash-map.d.ts +4 -3
  67. package/dist/cjs/types/utils/utils.d.ts +1 -0
  68. package/dist/mjs/data-structures/base/iterable-base.d.ts +114 -9
  69. package/dist/mjs/data-structures/base/iterable-base.js +143 -7
  70. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +43 -46
  71. package/dist/mjs/data-structures/binary-tree/avl-tree.js +68 -71
  72. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
  73. package/dist/mjs/data-structures/binary-tree/binary-tree.js +483 -375
  74. package/dist/mjs/data-structures/binary-tree/bst.d.ts +54 -74
  75. package/dist/mjs/data-structures/binary-tree/bst.js +30 -71
  76. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +78 -60
  77. package/dist/mjs/data-structures/binary-tree/rb-tree.js +84 -89
  78. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +37 -56
  79. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +64 -85
  80. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -0
  81. package/dist/mjs/data-structures/graph/abstract-graph.js +3 -0
  82. package/dist/mjs/data-structures/graph/directed-graph.d.ts +14 -0
  83. package/dist/mjs/data-structures/graph/directed-graph.js +26 -0
  84. package/dist/mjs/data-structures/graph/map-graph.d.ts +8 -0
  85. package/dist/mjs/data-structures/graph/map-graph.js +14 -0
  86. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +16 -0
  87. package/dist/mjs/data-structures/graph/undirected-graph.js +25 -0
  88. package/dist/mjs/data-structures/hash/hash-map.d.ts +121 -15
  89. package/dist/mjs/data-structures/hash/hash-map.js +160 -25
  90. package/dist/mjs/data-structures/heap/heap.d.ts +66 -6
  91. package/dist/mjs/data-structures/heap/heap.js +66 -6
  92. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
  93. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +70 -64
  94. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +128 -103
  95. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +130 -112
  96. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  97. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +63 -36
  98. package/dist/mjs/data-structures/matrix/matrix.d.ts +35 -4
  99. package/dist/mjs/data-structures/matrix/matrix.js +50 -11
  100. package/dist/mjs/data-structures/queue/deque.d.ts +49 -19
  101. package/dist/mjs/data-structures/queue/deque.js +101 -47
  102. package/dist/mjs/data-structures/queue/queue.d.ts +39 -5
  103. package/dist/mjs/data-structures/queue/queue.js +47 -5
  104. package/dist/mjs/data-structures/stack/stack.d.ts +16 -0
  105. package/dist/mjs/data-structures/stack/stack.js +22 -0
  106. package/dist/mjs/data-structures/trie/trie.d.ts +38 -1
  107. package/dist/mjs/data-structures/trie/trie.js +41 -0
  108. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  109. package/dist/mjs/types/data-structures/hash/hash-map.d.ts +4 -3
  110. package/dist/mjs/types/utils/utils.d.ts +1 -0
  111. package/dist/umd/data-structure-typed.js +1730 -1042
  112. package/dist/umd/data-structure-typed.min.js +3 -3
  113. package/dist/umd/data-structure-typed.min.js.map +1 -1
  114. package/package.json +16 -40
  115. package/src/data-structures/base/iterable-base.ts +172 -19
  116. package/src/data-structures/binary-tree/avl-tree.ts +97 -97
  117. package/src/data-structures/binary-tree/binary-tree.ts +674 -671
  118. package/src/data-structures/binary-tree/bst.ts +89 -131
  119. package/src/data-structures/binary-tree/rb-tree.ts +127 -155
  120. package/src/data-structures/binary-tree/tree-multimap.ts +96 -112
  121. package/src/data-structures/graph/abstract-graph.ts +4 -0
  122. package/src/data-structures/graph/directed-graph.ts +30 -0
  123. package/src/data-structures/graph/map-graph.ts +15 -0
  124. package/src/data-structures/graph/undirected-graph.ts +28 -0
  125. package/src/data-structures/hash/hash-map.ts +175 -34
  126. package/src/data-structures/heap/heap.ts +66 -6
  127. package/src/data-structures/linked-list/doubly-linked-list.ts +72 -66
  128. package/src/data-structures/linked-list/singly-linked-list.ts +132 -114
  129. package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
  130. package/src/data-structures/matrix/matrix.ts +52 -12
  131. package/src/data-structures/queue/deque.ts +108 -49
  132. package/src/data-structures/queue/queue.ts +51 -5
  133. package/src/data-structures/stack/stack.ts +24 -0
  134. package/src/data-structures/trie/trie.ts +45 -1
  135. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  136. package/src/types/data-structures/hash/hash-map.ts +4 -3
  137. package/src/types/utils/utils.ts +2 -0
  138. package/test/performance/data-structures/graph/directed-graph.test.ts +3 -3
  139. package/test/performance/data-structures/queue/deque.test.ts +26 -25
  140. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +37 -0
  141. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -17
  142. package/test/unit/data-structures/binary-tree/bst.test.ts +65 -1
  143. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +38 -1
  144. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -32
  145. package/test/unit/data-structures/graph/abstract-graph.test.ts +8 -0
  146. package/test/unit/data-structures/graph/directed-graph.test.ts +249 -0
  147. package/test/unit/data-structures/hash/hash-map.test.ts +376 -353
  148. package/test/unit/data-structures/heap/heap.test.ts +18 -1
  149. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +24 -5
  150. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +20 -2
  151. package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
  152. package/test/unit/data-structures/queue/deque.test.ts +71 -10
  153. package/test/unit/data-structures/queue/queue.test.ts +23 -6
  154. package/test/unit/data-structures/stack/stack.test.ts +17 -0
  155. package/test/unit/data-structures/trie/trie.test.ts +17 -0
  156. package/test/unit/unrestricted-interconversion.test.ts +143 -10
@@ -14,6 +14,17 @@ export class Deque extends IterableElementBase {
14
14
  _lastInBucket = 0;
15
15
  _bucketCount = 0;
16
16
  _bucketSize = 1 << 12;
17
+ /**
18
+ * The constructor initializes a Deque object with an optional iterable of elements and options.
19
+ * @param elements - An iterable object (such as an array or a Set) that contains the initial
20
+ * elements to be added to the deque. It can also be an object with a `length` or `size` property
21
+ * that represents the number of elements in the iterable object. If no elements are provided, an
22
+ * empty deque
23
+ * @param {DequeOptions} [options] - The `options` parameter is an optional object that can contain
24
+ * configuration options for the deque. In this code, it is used to set the `bucketSize` option,
25
+ * which determines the size of each bucket in the deque. If the `bucketSize` option is not provided
26
+ * or is not a number
27
+ */
17
28
  constructor(elements = [], options) {
18
29
  super();
19
30
  if (options) {
@@ -45,11 +56,28 @@ export class Deque extends IterableElementBase {
45
56
  this.push(element);
46
57
  }
47
58
  }
59
+ /**
60
+ * The bucketSize function returns the size of the bucket.
61
+ *
62
+ * @return The size of the bucket
63
+ */
64
+ get bucketSize() {
65
+ return this._bucketSize;
66
+ }
48
67
  _buckets = [];
68
+ /**
69
+ * The buckets function returns the buckets property of the object.
70
+ *
71
+ * @return The buckets property
72
+ */
49
73
  get buckets() {
50
74
  return this._buckets;
51
75
  }
52
76
  _size = 0;
77
+ /**
78
+ * The size function returns the number of items in the stack.
79
+ * @return The number of values in the set
80
+ */
53
81
  get size() {
54
82
  return this._size;
55
83
  }
@@ -63,6 +91,10 @@ export class Deque extends IterableElementBase {
63
91
  return;
64
92
  return this._buckets[this._bucketFirst][this._firstInBucket];
65
93
  }
94
+ /**
95
+ * The last function returns the last element in the queue.
96
+ * @return The last element in the array
97
+ */
66
98
  get last() {
67
99
  if (this.size === 0)
68
100
  return;
@@ -223,7 +255,7 @@ export class Deque extends IterableElementBase {
223
255
  *begin() {
224
256
  let index = 0;
225
257
  while (index < this.size) {
226
- yield this.getAt(index);
258
+ yield this.at(index);
227
259
  index++;
228
260
  }
229
261
  }
@@ -234,7 +266,7 @@ export class Deque extends IterableElementBase {
234
266
  *reverseBegin() {
235
267
  let index = this.size - 1;
236
268
  while (index >= 0) {
237
- yield this.getAt(index);
269
+ yield this.at(index);
238
270
  index--;
239
271
  }
240
272
  }
@@ -246,13 +278,13 @@ export class Deque extends IterableElementBase {
246
278
  * Time Complexity: O(1)
247
279
  * Space Complexity: O(1)
248
280
  *
249
- * The `getAt` function retrieves an element at a specified position in an array-like data structure.
281
+ * The `at` function retrieves an element at a specified position in an array-like data structure.
250
282
  * @param {number} pos - The `pos` parameter represents the position of the element that you want to
251
283
  * retrieve from the data structure. It is of type `number` and should be a valid index within the
252
284
  * range of the data structure.
253
285
  * @returns The element at the specified position in the data structure is being returned.
254
286
  */
255
- getAt(pos) {
287
+ at(pos) {
256
288
  rangeCheck(pos, 0, this.size - 1);
257
289
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
258
290
  return this._buckets[bucketIndex][indexInBucket];
@@ -310,9 +342,9 @@ export class Deque extends IterableElementBase {
310
342
  else {
311
343
  const arr = [];
312
344
  for (let i = pos; i < this.size; ++i) {
313
- arr.push(this.getAt(i));
345
+ arr.push(this.at(i));
314
346
  }
315
- this.cut(pos - 1);
347
+ this.cut(pos - 1, true);
316
348
  for (let i = 0; i < num; ++i)
317
349
  this.push(element);
318
350
  for (let i = 0; i < arr.length; ++i)
@@ -332,18 +364,48 @@ export class Deque extends IterableElementBase {
332
364
  * updated size.
333
365
  * @param {number} pos - The `pos` parameter represents the position at which the string should be
334
366
  * cut. It is a number that indicates the index of the character where the cut should be made.
367
+ * @param {boolean} isCutSelf - If true, the original deque will not be cut, and return a new deque
335
368
  * @returns The method is returning the updated size of the data structure.
336
369
  */
337
- cut(pos) {
338
- if (pos < 0) {
339
- this.clear();
340
- return 0;
370
+ cut(pos, isCutSelf = false) {
371
+ if (isCutSelf) {
372
+ if (pos < 0) {
373
+ this.clear();
374
+ return this;
375
+ }
376
+ const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
377
+ this._bucketLast = bucketIndex;
378
+ this._lastInBucket = indexInBucket;
379
+ this._size = pos + 1;
380
+ return this;
381
+ }
382
+ else {
383
+ const newDeque = new Deque([], { bucketSize: this._bucketSize });
384
+ for (let i = 0; i <= pos; i++) {
385
+ newDeque.push(this.at(i));
386
+ }
387
+ return newDeque;
388
+ }
389
+ }
390
+ cutRest(pos, isCutSelf = false) {
391
+ if (isCutSelf) {
392
+ if (pos < 0) {
393
+ this.clear();
394
+ return this;
395
+ }
396
+ const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
397
+ this._bucketFirst = bucketIndex;
398
+ this._firstInBucket = indexInBucket;
399
+ this._size = this._size - pos;
400
+ return this;
401
+ }
402
+ else {
403
+ const newDeque = new Deque([], { bucketSize: this._bucketSize });
404
+ for (let i = pos; i < this.size; i++) {
405
+ newDeque.push(this.at(i));
406
+ }
407
+ return newDeque;
341
408
  }
342
- const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
343
- this._bucketLast = bucketIndex;
344
- this._lastInBucket = indexInBucket;
345
- this._size = pos + 1;
346
- return this.size;
347
409
  }
348
410
  /**
349
411
  * Time Complexity: O(n)
@@ -400,14 +462,14 @@ export class Deque extends IterableElementBase {
400
462
  let i = 0;
401
463
  let index = 0;
402
464
  while (i < size) {
403
- const oldElement = this.getAt(i);
465
+ const oldElement = this.at(i);
404
466
  if (oldElement !== element) {
405
467
  this.setAt(index, oldElement);
406
468
  index += 1;
407
469
  }
408
470
  i += 1;
409
471
  }
410
- this.cut(index - 1);
472
+ this.cut(index - 1, true);
411
473
  return true;
412
474
  }
413
475
  /**
@@ -451,15 +513,15 @@ export class Deque extends IterableElementBase {
451
513
  return this;
452
514
  }
453
515
  let index = 1;
454
- let prev = this.getAt(0);
516
+ let prev = this.at(0);
455
517
  for (let i = 1; i < this.size; ++i) {
456
- const cur = this.getAt(i);
518
+ const cur = this.at(i);
457
519
  if (cur !== prev) {
458
520
  prev = cur;
459
521
  this.setAt(index++, cur);
460
522
  }
461
523
  }
462
- this.cut(index - 1);
524
+ this.cut(index - 1, true);
463
525
  return this;
464
526
  }
465
527
  /**
@@ -479,7 +541,7 @@ export class Deque extends IterableElementBase {
479
541
  sort(comparator) {
480
542
  const arr = [];
481
543
  for (let i = 0; i < this.size; ++i) {
482
- arr.push(this.getAt(i));
544
+ arr.push(this.at(i));
483
545
  }
484
546
  arr.sort(comparator);
485
547
  for (let i = 0; i < this.size; ++i) {
@@ -523,30 +585,6 @@ export class Deque extends IterableElementBase {
523
585
  this._bucketLast = newBuckets.length - 1;
524
586
  this._buckets = newBuckets;
525
587
  }
526
- /**
527
- * Time Complexity: O(n)
528
- * Space Complexity: O(1)
529
- */
530
- /**
531
- * Time Complexity: O(n)
532
- * Space Complexity: O(1)
533
- *
534
- * The `find` function iterates over the elements in a deque and returns the first element for which
535
- * the callback function returns true, or undefined if no such element is found.
536
- * @param callback - A function that takes three parameters: element, index, and deque. It should
537
- * return a boolean value indicating whether the element satisfies a certain condition.
538
- * @returns The method `find` returns the first element in the deque that satisfies the condition
539
- * specified by the callback function. If no element satisfies the condition, it returns `undefined`.
540
- */
541
- find(callback) {
542
- for (let i = 0; i < this.size; ++i) {
543
- const element = this.getAt(i);
544
- if (callback(element, i, this)) {
545
- return element;
546
- }
547
- }
548
- return;
549
- }
550
588
  /**
551
589
  * Time Complexity: O(n)
552
590
  * Space Complexity: O(1)
@@ -564,7 +602,7 @@ export class Deque extends IterableElementBase {
564
602
  */
565
603
  indexOf(element) {
566
604
  for (let i = 0; i < this.size; ++i) {
567
- if (this.getAt(i) === element) {
605
+ if (this.at(i) === element) {
568
606
  return i;
569
607
  }
570
608
  }
@@ -584,6 +622,22 @@ export class Deque extends IterableElementBase {
584
622
  toArray() {
585
623
  return [...this];
586
624
  }
625
+ /**
626
+ * Time Complexity: O(n)
627
+ * Space Complexity: O(n)
628
+ */
629
+ /**
630
+ * Time Complexity: O(n)
631
+ * Space Complexity: O(n)
632
+ *
633
+ * The `clone()` function returns a new instance of the `Deque` class with the same elements and
634
+ * bucket size as the original instance.
635
+ * @returns The `clone()` method is returning a new instance of the `Deque` class with the same
636
+ * elements as the original deque (`this`) and the same bucket size.
637
+ */
638
+ clone() {
639
+ return new Deque([...this], { bucketSize: this.bucketSize });
640
+ }
587
641
  /**
588
642
  * Time Complexity: O(n)
589
643
  * Space Complexity: O(n)
@@ -701,7 +755,7 @@ export class Deque extends IterableElementBase {
701
755
  */
702
756
  *_getIterator() {
703
757
  for (let i = 0; i < this.size; ++i) {
704
- yield this.getAt(i);
758
+ yield this.at(i);
705
759
  }
706
760
  }
707
761
  /**
@@ -24,8 +24,16 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
24
24
  */
25
25
  constructor(elements?: Iterable<E>);
26
26
  protected _elements: E[];
27
+ /**
28
+ * The elements function returns the elements of this set.
29
+ * @return An array of the elements in the stack
30
+ */
27
31
  get elements(): E[];
28
32
  protected _offset: number;
33
+ /**
34
+ * The offset function returns the offset of the current page.
35
+ * @return The value of the private variable _offset
36
+ */
29
37
  get offset(): number;
30
38
  /**
31
39
  * The size function returns the number of elements in an array.
@@ -93,6 +101,18 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
93
101
  * @returns The function `shift()` returns either the first element in the queue or `undefined` if the queue is empty.
94
102
  */
95
103
  shift(): E | undefined;
104
+ /**
105
+ * The delete function removes an element from the list.
106
+ * @param element: E Specify the element to be deleted
107
+ * @return A boolean value indicating whether the element was successfully deleted or not
108
+ */
109
+ delete(element: E): boolean;
110
+ /**
111
+ * The deleteAt function deletes the element at a given index.
112
+ * @param index: number Determine the index of the element to be deleted
113
+ * @return A boolean value
114
+ */
115
+ deleteAt(index: number): boolean;
96
116
  /**
97
117
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
98
118
  * Space Complexity: O(1) - no additional space is used.
@@ -153,7 +173,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
153
173
  *
154
174
  * @param index
155
175
  */
156
- getAt(index: number): E | undefined;
176
+ at(index: number): E | undefined;
157
177
  /**
158
178
  * Time Complexity: O(1) - constant time as it retrieves the value at the specified index.
159
179
  * Space Complexity: O(1) - no additional space is used.
@@ -183,12 +203,13 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
183
203
  */
184
204
  clear(): void;
185
205
  /**
186
- * Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
187
- * Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
206
+ * Time Complexity: O(n)
207
+ * Space Complexity: O(n)
208
+ * where n is the number of elements in the queue. It creates a shallow copy of the internal array. the space required is proportional to the number of elements in the queue.
188
209
  */
189
210
  /**
190
- * Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
191
- * Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
211
+ * Time Complexity: O(n)
212
+ * Space Complexity: O(n)
192
213
  *
193
214
  * The `clone()` function returns a new Queue object with the same elements as the original Queue.
194
215
  * @returns The `clone()` method is returning a new instance of the `Queue` class.
@@ -267,4 +288,17 @@ export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
267
288
  * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
268
289
  */
269
290
  peek(): E | undefined;
291
+ /**
292
+ * Time Complexity: O(n)
293
+ * Space Complexity: O(n)
294
+ */
295
+ /**
296
+ * Time Complexity: O(n)
297
+ * Space Complexity: O(n)
298
+ * The `clone` function returns a new instance of the `LinkedListQueue` class with the same values as
299
+ * the current instance.
300
+ * @returns The `clone()` method is returning a new instance of `LinkedListQueue` with the same
301
+ * values as the original `LinkedListQueue`.
302
+ */
303
+ clone(): LinkedListQueue<E>;
270
304
  }
@@ -24,10 +24,18 @@ export class Queue extends IterableElementBase {
24
24
  }
25
25
  }
26
26
  _elements = [];
27
+ /**
28
+ * The elements function returns the elements of this set.
29
+ * @return An array of the elements in the stack
30
+ */
27
31
  get elements() {
28
32
  return this._elements;
29
33
  }
30
34
  _offset = 0;
35
+ /**
36
+ * The offset function returns the offset of the current page.
37
+ * @return The value of the private variable _offset
38
+ */
31
39
  get offset() {
32
40
  return this._offset;
33
41
  }
@@ -120,6 +128,24 @@ export class Queue extends IterableElementBase {
120
128
  this._offset = 0;
121
129
  return first;
122
130
  }
131
+ /**
132
+ * The delete function removes an element from the list.
133
+ * @param element: E Specify the element to be deleted
134
+ * @return A boolean value indicating whether the element was successfully deleted or not
135
+ */
136
+ delete(element) {
137
+ const index = this.elements.indexOf(element);
138
+ return this.deleteAt(index);
139
+ }
140
+ /**
141
+ * The deleteAt function deletes the element at a given index.
142
+ * @param index: number Determine the index of the element to be deleted
143
+ * @return A boolean value
144
+ */
145
+ deleteAt(index) {
146
+ const spliced = this.elements.splice(index, 1);
147
+ return spliced.length === 1;
148
+ }
123
149
  /**
124
150
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
125
151
  * Space Complexity: O(1) - no additional space is used.
@@ -188,7 +214,7 @@ export class Queue extends IterableElementBase {
188
214
  *
189
215
  * @param index
190
216
  */
191
- getAt(index) {
217
+ at(index) {
192
218
  return this.elements[index];
193
219
  }
194
220
  /**
@@ -227,12 +253,13 @@ export class Queue extends IterableElementBase {
227
253
  this._offset = 0;
228
254
  }
229
255
  /**
230
- * Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
231
- * Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
256
+ * Time Complexity: O(n)
257
+ * Space Complexity: O(n)
258
+ * where n is the number of elements in the queue. It creates a shallow copy of the internal array. the space required is proportional to the number of elements in the queue.
232
259
  */
233
260
  /**
234
- * Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
235
- * Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
261
+ * Time Complexity: O(n)
262
+ * Space Complexity: O(n)
236
263
  *
237
264
  * The `clone()` function returns a new Queue object with the same elements as the original Queue.
238
265
  * @returns The `clone()` method is returning a new instance of the `Queue` class.
@@ -343,4 +370,19 @@ export class LinkedListQueue extends SinglyLinkedList {
343
370
  peek() {
344
371
  return this.first;
345
372
  }
373
+ /**
374
+ * Time Complexity: O(n)
375
+ * Space Complexity: O(n)
376
+ */
377
+ /**
378
+ * Time Complexity: O(n)
379
+ * Space Complexity: O(n)
380
+ * The `clone` function returns a new instance of the `LinkedListQueue` class with the same values as
381
+ * the current instance.
382
+ * @returns The `clone()` method is returning a new instance of `LinkedListQueue` with the same
383
+ * values as the original `LinkedListQueue`.
384
+ */
385
+ clone() {
386
+ return new LinkedListQueue(this.values());
387
+ }
346
388
  }
@@ -24,6 +24,10 @@ export declare class Stack<E = any> extends IterableElementBase<E> {
24
24
  */
25
25
  constructor(elements?: Iterable<E>);
26
26
  protected _elements: E[];
27
+ /**
28
+ * The elements function returns the elements of this set.
29
+ * @return An array of elements
30
+ */
27
31
  get elements(): E[];
28
32
  /**
29
33
  * Time Complexity: O(n), where n is the number of elements in the input array. Similar to the constructor, it requires iterating through each element.
@@ -87,6 +91,18 @@ export declare class Stack<E = any> extends IterableElementBase<E> {
87
91
  * array is empty, it returns `undefined`.
88
92
  */
89
93
  pop(): E | undefined;
94
+ /**
95
+ * The delete function removes an element from the stack.
96
+ * @param element: E Specify the element to be deleted
97
+ * @return A boolean value indicating whether the element was successfully deleted or not
98
+ */
99
+ delete(element: E): boolean;
100
+ /**
101
+ * The deleteAt function deletes the element at a given index.
102
+ * @param index: number Determine the index of the element to be deleted
103
+ * @return A boolean value
104
+ */
105
+ deleteAt(index: number): boolean;
90
106
  /**
91
107
  * Time Complexity: O(n)
92
108
  * Space Complexity: O(n)
@@ -22,6 +22,10 @@ export class Stack extends IterableElementBase {
22
22
  }
23
23
  }
24
24
  _elements = [];
25
+ /**
26
+ * The elements function returns the elements of this set.
27
+ * @return An array of elements
28
+ */
25
29
  get elements() {
26
30
  return this._elements;
27
31
  }
@@ -104,6 +108,24 @@ export class Stack extends IterableElementBase {
104
108
  return;
105
109
  return this.elements.pop();
106
110
  }
111
+ /**
112
+ * The delete function removes an element from the stack.
113
+ * @param element: E Specify the element to be deleted
114
+ * @return A boolean value indicating whether the element was successfully deleted or not
115
+ */
116
+ delete(element) {
117
+ const index = this.elements.indexOf(element);
118
+ return this.deleteAt(index);
119
+ }
120
+ /**
121
+ * The deleteAt function deletes the element at a given index.
122
+ * @param index: number Determine the index of the element to be deleted
123
+ * @return A boolean value
124
+ */
125
+ deleteAt(index) {
126
+ const spliced = this.elements.splice(index, 1);
127
+ return spliced.length === 1;
128
+ }
107
129
  /**
108
130
  * Time Complexity: O(n)
109
131
  * Space Complexity: O(n)
@@ -30,13 +30,32 @@ export declare class TrieNode {
30
30
  * 10. IP Routing: Used in certain types of IP routing algorithms.
31
31
  * 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
32
32
  */
33
- export declare class Trie extends IterableElementBase<string> {
33
+ export declare class Trie extends IterableElementBase<string, Trie> {
34
+ /**
35
+ * The constructor function for the Trie class.
36
+ * @param words: Iterable string Initialize the trie with a set of words
37
+ * @param options?: TrieOptions Allow the user to pass in options for the trie
38
+ * @return This
39
+ */
34
40
  constructor(words?: Iterable<string>, options?: TrieOptions);
35
41
  protected _size: number;
42
+ /**
43
+ * The size function returns the size of the stack.
44
+ * @return The number of elements in the list
45
+ */
36
46
  get size(): number;
37
47
  protected _caseSensitive: boolean;
48
+ /**
49
+ * The caseSensitive function is a getter that returns the value of the private _caseSensitive property.
50
+ *
51
+ * @return The value of the _casesensitive private variable
52
+ */
38
53
  get caseSensitive(): boolean;
39
54
  protected _root: TrieNode;
55
+ /**
56
+ * The root function returns the root node of the tree.
57
+ * @return The root node
58
+ */
40
59
  get root(): TrieNode;
41
60
  /**
42
61
  * Time Complexity: O(M), where M is the length of the word being added.
@@ -64,6 +83,11 @@ export declare class Trie extends IterableElementBase<string> {
64
83
  * @returns {boolean} True if the word is present in the Trie.
65
84
  */
66
85
  has(word: string): boolean;
86
+ /**
87
+ * The isEmpty function checks if the size of the queue is 0.
88
+ * @return True if the size of the queue is 0
89
+ */
90
+ isEmpty(): boolean;
67
91
  /**
68
92
  * Time Complexity: O(M), where M is the length of the word being deleted.
69
93
  * Space Complexity: O(M) - Due to the recursive DFS approach.
@@ -154,6 +178,19 @@ export declare class Trie extends IterableElementBase<string> {
154
178
  * @returns {string[]} an array of strings.
155
179
  */
156
180
  getWords(prefix?: string, max?: number, isAllWhenEmptyPrefix?: boolean): string[];
181
+ /**
182
+ * Time Complexity: O(n)
183
+ * Space Complexity: O(n)
184
+ */
185
+ /**
186
+ * Time Complexity: O(n)
187
+ * Space Complexity: O(n)
188
+ *
189
+ * The `clone` function returns a new instance of the Trie class with the same values and case
190
+ * sensitivity as the original Trie.
191
+ * @returns A new instance of the Trie class is being returned.
192
+ */
193
+ clone(): Trie;
157
194
  /**
158
195
  * Time Complexity: O(n)
159
196
  * Space Complexity: O(n)
@@ -27,6 +27,12 @@ export class TrieNode {
27
27
  * 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
28
28
  */
29
29
  export class Trie extends IterableElementBase {
30
+ /**
31
+ * The constructor function for the Trie class.
32
+ * @param words: Iterable string Initialize the trie with a set of words
33
+ * @param options?: TrieOptions Allow the user to pass in options for the trie
34
+ * @return This
35
+ */
30
36
  constructor(words = [], options) {
31
37
  super();
32
38
  if (options) {
@@ -40,14 +46,27 @@ export class Trie extends IterableElementBase {
40
46
  }
41
47
  }
42
48
  _size = 0;
49
+ /**
50
+ * The size function returns the size of the stack.
51
+ * @return The number of elements in the list
52
+ */
43
53
  get size() {
44
54
  return this._size;
45
55
  }
46
56
  _caseSensitive = true;
57
+ /**
58
+ * The caseSensitive function is a getter that returns the value of the private _caseSensitive property.
59
+ *
60
+ * @return The value of the _casesensitive private variable
61
+ */
47
62
  get caseSensitive() {
48
63
  return this._caseSensitive;
49
64
  }
50
65
  _root = new TrieNode('');
66
+ /**
67
+ * The root function returns the root node of the tree.
68
+ * @return The root node
69
+ */
51
70
  get root() {
52
71
  return this._root;
53
72
  }
@@ -105,6 +124,13 @@ export class Trie extends IterableElementBase {
105
124
  }
106
125
  return cur.isEnd;
107
126
  }
127
+ /**
128
+ * The isEmpty function checks if the size of the queue is 0.
129
+ * @return True if the size of the queue is 0
130
+ */
131
+ isEmpty() {
132
+ return this.size === 0;
133
+ }
108
134
  /**
109
135
  * Time Complexity: O(M), where M is the length of the word being deleted.
110
136
  * Space Complexity: O(M) - Due to the recursive DFS approach.
@@ -325,6 +351,21 @@ export class Trie extends IterableElementBase {
325
351
  dfs(startNode, prefix);
326
352
  return words;
327
353
  }
354
+ /**
355
+ * Time Complexity: O(n)
356
+ * Space Complexity: O(n)
357
+ */
358
+ /**
359
+ * Time Complexity: O(n)
360
+ * Space Complexity: O(n)
361
+ *
362
+ * The `clone` function returns a new instance of the Trie class with the same values and case
363
+ * sensitivity as the original Trie.
364
+ * @returns A new instance of the Trie class is being returned.
365
+ */
366
+ clone() {
367
+ return new Trie(this.values(), { caseSensitive: this.caseSensitive });
368
+ }
328
369
  /**
329
370
  * Time Complexity: O(n)
330
371
  * Space Complexity: O(n)
@@ -1,7 +1,7 @@
1
1
  import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
2
2
  import { IterationType } from "../../common";
3
3
  export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
- export type BinaryTreeNested<K, V, N extends BinaryTreeNode<K, V, N>> = BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
+ export type BinaryTreeNested<K, V, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
5
  export type BinaryTreeOptions<K> = {
6
6
  iterationType?: IterationType;
7
7
  extractor?: (key: K) => number;