data-structure-typed 1.48.0 → 1.48.1

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 (63) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +16 -16
  3. package/benchmark/report.html +16 -16
  4. package/benchmark/report.json +172 -292
  5. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  6. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +38 -0
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.js +54 -0
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  10. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
  13. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +12 -0
  14. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +16 -0
  15. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  16. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  17. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  18. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  19. package/dist/cjs/data-structures/hash/hash-map.d.ts +173 -16
  20. package/dist/cjs/data-structures/hash/hash-map.js +373 -37
  21. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  22. package/dist/cjs/data-structures/hash/hash-table.js.map +1 -1
  23. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  24. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  25. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  26. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  27. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  28. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  29. package/dist/cjs/data-structures/matrix/matrix2d.js.map +1 -1
  30. package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
  31. package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
  32. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  33. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  34. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  35. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  36. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  37. package/dist/cjs/data-structures/tree/tree.js.map +1 -1
  38. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  39. package/dist/cjs/types/data-structures/hash/hash-map.d.ts +4 -0
  40. package/dist/cjs/utils/utils.js.map +1 -1
  41. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +38 -0
  42. package/dist/mjs/data-structures/binary-tree/binary-tree.js +54 -0
  43. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +12 -0
  44. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +16 -0
  45. package/dist/mjs/data-structures/hash/hash-map.d.ts +173 -16
  46. package/dist/mjs/data-structures/hash/hash-map.js +369 -35
  47. package/dist/mjs/types/data-structures/hash/hash-map.d.ts +4 -0
  48. package/dist/umd/data-structure-typed.js +429 -31
  49. package/dist/umd/data-structure-typed.min.js +2 -2
  50. package/dist/umd/data-structure-typed.min.js.map +1 -1
  51. package/package.json +2 -2
  52. package/src/data-structures/binary-tree/binary-tree.ts +62 -1
  53. package/src/data-structures/binary-tree/tree-multimap.ts +18 -0
  54. package/src/data-structures/hash/hash-map.ts +400 -40
  55. package/src/types/data-structures/hash/hash-map.ts +2 -0
  56. package/test/integration/avl-tree.test.ts +2 -2
  57. package/test/integration/bst.test.ts +21 -25
  58. package/test/performance/data-structures/binary-tree/binary-tree.test.ts +17 -12
  59. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +16 -0
  60. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +16 -1
  61. package/test/unit/data-structures/binary-tree/bst.test.ts +16 -0
  62. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +82 -1
  63. package/test/unit/data-structures/hash/hash-map.test.ts +312 -18
@@ -127,6 +127,7 @@ var dataStructureTyped = (() => {
127
127
  HashTableNode: () => HashTableNode,
128
128
  Heap: () => Heap,
129
129
  IterationType: () => IterationType,
130
+ LinkedHashMap: () => LinkedHashMap,
130
131
  LinkedListQueue: () => LinkedListQueue,
131
132
  MapEdge: () => MapEdge,
132
133
  MapGraph: () => MapGraph,
@@ -517,6 +518,299 @@ var dataStructureTyped = (() => {
517
518
 
518
519
  // src/data-structures/hash/hash-map.ts
519
520
  var HashMap = class _HashMap {
521
+ /**
522
+ * The constructor function initializes a new instance of a class with optional elements and options.
523
+ * @param elements - The `elements` parameter is an iterable containing key-value pairs `[K, V]`. It
524
+ * is optional and defaults to an empty array `[]`. This parameter is used to initialize the map with
525
+ * key-value pairs.
526
+ * @param [options] - The `options` parameter is an optional object that can contain additional
527
+ * configuration options for the constructor. In this case, it has one property:
528
+ */
529
+ constructor(elements = [], options) {
530
+ __publicField(this, "_store", {});
531
+ __publicField(this, "_objMap", /* @__PURE__ */ new Map());
532
+ __publicField(this, "_size", 0);
533
+ __publicField(this, "_hashFn", (key) => String(key));
534
+ if (options) {
535
+ const { hashFn } = options;
536
+ if (hashFn) {
537
+ this._hashFn = hashFn;
538
+ }
539
+ }
540
+ if (elements) {
541
+ this.setMany(elements);
542
+ }
543
+ }
544
+ get size() {
545
+ return this._size;
546
+ }
547
+ isEmpty() {
548
+ return this.size === 0;
549
+ }
550
+ clear() {
551
+ this._store = {};
552
+ this._objMap.clear();
553
+ this._size = 0;
554
+ }
555
+ /**
556
+ * The `set` function adds a key-value pair to a map-like data structure, incrementing the size if
557
+ * the key is not already present.
558
+ * @param {K} key - The key parameter is the key used to identify the value in the data structure. It
559
+ * can be of any type, but if it is an object, it will be stored in a Map, otherwise it will be
560
+ * stored in a regular JavaScript object.
561
+ * @param {V} value - The value parameter represents the value that you want to associate with the
562
+ * key in the data structure.
563
+ */
564
+ set(key, value) {
565
+ if (this._isObjKey(key)) {
566
+ if (!this._objMap.has(key)) {
567
+ this._size++;
568
+ }
569
+ this._objMap.set(key, value);
570
+ } else {
571
+ const strKey = this._getNoObjKey(key);
572
+ if (this._store[strKey] === void 0) {
573
+ this._size++;
574
+ }
575
+ this._store[strKey] = { key, value };
576
+ }
577
+ }
578
+ /**
579
+ * The function "setMany" sets multiple key-value pairs in a map.
580
+ * @param elements - The `elements` parameter is an iterable containing key-value pairs. Each
581
+ * key-value pair is represented as an array with two elements: the key and the value.
582
+ */
583
+ setMany(elements) {
584
+ for (const [key, value] of elements)
585
+ this.set(key, value);
586
+ }
587
+ /**
588
+ * The `get` function retrieves a value from a map based on a given key, either from an object map or
589
+ * a string map.
590
+ * @param {K} key - The `key` parameter is the key used to retrieve a value from the map. It can be
591
+ * of any type, but it should be compatible with the key type used when the map was created.
592
+ * @returns The method `get(key: K)` returns a value of type `V` if the key exists in the `_objMap`
593
+ * or `_store`, otherwise it returns `undefined`.
594
+ */
595
+ get(key) {
596
+ var _a;
597
+ if (this._isObjKey(key)) {
598
+ return this._objMap.get(key);
599
+ } else {
600
+ const strKey = this._getNoObjKey(key);
601
+ return (_a = this._store[strKey]) == null ? void 0 : _a.value;
602
+ }
603
+ }
604
+ /**
605
+ * The `has` function checks if a given key exists in the `_objMap` or `_store` based on whether it
606
+ * is an object key or not.
607
+ * @param {K} key - The parameter "key" is of type K, which means it can be any type.
608
+ * @returns The `has` method is returning a boolean value.
609
+ */
610
+ has(key) {
611
+ if (this._isObjKey(key)) {
612
+ return this._objMap.has(key);
613
+ } else {
614
+ const strKey = this._getNoObjKey(key);
615
+ return strKey in this._store;
616
+ }
617
+ }
618
+ /**
619
+ * The `delete` function removes an element from a map-like data structure based on the provided key.
620
+ * @param {K} key - The `key` parameter is the key of the element that you want to delete from the
621
+ * data structure.
622
+ * @returns The `delete` method returns a boolean value. It returns `true` if the key was
623
+ * successfully deleted from the map, and `false` if the key was not found in the map.
624
+ */
625
+ delete(key) {
626
+ if (this._isObjKey(key)) {
627
+ if (this._objMap.has(key)) {
628
+ this._size--;
629
+ }
630
+ return this._objMap.delete(key);
631
+ } else {
632
+ const strKey = this._getNoObjKey(key);
633
+ if (strKey in this._store) {
634
+ delete this._store[strKey];
635
+ this._size--;
636
+ return true;
637
+ }
638
+ return false;
639
+ }
640
+ }
641
+ /**
642
+ * The function returns an iterator that yields key-value pairs from both an object store and an
643
+ * object map.
644
+ */
645
+ *[Symbol.iterator]() {
646
+ for (const node of Object.values(this._store)) {
647
+ yield [node.key, node.value];
648
+ }
649
+ for (const node of this._objMap) {
650
+ yield node;
651
+ }
652
+ }
653
+ /**
654
+ * The function returns an iterator that yields key-value pairs from the object.
655
+ */
656
+ *entries() {
657
+ for (const item of this) {
658
+ yield item;
659
+ }
660
+ }
661
+ /**
662
+ * The function `keys()` returns an iterator that yields all the keys of the object.
663
+ */
664
+ *keys() {
665
+ for (const [key] of this) {
666
+ yield key;
667
+ }
668
+ }
669
+ *values() {
670
+ for (const [, value] of this) {
671
+ yield value;
672
+ }
673
+ }
674
+ /**
675
+ * The `every` function checks if every element in a HashMap satisfies a given predicate function.
676
+ * @param predicate - The predicate parameter is a function that takes four arguments: value, key,
677
+ * index, and map. It is used to test each element in the map against a condition. If the predicate
678
+ * function returns false for any element, the every() method will return false. If the predicate
679
+ * function returns true for all
680
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
681
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
682
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
683
+ * @returns The method is returning a boolean value. It returns true if the predicate function
684
+ * returns true for every element in the map, and false otherwise.
685
+ */
686
+ every(predicate, thisArg) {
687
+ let index = 0;
688
+ for (const [key, value] of this) {
689
+ if (!predicate.call(thisArg, value, key, index++, this)) {
690
+ return false;
691
+ }
692
+ }
693
+ return true;
694
+ }
695
+ /**
696
+ * The "some" function checks if at least one element in a HashMap satisfies a given predicate.
697
+ * @param predicate - The `predicate` parameter is a function that takes four arguments: `value`,
698
+ * `key`, `index`, and `map`. It is used to determine whether a specific condition is met for a given
699
+ * key-value pair in the `HashMap`.
700
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
701
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
702
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
703
+ * @returns a boolean value. It returns true if the predicate function returns true for any element
704
+ * in the map, and false otherwise.
705
+ */
706
+ some(predicate, thisArg) {
707
+ let index = 0;
708
+ for (const [key, value] of this) {
709
+ if (predicate.call(thisArg, value, key, index++, this)) {
710
+ return true;
711
+ }
712
+ }
713
+ return false;
714
+ }
715
+ /**
716
+ * The `forEach` function iterates over the elements of a HashMap and applies a callback function to
717
+ * each element.
718
+ * @param callbackfn - A function that will be called for each key-value pair in the HashMap. It
719
+ * takes four parameters:
720
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
721
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
722
+ * be passed as the `this` value inside the `callbackfn` function. If `thisArg
723
+ */
724
+ forEach(callbackfn, thisArg) {
725
+ let index = 0;
726
+ for (const [key, value] of this) {
727
+ callbackfn.call(thisArg, value, key, index++, this);
728
+ }
729
+ }
730
+ /**
731
+ * The `map` function in TypeScript creates a new HashMap by applying a callback function to each
732
+ * key-value pair in the original HashMap.
733
+ * @param callbackfn - The callback function that will be called for each key-value pair in the
734
+ * HashMap. It takes four parameters:
735
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
736
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
737
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
738
+ * @returns The `map` method is returning a new `HashMap` object with the transformed values based on
739
+ * the provided callback function.
740
+ */
741
+ map(callbackfn, thisArg) {
742
+ const resultMap = new _HashMap();
743
+ let index = 0;
744
+ for (const [key, value] of this) {
745
+ resultMap.set(key, callbackfn.call(thisArg, value, key, index++, this));
746
+ }
747
+ return resultMap;
748
+ }
749
+ /**
750
+ * The `filter` function creates a new HashMap containing key-value pairs from the original HashMap
751
+ * that satisfy a given predicate function.
752
+ * @param predicate - The predicate parameter is a function that takes four arguments: value, key,
753
+ * index, and map. It is used to determine whether an element should be included in the filtered map
754
+ * or not. The function should return a boolean value - true if the element should be included, and
755
+ * false otherwise.
756
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
757
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
758
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
759
+ * @returns The `filter` method is returning a new `HashMap` object that contains the key-value pairs
760
+ * from the original `HashMap` that pass the provided `predicate` function.
761
+ */
762
+ filter(predicate, thisArg) {
763
+ const filteredMap = new _HashMap();
764
+ let index = 0;
765
+ for (const [key, value] of this) {
766
+ if (predicate.call(thisArg, value, key, index++, this)) {
767
+ filteredMap.set(key, value);
768
+ }
769
+ }
770
+ return filteredMap;
771
+ }
772
+ /**
773
+ * The `reduce` function iterates over the elements of a HashMap and applies a callback function to
774
+ * each element, accumulating a single value.
775
+ * @param callbackfn - The callback function that will be called for each element in the HashMap. It
776
+ * takes five parameters:
777
+ * @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
778
+ * is the value that will be used as the first argument of the callback function when reducing the
779
+ * elements of the map.
780
+ * @returns The `reduce` method is returning the final value of the accumulator after iterating over
781
+ * all the elements in the `HashMap`.
782
+ */
783
+ reduce(callbackfn, initialValue) {
784
+ let accumulator = initialValue;
785
+ let index = 0;
786
+ for (const [key, value] of this) {
787
+ accumulator = callbackfn(accumulator, value, key, index++, this);
788
+ }
789
+ return accumulator;
790
+ }
791
+ print() {
792
+ console.log([...this.entries()]);
793
+ }
794
+ _isObjKey(key) {
795
+ const keyType = typeof key;
796
+ return (keyType === "object" || keyType === "function") && key !== null;
797
+ }
798
+ _getNoObjKey(key) {
799
+ const keyType = typeof key;
800
+ let strKey;
801
+ if (keyType !== "string" && keyType !== "number" && keyType !== "symbol") {
802
+ strKey = this._hashFn(key);
803
+ } else {
804
+ if (keyType === "number") {
805
+ strKey = key;
806
+ } else {
807
+ strKey = key;
808
+ }
809
+ }
810
+ return strKey;
811
+ }
812
+ };
813
+ var LinkedHashMap = class _LinkedHashMap {
520
814
  constructor(elements, options = {
521
815
  hashFn: (key) => String(key),
522
816
  objHashFn: (key) => key
@@ -604,39 +898,65 @@ var dataStructureTyped = (() => {
604
898
  */
605
899
  set(key, value) {
606
900
  let node;
901
+ const isNewKey = !this.has(key);
607
902
  if (isWeakKey(key)) {
608
903
  const hash = this._objHashFn(key);
609
904
  node = this._objMap.get(hash);
610
- if (node) {
611
- node.value = value;
612
- } else {
905
+ if (!node && isNewKey) {
613
906
  node = { key: hash, value, prev: this._tail, next: this._sentinel };
614
907
  this._objMap.set(hash, node);
908
+ } else if (node) {
909
+ node.value = value;
615
910
  }
616
911
  } else {
617
912
  const hash = this._hashFn(key);
618
913
  node = this._noObjMap[hash];
619
- if (node) {
914
+ if (!node && isNewKey) {
915
+ this._noObjMap[hash] = node = { key, value, prev: this._tail, next: this._sentinel };
916
+ } else if (node) {
620
917
  node.value = value;
918
+ }
919
+ }
920
+ if (node && isNewKey) {
921
+ if (this._size === 0) {
922
+ this._head = node;
923
+ this._sentinel.next = node;
621
924
  } else {
622
- this._noObjMap[hash] = node = {
623
- key,
624
- value,
625
- prev: this._tail,
626
- next: this._sentinel
627
- };
925
+ this._tail.next = node;
926
+ node.prev = this._tail;
628
927
  }
928
+ this._tail = node;
929
+ this._sentinel.prev = node;
930
+ this._size++;
629
931
  }
630
- if (this._size === 0) {
631
- this._head = node;
632
- this._sentinel.next = node;
932
+ return this._size;
933
+ }
934
+ has(key) {
935
+ if (isWeakKey(key)) {
936
+ const hash = this._objHashFn(key);
937
+ return this._objMap.has(hash);
633
938
  } else {
634
- this._tail.next = node;
939
+ const hash = this._hashFn(key);
940
+ return hash in this._noObjMap;
941
+ }
942
+ }
943
+ setMany(entries) {
944
+ for (const entry of entries) {
945
+ const [key, value] = entry;
946
+ this.set(key, value);
635
947
  }
636
- this._tail = node;
637
- this._sentinel.prev = node;
638
- this._size++;
639
- return this._size;
948
+ }
949
+ keys() {
950
+ const keys = [];
951
+ for (const [key] of this)
952
+ keys.push(key);
953
+ return keys;
954
+ }
955
+ values() {
956
+ const values = [];
957
+ for (const [, value] of this)
958
+ values.push(value);
959
+ return values;
640
960
  }
641
961
  /**
642
962
  * Time Complexity: O(1)
@@ -751,14 +1071,22 @@ var dataStructureTyped = (() => {
751
1071
  this._size = 0;
752
1072
  this._head = this._tail = this._sentinel.prev = this._sentinel.next = this._sentinel;
753
1073
  }
1074
+ clone() {
1075
+ const cloned = new _LinkedHashMap([], { hashFn: this._hashFn, objHashFn: this._objHashFn });
1076
+ for (const entry of this) {
1077
+ const [key, value] = entry;
1078
+ cloned.set(key, value);
1079
+ }
1080
+ return cloned;
1081
+ }
754
1082
  /**
755
- * Time Complexity: O(n), where n is the number of elements in the HashMap.
1083
+ * Time Complexity: O(n), where n is the number of elements in the LinkedHashMap.
756
1084
  * Space Complexity: O(1)
757
1085
  *
758
- * The `forEach` function iterates over each element in a HashMap and executes a callback function on
1086
+ * The `forEach` function iterates over each element in a LinkedHashMap and executes a callback function on
759
1087
  * each element.
760
1088
  * @param callback - The callback parameter is a function that will be called for each element in the
761
- * HashMap. It takes three arguments:
1089
+ * LinkedHashMap. It takes three arguments:
762
1090
  */
763
1091
  forEach(callback) {
764
1092
  let index = 0;
@@ -769,15 +1097,15 @@ var dataStructureTyped = (() => {
769
1097
  }
770
1098
  }
771
1099
  /**
772
- * The `filter` function takes a predicate function and returns a new HashMap containing only the
1100
+ * The `filter` function takes a predicate function and returns a new LinkedHashMap containing only the
773
1101
  * key-value pairs that satisfy the predicate.
774
1102
  * @param predicate - The `predicate` parameter is a function that takes two arguments: `element` and
775
1103
  * `map`.
776
- * @returns a new HashMap object that contains the key-value pairs from the original HashMap that
1104
+ * @returns a new LinkedHashMap object that contains the key-value pairs from the original LinkedHashMap that
777
1105
  * satisfy the given predicate function.
778
1106
  */
779
1107
  filter(predicate) {
780
- const filteredMap = new _HashMap();
1108
+ const filteredMap = new _LinkedHashMap();
781
1109
  let index = 0;
782
1110
  for (const [key, value] of this) {
783
1111
  if (predicate([key, value], index, this)) {
@@ -788,14 +1116,14 @@ var dataStructureTyped = (() => {
788
1116
  return filteredMap;
789
1117
  }
790
1118
  /**
791
- * The `map` function takes a callback function and returns a new HashMap with the values transformed
1119
+ * The `map` function takes a callback function and returns a new LinkedHashMap with the values transformed
792
1120
  * by the callback.
793
1121
  * @param callback - The `callback` parameter is a function that takes two arguments: `element` and
794
1122
  * `map`.
795
- * @returns a new HashMap object with the values mapped according to the provided callback function.
1123
+ * @returns a new LinkedHashMap object with the values mapped according to the provided callback function.
796
1124
  */
797
1125
  map(callback) {
798
- const mappedMap = new _HashMap();
1126
+ const mappedMap = new _LinkedHashMap();
799
1127
  let index = 0;
800
1128
  for (const [key, value] of this) {
801
1129
  const newValue = callback([key, value], index, this);
@@ -805,16 +1133,16 @@ var dataStructureTyped = (() => {
805
1133
  return mappedMap;
806
1134
  }
807
1135
  /**
808
- * The `reduce` function iterates over the elements of a HashMap and applies a callback function to
1136
+ * The `reduce` function iterates over the elements of a LinkedHashMap and applies a callback function to
809
1137
  * each element, accumulating a single value.
810
1138
  * @param callback - The callback parameter is a function that takes three arguments: accumulator,
811
- * element, and map. It is called for each element in the HashMap and is used to accumulate a single
1139
+ * element, and map. It is called for each element in the LinkedHashMap and is used to accumulate a single
812
1140
  * result.
813
1141
  * @param {A} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
814
1142
  * is the value that will be passed as the first argument to the `callback` function when reducing
815
1143
  * the elements of the map.
816
1144
  * @returns The `reduce` function is returning the final value of the accumulator after iterating
817
- * over all the elements in the HashMap and applying the callback function to each element.
1145
+ * over all the elements in the LinkedHashMap and applying the callback function to each element.
818
1146
  */
819
1147
  reduce(callback, initialValue) {
820
1148
  let accumulator = initialValue;
@@ -826,7 +1154,7 @@ var dataStructureTyped = (() => {
826
1154
  return accumulator;
827
1155
  }
828
1156
  /**
829
- * Time Complexity: O(n), where n is the number of elements in the HashMap.
1157
+ * Time Complexity: O(n), where n is the number of elements in the LinkedHashMap.
830
1158
  * Space Complexity: O(1)
831
1159
  *
832
1160
  * The above function is an iterator that yields key-value pairs from a linked list.
@@ -8218,6 +8546,60 @@ var dataStructureTyped = (() => {
8218
8546
  }
8219
8547
  return ans;
8220
8548
  }
8549
+ /**
8550
+ * Time complexity: O(n)
8551
+ * Space complexity: O(n)
8552
+ */
8553
+ /**
8554
+ * Time complexity: O(n)
8555
+ * Space complexity: O(n)
8556
+ *
8557
+ * The function "keys" returns an array of keys from a given object.
8558
+ * @returns an array of BTNKey objects.
8559
+ */
8560
+ keys() {
8561
+ const keys = [];
8562
+ for (const entry of this) {
8563
+ keys.push(entry[0]);
8564
+ }
8565
+ return keys;
8566
+ }
8567
+ /**
8568
+ * Time complexity: O(n)
8569
+ * Space complexity: O(n)
8570
+ */
8571
+ /**
8572
+ * Time complexity: O(n)
8573
+ * Space complexity: O(n)
8574
+ *
8575
+ * The function "values" returns an array of values from a map-like object.
8576
+ * @returns The `values()` method is returning an array of values (`V`) from the entries in the
8577
+ * object.
8578
+ */
8579
+ values() {
8580
+ const values = [];
8581
+ for (const entry of this) {
8582
+ values.push(entry[1]);
8583
+ }
8584
+ return values;
8585
+ }
8586
+ /**
8587
+ * Time complexity: O(n)
8588
+ * Space complexity: O(n)
8589
+ */
8590
+ /**
8591
+ * Time complexity: O(n)
8592
+ * Space complexity: O(n)
8593
+ *
8594
+ * The `clone` function creates a new tree object and copies all the nodes from the original tree to
8595
+ * the new tree.
8596
+ * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
8597
+ */
8598
+ clone() {
8599
+ const cloned = this.createTree();
8600
+ this.bfs((node) => cloned.add([node.key, node.value]));
8601
+ return cloned;
8602
+ }
8221
8603
  /**
8222
8604
  * Time complexity: O(n)
8223
8605
  * Space complexity: O(1)
@@ -10771,6 +11153,22 @@ var dataStructureTyped = (() => {
10771
11153
  super.clear();
10772
11154
  this._count = 0;
10773
11155
  }
11156
+ /**
11157
+ * Time complexity: O(n)
11158
+ * Space complexity: O(n)
11159
+ */
11160
+ /**
11161
+ * Time complexity: O(n)
11162
+ * Space complexity: O(n)
11163
+ *
11164
+ * The `clone` function creates a deep copy of a tree object.
11165
+ * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
11166
+ */
11167
+ clone() {
11168
+ const cloned = this.createTree();
11169
+ this.bfs((node) => cloned.add([node.key, node.value], node.count));
11170
+ return cloned;
11171
+ }
10774
11172
  /**
10775
11173
  * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
10776
11174
  * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.