linked-list-typed 1.49.6 → 1.49.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +3 -3
  2. package/dist/data-structures/binary-tree/avl-tree.js +5 -5
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +3 -3
  4. package/dist/data-structures/binary-tree/binary-tree.js +11 -13
  5. package/dist/data-structures/binary-tree/bst.d.ts +3 -3
  6. package/dist/data-structures/binary-tree/bst.js +6 -7
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +2 -2
  8. package/dist/data-structures/binary-tree/rb-tree.js +6 -6
  9. package/dist/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  10. package/dist/data-structures/binary-tree/tree-multimap.js +3 -3
  11. package/dist/data-structures/hash/hash-map.d.ts +24 -27
  12. package/dist/data-structures/hash/hash-map.js +35 -35
  13. package/dist/data-structures/hash/index.d.ts +0 -1
  14. package/dist/data-structures/hash/index.js +0 -1
  15. package/dist/data-structures/heap/heap.d.ts +2 -1
  16. package/dist/data-structures/heap/heap.js +13 -13
  17. package/dist/data-structures/heap/max-heap.js +1 -1
  18. package/dist/data-structures/heap/min-heap.js +1 -1
  19. package/dist/data-structures/linked-list/doubly-linked-list.js +1 -1
  20. package/dist/data-structures/linked-list/singly-linked-list.js +1 -3
  21. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -8
  22. package/dist/data-structures/linked-list/skip-linked-list.js +15 -18
  23. package/dist/data-structures/matrix/matrix.d.ts +2 -7
  24. package/dist/data-structures/matrix/matrix.js +0 -7
  25. package/dist/data-structures/priority-queue/max-priority-queue.js +1 -1
  26. package/dist/data-structures/priority-queue/min-priority-queue.js +1 -1
  27. package/dist/data-structures/priority-queue/priority-queue.js +1 -1
  28. package/dist/data-structures/queue/deque.d.ts +2 -11
  29. package/dist/data-structures/queue/deque.js +9 -13
  30. package/dist/data-structures/queue/queue.d.ts +13 -13
  31. package/dist/data-structures/queue/queue.js +29 -25
  32. package/dist/data-structures/stack/stack.js +2 -3
  33. package/dist/data-structures/trie/trie.d.ts +2 -2
  34. package/dist/data-structures/trie/trie.js +9 -5
  35. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -2
  36. package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
  37. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
  38. package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  39. package/dist/types/data-structures/hash/hash-map.d.ts +5 -2
  40. package/dist/types/data-structures/hash/index.d.ts +0 -1
  41. package/dist/types/data-structures/hash/index.js +0 -1
  42. package/dist/types/data-structures/heap/heap.d.ts +1 -1
  43. package/dist/types/data-structures/linked-list/index.d.ts +1 -0
  44. package/dist/types/data-structures/linked-list/index.js +1 -0
  45. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +4 -1
  46. package/dist/types/data-structures/matrix/index.d.ts +1 -0
  47. package/dist/types/data-structures/matrix/index.js +1 -0
  48. package/dist/types/data-structures/matrix/matrix.d.ts +7 -1
  49. package/dist/types/data-structures/queue/deque.d.ts +3 -1
  50. package/dist/types/data-structures/trie/trie.d.ts +3 -1
  51. package/package.json +2 -2
  52. package/src/data-structures/binary-tree/avl-tree.ts +4 -4
  53. package/src/data-structures/binary-tree/binary-tree.ts +10 -14
  54. package/src/data-structures/binary-tree/bst.ts +5 -7
  55. package/src/data-structures/binary-tree/rb-tree.ts +4 -5
  56. package/src/data-structures/binary-tree/tree-multimap.ts +2 -2
  57. package/src/data-structures/hash/hash-map.ts +46 -50
  58. package/src/data-structures/hash/index.ts +0 -1
  59. package/src/data-structures/heap/heap.ts +20 -19
  60. package/src/data-structures/heap/max-heap.ts +1 -1
  61. package/src/data-structures/heap/min-heap.ts +1 -1
  62. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
  63. package/src/data-structures/linked-list/singly-linked-list.ts +2 -5
  64. package/src/data-structures/linked-list/skip-linked-list.ts +15 -16
  65. package/src/data-structures/matrix/matrix.ts +2 -10
  66. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  67. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  68. package/src/data-structures/priority-queue/priority-queue.ts +1 -1
  69. package/src/data-structures/queue/deque.ts +11 -15
  70. package/src/data-structures/queue/queue.ts +29 -28
  71. package/src/data-structures/stack/stack.ts +3 -6
  72. package/src/data-structures/trie/trie.ts +10 -11
  73. package/src/types/data-structures/binary-tree/binary-tree.ts +2 -2
  74. package/src/types/data-structures/binary-tree/bst.ts +1 -1
  75. package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
  76. package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
  77. package/src/types/data-structures/hash/hash-map.ts +6 -2
  78. package/src/types/data-structures/hash/index.ts +0 -1
  79. package/src/types/data-structures/heap/heap.ts +1 -1
  80. package/src/types/data-structures/linked-list/index.ts +1 -0
  81. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -1
  82. package/src/types/data-structures/matrix/index.ts +1 -0
  83. package/src/types/data-structures/matrix/matrix.ts +7 -1
  84. package/src/types/data-structures/queue/deque.ts +1 -1
  85. package/src/types/data-structures/trie/trie.ts +1 -1
  86. package/dist/data-structures/hash/hash-table.d.ts +0 -108
  87. package/dist/data-structures/hash/hash-table.js +0 -281
  88. package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
  89. package/dist/types/data-structures/hash/hash-table.js +0 -2
  90. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -1
  91. package/dist/types/data-structures/matrix/matrix2d.js +0 -2
  92. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -1
  93. package/dist/types/data-structures/matrix/vector2d.js +0 -2
  94. package/src/data-structures/hash/hash-table.ts +0 -318
  95. package/src/types/data-structures/hash/hash-table.ts +0 -1
  96. package/src/types/data-structures/matrix/matrix2d.ts +0 -1
  97. package/src/types/data-structures/matrix/vector2d.ts +0 -1
@@ -23,15 +23,15 @@ export declare class AVLTreeNode<K = any, V = any, N extends AVLTreeNode<K, V, N
23
23
  */
24
24
  export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, TREE extends AVLTree<K, V, N, TREE> = AVLTree<K, V, N, AVLTreeNested<K, V, N>>> extends BST<K, V, N, TREE> implements IBinaryTree<K, V, N, TREE> {
25
25
  /**
26
- * The constructor function initializes an AVLTree object with optional nodes and options.
27
- * @param [nodes] - The `nodes` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
26
+ * The constructor function initializes an AVLTree object with optional keysOrNodesOrEntries and options.
27
+ * @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
28
28
  * objects. It represents a collection of nodes that will be added to the AVL tree during
29
29
  * initialization.
30
30
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
31
31
  * behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
32
32
  * provide only a subset of the properties defined in the `AVLTreeOptions` interface.
33
33
  */
34
- constructor(nodes?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: Partial<AVLTreeOptions<K>>);
34
+ constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: AVLTreeOptions<K>);
35
35
  /**
36
36
  * The function creates a new AVL tree node with the specified key and value.
37
37
  * @param {K} key - The key parameter is the key value that will be associated with
@@ -27,18 +27,18 @@ exports.AVLTreeNode = AVLTreeNode;
27
27
  */
28
28
  class AVLTree extends bst_1.BST {
29
29
  /**
30
- * The constructor function initializes an AVLTree object with optional nodes and options.
31
- * @param [nodes] - The `nodes` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
30
+ * The constructor function initializes an AVLTree object with optional keysOrNodesOrEntries and options.
31
+ * @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
32
32
  * objects. It represents a collection of nodes that will be added to the AVL tree during
33
33
  * initialization.
34
34
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
35
35
  * behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
36
36
  * provide only a subset of the properties defined in the `AVLTreeOptions` interface.
37
37
  */
38
- constructor(nodes, options) {
38
+ constructor(keysOrNodesOrEntries = [], options) {
39
39
  super([], options);
40
- if (nodes)
41
- super.addMany(nodes);
40
+ if (keysOrNodesOrEntries)
41
+ super.addMany(keysOrNodesOrEntries);
42
42
  }
43
43
  /**
44
44
  * The function creates a new AVL tree node with the specified key and value.
@@ -41,15 +41,15 @@ export declare class BinaryTreeNode<K = any, V = any, N extends BinaryTreeNode<K
41
41
  export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V, N> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, N, TREE> = BinaryTree<K, V, N, BinaryTreeNested<K, V, N>>> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, N, TREE> {
42
42
  iterationType: IterationType;
43
43
  /**
44
- * The constructor function initializes a binary tree object with optional nodes and options.
45
- * @param [nodes] - An optional iterable of KeyOrNodeOrEntry objects. These objects represent the
44
+ * The constructor function initializes a binary tree object with optional keysOrNodesOrEntries and options.
45
+ * @param [keysOrNodesOrEntries] - An optional iterable of KeyOrNodeOrEntry objects. These objects represent the
46
46
  * nodes to be added to the binary tree.
47
47
  * @param [options] - The `options` parameter is an optional object that can contain additional
48
48
  * configuration options for the binary tree. In this case, it is of type
49
49
  * `Partial<BinaryTreeOptions>`, which means that not all properties of `BinaryTreeOptions` are
50
50
  * required.
51
51
  */
52
- constructor(nodes?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: Partial<BinaryTreeOptions<K>>);
52
+ constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: BinaryTreeOptions<K>);
53
53
  protected _extractor: (key: K) => number;
54
54
  get extractor(): (key: K) => number;
55
55
  protected _root?: N | null;
@@ -68,31 +68,29 @@ exports.BinaryTreeNode = BinaryTreeNode;
68
68
  */
69
69
  class BinaryTree extends base_1.IterableEntryBase {
70
70
  /**
71
- * The constructor function initializes a binary tree object with optional nodes and options.
72
- * @param [nodes] - An optional iterable of KeyOrNodeOrEntry objects. These objects represent the
71
+ * The constructor function initializes a binary tree object with optional keysOrNodesOrEntries and options.
72
+ * @param [keysOrNodesOrEntries] - An optional iterable of KeyOrNodeOrEntry objects. These objects represent the
73
73
  * nodes to be added to the binary tree.
74
74
  * @param [options] - The `options` parameter is an optional object that can contain additional
75
75
  * configuration options for the binary tree. In this case, it is of type
76
76
  * `Partial<BinaryTreeOptions>`, which means that not all properties of `BinaryTreeOptions` are
77
77
  * required.
78
78
  */
79
- constructor(nodes, options) {
79
+ constructor(keysOrNodesOrEntries = [], options) {
80
80
  super();
81
81
  this.iterationType = types_1.IterationType.ITERATIVE;
82
82
  this._extractor = (key) => Number(key);
83
83
  this._defaultOneParamCallback = (node) => (node ? node.key : undefined);
84
84
  if (options) {
85
85
  const { iterationType, extractor } = options;
86
- if (iterationType) {
86
+ if (iterationType)
87
87
  this.iterationType = iterationType;
88
- }
89
- if (extractor) {
88
+ if (extractor)
90
89
  this._extractor = extractor;
91
- }
92
90
  }
93
91
  this._size = 0;
94
- if (nodes)
95
- this.addMany(nodes);
92
+ if (keysOrNodesOrEntries)
93
+ this.addMany(keysOrNodesOrEntries);
96
94
  }
97
95
  get extractor() {
98
96
  return this._extractor;
@@ -1207,9 +1205,9 @@ class BinaryTree extends base_1.IterableEntryBase {
1207
1205
  queue.push(current.right);
1208
1206
  }
1209
1207
  else {
1210
- if (current.left)
1208
+ if (this.isRealNode(current.left))
1211
1209
  queue.push(current.left);
1212
- if (current.right)
1210
+ if (this.isRealNode(current.right))
1213
1211
  queue.push(current.right);
1214
1212
  }
1215
1213
  traverse(level + 1);
@@ -1230,9 +1228,9 @@ class BinaryTree extends base_1.IterableEntryBase {
1230
1228
  queue.push(current.right);
1231
1229
  }
1232
1230
  else {
1233
- if (current.left)
1231
+ if (this.isRealNode(current.left))
1234
1232
  queue.push(current.left);
1235
- if (current.right)
1233
+ if (this.isRealNode(current.right))
1236
1234
  queue.push(current.right);
1237
1235
  }
1238
1236
  }
@@ -45,13 +45,13 @@ export declare class BSTNode<K = any, V = any, N extends BSTNode<K, V, N> = BSTN
45
45
  export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<K, V, BSTNodeNested<K, V>>, TREE extends BST<K, V, N, TREE> = BST<K, V, N, BSTNested<K, V, N>>> extends BinaryTree<K, V, N, TREE> implements IBinaryTree<K, V, N, TREE> {
46
46
  /**
47
47
  * This is the constructor function for a binary search tree class in TypeScript, which initializes
48
- * the tree with optional nodes and options.
49
- * @param [nodes] - An optional iterable of KeyOrNodeOrEntry objects that will be added to the
48
+ * the tree with optional keysOrNodesOrEntries and options.
49
+ * @param [keysOrNodesOrEntries] - An optional iterable of KeyOrNodeOrEntry objects that will be added to the
50
50
  * binary search tree.
51
51
  * @param [options] - The `options` parameter is an optional object that can contain additional
52
52
  * configuration options for the binary search tree. It can have the following properties:
53
53
  */
54
- constructor(nodes?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: Partial<BSTOptions<K>>);
54
+ constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: BSTOptions<K>);
55
55
  protected _root?: N;
56
56
  get root(): N | undefined;
57
57
  protected _variant: BSTVariant;
@@ -57,24 +57,23 @@ exports.BSTNode = BSTNode;
57
57
  class BST extends binary_tree_1.BinaryTree {
58
58
  /**
59
59
  * This is the constructor function for a binary search tree class in TypeScript, which initializes
60
- * the tree with optional nodes and options.
61
- * @param [nodes] - An optional iterable of KeyOrNodeOrEntry objects that will be added to the
60
+ * the tree with optional keysOrNodesOrEntries and options.
61
+ * @param [keysOrNodesOrEntries] - An optional iterable of KeyOrNodeOrEntry objects that will be added to the
62
62
  * binary search tree.
63
63
  * @param [options] - The `options` parameter is an optional object that can contain additional
64
64
  * configuration options for the binary search tree. It can have the following properties:
65
65
  */
66
- constructor(nodes, options) {
66
+ constructor(keysOrNodesOrEntries = [], options) {
67
67
  super([], options);
68
68
  this._variant = types_1.BSTVariant.STANDARD;
69
69
  if (options) {
70
70
  const { variant } = options;
71
- if (variant) {
71
+ if (variant)
72
72
  this._variant = variant;
73
- }
74
73
  }
75
74
  this._root = undefined;
76
- if (nodes)
77
- this.addMany(nodes);
75
+ if (keysOrNodesOrEntries)
76
+ this.addMany(keysOrNodesOrEntries);
78
77
  }
79
78
  get root() {
80
79
  return this._root;
@@ -24,7 +24,7 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
24
24
  /**
25
25
  * This is the constructor function for a Red-Black Tree data structure in TypeScript, which
26
26
  * initializes the tree with optional nodes and options.
27
- * @param [nodes] - The `nodes` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
27
+ * @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
28
28
  * objects. It represents the initial nodes that will be added to the RBTree during its
29
29
  * construction. If this parameter is provided, the `addMany` method is called to add all the
30
30
  * nodes to the
@@ -32,7 +32,7 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
32
32
  * behavior of the RBTree. It is of type `Partial<RBTreeOptions>`, which means that you can provide
33
33
  * only a subset of the properties defined in the `RBTreeOptions` interface.
34
34
  */
35
- constructor(nodes?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: Partial<RBTreeOptions<K>>);
35
+ constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: RBTreeOptions<K>);
36
36
  protected _root: N;
37
37
  get root(): N;
38
38
  protected _size: number;
@@ -28,7 +28,7 @@ class RedBlackTree extends bst_1.BST {
28
28
  /**
29
29
  * This is the constructor function for a Red-Black Tree data structure in TypeScript, which
30
30
  * initializes the tree with optional nodes and options.
31
- * @param [nodes] - The `nodes` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
31
+ * @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
32
32
  * objects. It represents the initial nodes that will be added to the RBTree during its
33
33
  * construction. If this parameter is provided, the `addMany` method is called to add all the
34
34
  * nodes to the
@@ -36,13 +36,13 @@ class RedBlackTree extends bst_1.BST {
36
36
  * behavior of the RBTree. It is of type `Partial<RBTreeOptions>`, which means that you can provide
37
37
  * only a subset of the properties defined in the `RBTreeOptions` interface.
38
38
  */
39
- constructor(nodes, options) {
39
+ constructor(keysOrNodesOrEntries = [], options) {
40
40
  super([], options);
41
41
  this.Sentinel = new RedBlackTreeNode(NaN);
42
42
  this._size = 0;
43
43
  this._root = this.Sentinel;
44
- if (nodes)
45
- super.addMany(nodes);
44
+ if (keysOrNodesOrEntries)
45
+ super.addMany(keysOrNodesOrEntries);
46
46
  }
47
47
  get root() {
48
48
  return this._root;
@@ -73,7 +73,7 @@ class RedBlackTree extends bst_1.BST {
73
73
  * @returns a new instance of a RedBlackTree object.
74
74
  */
75
75
  createTree(options) {
76
- return new RedBlackTree([], Object.assign({ iterationType: this.iterationType, variant: this.variant }, options));
76
+ return new RedBlackTree([], Object.assign({ iterationType: this.iterationType }, options));
77
77
  }
78
78
  /**
79
79
  * The function `exemplarToNode` takes an keyOrNodeOrEntry and converts it into a node object if possible.
@@ -273,9 +273,9 @@ class RedBlackTree extends bst_1.BST {
273
273
  this._fixDelete(x);
274
274
  }
275
275
  this._size--;
276
+ ans.push({ deleted: z, needBalanced: undefined });
276
277
  };
277
278
  helper(this.root);
278
- // TODO
279
279
  return ans;
280
280
  }
281
281
  /**
@@ -27,7 +27,7 @@ export declare class TreeMultimapNode<K = any, V = any, N extends TreeMultimapNo
27
27
  * The only distinction between a TreeMultimap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
28
28
  */
29
29
  export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K, V, N> = TreeMultimapNode<K, V, TreeMultimapNodeNested<K, V>>, TREE extends TreeMultimap<K, V, N, TREE> = TreeMultimap<K, V, N, TreeMultimapNested<K, V, N>>> extends AVLTree<K, V, N, TREE> implements IBinaryTree<K, V, N, TREE> {
30
- constructor(nodes?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: Partial<TreeMultimapOptions<K>>);
30
+ constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: TreeMultimapOptions<K>);
31
31
  private _count;
32
32
  get count(): number;
33
33
  /**
@@ -24,11 +24,11 @@ exports.TreeMultimapNode = TreeMultimapNode;
24
24
  * The only distinction between a TreeMultimap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
25
25
  */
26
26
  class TreeMultimap extends avl_tree_1.AVLTree {
27
- constructor(nodes, options) {
27
+ constructor(keysOrNodesOrEntries = [], options) {
28
28
  super([], options);
29
29
  this._count = 0;
30
- if (nodes)
31
- this.addMany(nodes);
30
+ if (keysOrNodesOrEntries)
31
+ this.addMany(keysOrNodesOrEntries);
32
32
  }
33
33
  // TODO the _count is not accurate after nodes count modified
34
34
  get count() {
@@ -5,13 +5,13 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { EntryCallback, HashMapLinkedNode, HashMapOptions, HashMapStoreItem } from '../../types';
8
+ import type { EntryCallback, HashMapLinkedNode, HashMapOptions, HashMapStoreItem, LinkedHashMapOptions } from '../../types';
9
9
  import { IterableEntryBase } from '../base';
10
10
  /**
11
11
  * 1. Key-Value Pair Storage: HashMap stores key-value pairs. Each key maps to a value.
12
- * 2. Fast Lookup: It's used when you need to quickly find, insert, or delete elements based on a key.
12
+ * 2. Fast Lookup: It's used when you need to quickly find, insert, or delete entries based on a key.
13
13
  * 3. Unique Keys: Keys are unique. If you try to insert another entry with the same key, the old entry will be replaced by the new one.
14
- * 4. Unordered Collection: HashMap does not guarantee the order of elements, and the order may change over time.
14
+ * 4. Unordered Collection: HashMap does not guarantee the order of entries, and the order may change over time.
15
15
  */
16
16
  export declare class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
17
17
  protected _store: {
@@ -19,16 +19,14 @@ export declare class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
19
19
  };
20
20
  protected _objMap: Map<object, V>;
21
21
  /**
22
- * The constructor function initializes a new instance of a class with optional elements and options.
23
- * @param elements - The `elements` parameter is an iterable containing key-value pairs `[K, V]`. It
22
+ * The constructor function initializes a new instance of a class with optional entries and options.
23
+ * @param entries - The `entries` parameter is an iterable containing key-value pairs `[K, V]`. It
24
24
  * is optional and defaults to an empty array `[]`. This parameter is used to initialize the map with
25
25
  * key-value pairs.
26
26
  * @param [options] - The `options` parameter is an optional object that can contain additional
27
27
  * configuration options for the constructor. In this case, it has one property:
28
28
  */
29
- constructor(elements?: Iterable<[K, V]>, options?: {
30
- hashFn: (key: K) => string;
31
- });
29
+ constructor(entries?: Iterable<[K, V]>, options?: HashMapOptions<K>);
32
30
  protected _size: number;
33
31
  get size(): number;
34
32
  isEmpty(): boolean;
@@ -45,10 +43,10 @@ export declare class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
45
43
  set(key: K, value: V): boolean;
46
44
  /**
47
45
  * The function "setMany" sets multiple key-value pairs in a map.
48
- * @param elements - The `elements` parameter is an iterable containing key-value pairs. Each
49
- * key-value pair is represented as an array with two elements: the key and the value.
46
+ * @param entries - The `entries` parameter is an iterable containing key-value pairs. Each
47
+ * key-value pair is represented as an array with two entries: the key and the value.
50
48
  */
51
- setMany(elements: Iterable<[K, V]>): boolean[];
49
+ setMany(entries: Iterable<[K, V]>): boolean[];
52
50
  /**
53
51
  * The `get` function retrieves a value from a map based on a given key, either from an object map or
54
52
  * a string map.
@@ -113,7 +111,6 @@ export declare class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
113
111
  * from the original `HashMap` that pass the provided `predicate` function.
114
112
  */
115
113
  filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): HashMap<K, V>;
116
- print(): void;
117
114
  put(key: K, value: V): boolean;
118
115
  /**
119
116
  * The function returns an iterator that yields key-value pairs from both an object store and an
@@ -125,8 +122,8 @@ export declare class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
125
122
  protected _getNoObjKey(key: K): string;
126
123
  }
127
124
  /**
128
- * 1. Maintaining the Order of Element Insertion: Unlike HashMap, LinkedHashMap maintains the order in which elements are inserted. Therefore, when you traverse it, elements will be returned in the order they were inserted into the map.
129
- * 2. Based on Hash Table and Linked List: It combines the structures of a hash table and a linked list, using the hash table to ensure fast access, while maintaining the order of elements through the linked list.
125
+ * 1. Maintaining the Order of Element Insertion: Unlike HashMap, LinkedHashMap maintains the order in which entries are inserted. Therefore, when you traverse it, entries will be returned in the order they were inserted into the map.
126
+ * 2. Based on Hash Table and Linked List: It combines the structures of a hash table and a linked list, using the hash table to ensure fast access, while maintaining the order of entries through the linked list.
130
127
  * 3. Time Complexity: Similar to HashMap, LinkedHashMap offers constant-time performance for get and put operations in most cases.
131
128
  */
132
129
  export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K, V> {
@@ -135,9 +132,7 @@ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K
135
132
  protected _head: HashMapLinkedNode<K, V | undefined>;
136
133
  protected _tail: HashMapLinkedNode<K, V | undefined>;
137
134
  protected readonly _sentinel: HashMapLinkedNode<K, V | undefined>;
138
- protected _hashFn: (key: K) => string;
139
- protected _objHashFn: (key: K) => object;
140
- constructor(elements?: Iterable<[K, V]>, options?: HashMapOptions<K>);
135
+ constructor(entries?: Iterable<[K, V]>, options?: LinkedHashMapOptions<K>);
141
136
  protected _size: number;
142
137
  get size(): number;
143
138
  /**
@@ -242,14 +237,10 @@ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K
242
237
  * Time Complexity: O(1)
243
238
  * Space Complexity: O(1)
244
239
  *
245
- * The `clear` function clears all the elements in a data structure and resets its properties.
240
+ * The `clear` function clears all the entries in a data structure and resets its properties.
246
241
  */
247
242
  clear(): void;
248
243
  clone(): LinkedHashMap<K, V>;
249
- /**
250
- * Time Complexity: O(n)
251
- * Space Complexity: O(n)
252
- */
253
244
  /**
254
245
  * Time Complexity: O(n)
255
246
  * Space Complexity: O(n)
@@ -266,10 +257,6 @@ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K
266
257
  * `LinkedHashMap` object that satisfy the given predicate function.
267
258
  */
268
259
  filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): LinkedHashMap<K, V>;
269
- /**
270
- * Time Complexity: O(n)
271
- * Space Complexity: O(n)
272
- */
273
260
  /**
274
261
  * Time Complexity: O(n)
275
262
  * Space Complexity: O(n)
@@ -288,9 +275,19 @@ export declare class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K
288
275
  * function.
289
276
  */
290
277
  map<NV>(callback: EntryCallback<K, V, NV>, thisArg?: any): LinkedHashMap<K, NV>;
278
+ /**
279
+ * Time Complexity: O(n)
280
+ * Space Complexity: O(n)
281
+ */
291
282
  put(key: K, value: V): boolean;
292
283
  /**
293
- * Time Complexity: O(n), where n is the number of elements in the LinkedHashMap.
284
+ * Time Complexity: O(n)
285
+ * Space Complexity: O(n)
286
+ */
287
+ protected _hashFn: (key: K) => string;
288
+ protected _objHashFn: (key: K) => object;
289
+ /**
290
+ * Time Complexity: O(n), where n is the number of entries in the LinkedHashMap.
294
291
  * Space Complexity: O(1)
295
292
  *
296
293
  * The above function is an iterator that yields key-value pairs from a linked list.
@@ -5,20 +5,20 @@ const base_1 = require("../base");
5
5
  const utils_1 = require("../../utils");
6
6
  /**
7
7
  * 1. Key-Value Pair Storage: HashMap stores key-value pairs. Each key maps to a value.
8
- * 2. Fast Lookup: It's used when you need to quickly find, insert, or delete elements based on a key.
8
+ * 2. Fast Lookup: It's used when you need to quickly find, insert, or delete entries based on a key.
9
9
  * 3. Unique Keys: Keys are unique. If you try to insert another entry with the same key, the old entry will be replaced by the new one.
10
- * 4. Unordered Collection: HashMap does not guarantee the order of elements, and the order may change over time.
10
+ * 4. Unordered Collection: HashMap does not guarantee the order of entries, and the order may change over time.
11
11
  */
12
12
  class HashMap extends base_1.IterableEntryBase {
13
13
  /**
14
- * The constructor function initializes a new instance of a class with optional elements and options.
15
- * @param elements - The `elements` parameter is an iterable containing key-value pairs `[K, V]`. It
14
+ * The constructor function initializes a new instance of a class with optional entries and options.
15
+ * @param entries - The `entries` parameter is an iterable containing key-value pairs `[K, V]`. It
16
16
  * is optional and defaults to an empty array `[]`. This parameter is used to initialize the map with
17
17
  * key-value pairs.
18
18
  * @param [options] - The `options` parameter is an optional object that can contain additional
19
19
  * configuration options for the constructor. In this case, it has one property:
20
20
  */
21
- constructor(elements = [], options) {
21
+ constructor(entries = [], options) {
22
22
  super();
23
23
  this._store = {};
24
24
  this._objMap = new Map();
@@ -30,8 +30,8 @@ class HashMap extends base_1.IterableEntryBase {
30
30
  this._hashFn = hashFn;
31
31
  }
32
32
  }
33
- if (elements) {
34
- this.setMany(elements);
33
+ if (entries) {
34
+ this.setMany(entries);
35
35
  }
36
36
  }
37
37
  get size() {
@@ -72,12 +72,12 @@ class HashMap extends base_1.IterableEntryBase {
72
72
  }
73
73
  /**
74
74
  * The function "setMany" sets multiple key-value pairs in a map.
75
- * @param elements - The `elements` parameter is an iterable containing key-value pairs. Each
76
- * key-value pair is represented as an array with two elements: the key and the value.
75
+ * @param entries - The `entries` parameter is an iterable containing key-value pairs. Each
76
+ * key-value pair is represented as an array with two entries: the key and the value.
77
77
  */
78
- setMany(elements) {
78
+ setMany(entries) {
79
79
  const results = [];
80
- for (const [key, value] of elements)
80
+ for (const [key, value] of entries)
81
81
  results.push(this.set(key, value));
82
82
  return results;
83
83
  }
@@ -194,9 +194,6 @@ class HashMap extends base_1.IterableEntryBase {
194
194
  }
195
195
  return filteredMap;
196
196
  }
197
- print() {
198
- console.log([...this.entries()]);
199
- }
200
197
  put(key, value) {
201
198
  return this.set(key, value);
202
199
  }
@@ -236,26 +233,33 @@ class HashMap extends base_1.IterableEntryBase {
236
233
  }
237
234
  exports.HashMap = HashMap;
238
235
  /**
239
- * 1. Maintaining the Order of Element Insertion: Unlike HashMap, LinkedHashMap maintains the order in which elements are inserted. Therefore, when you traverse it, elements will be returned in the order they were inserted into the map.
240
- * 2. Based on Hash Table and Linked List: It combines the structures of a hash table and a linked list, using the hash table to ensure fast access, while maintaining the order of elements through the linked list.
236
+ * 1. Maintaining the Order of Element Insertion: Unlike HashMap, LinkedHashMap maintains the order in which entries are inserted. Therefore, when you traverse it, entries will be returned in the order they were inserted into the map.
237
+ * 2. Based on Hash Table and Linked List: It combines the structures of a hash table and a linked list, using the hash table to ensure fast access, while maintaining the order of entries through the linked list.
241
238
  * 3. Time Complexity: Similar to HashMap, LinkedHashMap offers constant-time performance for get and put operations in most cases.
242
239
  */
243
240
  class LinkedHashMap extends base_1.IterableEntryBase {
244
- constructor(elements, options = {
245
- hashFn: (key) => String(key),
246
- objHashFn: (key) => key
247
- }) {
241
+ constructor(entries, options) {
248
242
  super();
249
243
  this._noObjMap = {};
250
244
  this._objMap = new WeakMap();
251
245
  this._size = 0;
246
+ /**
247
+ * Time Complexity: O(n)
248
+ * Space Complexity: O(n)
249
+ */
250
+ this._hashFn = (key) => String(key);
251
+ this._objHashFn = (key) => key;
252
252
  this._sentinel = {};
253
253
  this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
254
- const { hashFn, objHashFn } = options;
255
- this._hashFn = hashFn;
256
- this._objHashFn = objHashFn;
257
- if (elements) {
258
- for (const el of elements) {
254
+ if (options) {
255
+ const { hashFn, objHashFn } = options;
256
+ if (hashFn)
257
+ this._hashFn = hashFn;
258
+ if (objHashFn)
259
+ this._objHashFn = objHashFn;
260
+ }
261
+ if (entries) {
262
+ for (const el of entries) {
259
263
  this.set(el[0], el[1]);
260
264
  }
261
265
  }
@@ -495,7 +499,7 @@ class LinkedHashMap extends base_1.IterableEntryBase {
495
499
  * Time Complexity: O(1)
496
500
  * Space Complexity: O(1)
497
501
  *
498
- * The `clear` function clears all the elements in a data structure and resets its properties.
502
+ * The `clear` function clears all the entries in a data structure and resets its properties.
499
503
  */
500
504
  clear() {
501
505
  this._noObjMap = {};
@@ -510,10 +514,6 @@ class LinkedHashMap extends base_1.IterableEntryBase {
510
514
  }
511
515
  return cloned;
512
516
  }
513
- /**
514
- * Time Complexity: O(n)
515
- * Space Complexity: O(n)
516
- */
517
517
  /**
518
518
  * Time Complexity: O(n)
519
519
  * Space Complexity: O(n)
@@ -540,10 +540,6 @@ class LinkedHashMap extends base_1.IterableEntryBase {
540
540
  }
541
541
  return filteredMap;
542
542
  }
543
- /**
544
- * Time Complexity: O(n)
545
- * Space Complexity: O(n)
546
- */
547
543
  /**
548
544
  * Time Complexity: O(n)
549
545
  * Space Complexity: O(n)
@@ -571,11 +567,15 @@ class LinkedHashMap extends base_1.IterableEntryBase {
571
567
  }
572
568
  return mappedMap;
573
569
  }
570
+ /**
571
+ * Time Complexity: O(n)
572
+ * Space Complexity: O(n)
573
+ */
574
574
  put(key, value) {
575
575
  return this.set(key, value);
576
576
  }
577
577
  /**
578
- * Time Complexity: O(n), where n is the number of elements in the LinkedHashMap.
578
+ * Time Complexity: O(n), where n is the number of entries in the LinkedHashMap.
579
579
  * Space Complexity: O(1)
580
580
  *
581
581
  * The above function is an iterator that yields key-value pairs from a linked list.
@@ -1,2 +1 @@
1
- export * from './hash-table';
2
1
  export * from './hash-map';
@@ -14,5 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./hash-table"), exports);
18
17
  __exportStar(require("./hash-map"), exports);
@@ -19,8 +19,9 @@ import { IterableElementBase } from '../base';
19
19
  * 8. Graph Algorithms: Such as Dijkstra's shortest path algorithm and Prim's minimum spanning tree algorithm, which use heaps to improve performance.
20
20
  */
21
21
  export declare class Heap<E = any> extends IterableElementBase<E> {
22
- options: HeapOptions<E>;
23
22
  constructor(elements?: Iterable<E>, options?: HeapOptions<E>);
23
+ protected _comparator: (a: E, b: E) => number;
24
+ get comparator(): (a: E, b: E) => number;
24
25
  protected _elements: E[];
25
26
  get elements(): E[];
26
27
  /**
@@ -21,10 +21,9 @@ const base_1 = require("../base");
21
21
  * 8. Graph Algorithms: Such as Dijkstra's shortest path algorithm and Prim's minimum spanning tree algorithm, which use heaps to improve performance.
22
22
  */
23
23
  class Heap extends base_1.IterableElementBase {
24
- constructor(elements, options) {
24
+ constructor(elements = [], options) {
25
25
  super();
26
- this._elements = [];
27
- const defaultComparator = (a, b) => {
26
+ this._comparator = (a, b) => {
28
27
  if (!(typeof a === 'number' && typeof b === 'number')) {
29
28
  throw new Error('The a, b params of compare function must be number');
30
29
  }
@@ -32,13 +31,11 @@ class Heap extends base_1.IterableElementBase {
32
31
  return a - b;
33
32
  }
34
33
  };
34
+ this._elements = [];
35
35
  if (options) {
36
- this.options = options;
37
- }
38
- else {
39
- this.options = {
40
- comparator: defaultComparator
41
- };
36
+ const { comparator } = options;
37
+ if (comparator)
38
+ this._comparator = comparator;
42
39
  }
43
40
  if (elements) {
44
41
  for (const el of elements) {
@@ -47,6 +44,9 @@ class Heap extends base_1.IterableElementBase {
47
44
  // this.fix();
48
45
  }
49
46
  }
47
+ get comparator() {
48
+ return this._comparator;
49
+ }
50
50
  get elements() {
51
51
  return this._elements;
52
52
  }
@@ -256,7 +256,7 @@ class Heap extends base_1.IterableElementBase {
256
256
  * @returns A new Heap instance containing the same elements.
257
257
  */
258
258
  clone() {
259
- const clonedHeap = new Heap([], this.options);
259
+ const clonedHeap = new Heap([], { comparator: this.comparator });
260
260
  clonedHeap._elements = [...this.elements];
261
261
  return clonedHeap;
262
262
  }
@@ -382,7 +382,7 @@ class Heap extends base_1.IterableElementBase {
382
382
  while (index > 0) {
383
383
  const parent = (index - 1) >> 1;
384
384
  const parentItem = this.elements[parent];
385
- if (this.options.comparator(parentItem, element) <= 0)
385
+ if (this.comparator(parentItem, element) <= 0)
386
386
  break;
387
387
  this.elements[index] = parentItem;
388
388
  index = parent;
@@ -404,11 +404,11 @@ class Heap extends base_1.IterableElementBase {
404
404
  let left = (index << 1) | 1;
405
405
  const right = left + 1;
406
406
  let minItem = this.elements[left];
407
- if (right < this.elements.length && this.options.comparator(minItem, this.elements[right]) > 0) {
407
+ if (right < this.elements.length && this.comparator(minItem, this.elements[right]) > 0) {
408
408
  left = right;
409
409
  minItem = this.elements[right];
410
410
  }
411
- if (this.options.comparator(minItem, element) >= 0)
411
+ if (this.comparator(minItem, element) >= 0)
412
412
  break;
413
413
  this.elements[index] = minItem;
414
414
  index = left;