linked-list-typed 1.38.8 → 1.38.9

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.
@@ -77,8 +77,9 @@ export declare class Trie {
77
77
  * @param {string} prefix - The `prefix` parameter is a string that represents the prefix that we want to search for in the
78
78
  * trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
79
79
  * @param {number} max - The max count of words will be found
80
+ * @param isAllWhenEmptyPrefix - If true, when the prefix provided as '', returns all the words in the trie.
80
81
  * @returns {string[]} an array of strings.
81
82
  */
82
- getWords(prefix?: string, max?: number): string[];
83
+ getWords(prefix?: string, max?: number, isAllWhenEmptyPrefix?: boolean): string[];
83
84
  private _caseProcess;
84
85
  }
@@ -226,9 +226,10 @@ class Trie {
226
226
  * @param {string} prefix - The `prefix` parameter is a string that represents the prefix that we want to search for in the
227
227
  * trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
228
228
  * @param {number} max - The max count of words will be found
229
+ * @param isAllWhenEmptyPrefix - If true, when the prefix provided as '', returns all the words in the trie.
229
230
  * @returns {string[]} an array of strings.
230
231
  */
231
- getWords(prefix = '', max = Number.MAX_SAFE_INTEGER) {
232
+ getWords(prefix = '', max = Number.MAX_SAFE_INTEGER, isAllWhenEmptyPrefix = false) {
232
233
  prefix = this._caseProcess(prefix);
233
234
  const words = [];
234
235
  let found = 0;
@@ -254,7 +255,7 @@ class Trie {
254
255
  startNode = nodeC;
255
256
  }
256
257
  }
257
- if (startNode !== this.root)
258
+ if (isAllWhenEmptyPrefix || startNode !== this.root)
258
259
  dfs(startNode, prefix);
259
260
  return words;
260
261
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linked-list-typed",
3
- "version": "1.38.8",
3
+ "version": "1.38.9",
4
4
  "description": "Linked List, Doubly Linked List, Singly Linked List. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -66,6 +66,6 @@
66
66
  "typescript": "^4.9.5"
67
67
  },
68
68
  "dependencies": {
69
- "data-structure-typed": "^1.38.8"
69
+ "data-structure-typed": "^1.38.9"
70
70
  }
71
71
  }
@@ -115,7 +115,8 @@ export class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = BinaryTree
115
115
  * Represents a binary tree data structure.
116
116
  * @template N - The type of the binary tree's nodes.
117
117
  */
118
- export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>> implements IBinaryTree<V, N> {
118
+ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>>
119
+ implements IBinaryTree<V, N> {
119
120
  /**
120
121
  * Creates a new instance of BinaryTree.
121
122
  * @param {BinaryTreeOptions} [options] - The options for the binary tree.
@@ -974,7 +975,6 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
974
975
  if (current.left) queue.push(current.left);
975
976
  if (current.right) queue.push(current.right);
976
977
  }
977
-
978
978
  }
979
979
  }
980
980
  return ans;
@@ -24,7 +24,9 @@ export class BSTNode<V = any, N extends BSTNode<V, N> = BSTNodeNested<V>> extend
24
24
  }
25
25
  }
26
26
 
27
- export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>> extends BinaryTree<V, N> implements IBinaryTree<V, N> {
27
+ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>>
28
+ extends BinaryTree<V, N>
29
+ implements IBinaryTree<V, N> {
28
30
  /**
29
31
  * The constructor function initializes a binary search tree object with an optional comparator
30
32
  * function.
@@ -19,7 +19,9 @@ export class RBTreeNode<V = any, N extends RBTreeNode<V, N> = RBTreeNodeNested<V
19
19
  }
20
20
  }
21
21
 
22
- export class RBTree<V, N extends RBTreeNode<V, N> = RBTreeNode<V, RBTreeNodeNested<V>>> extends BST<V, N> implements IBinaryTree<V, N> {
22
+ export class RBTree<V, N extends RBTreeNode<V, N> = RBTreeNode<V, RBTreeNodeNested<V>>>
23
+ extends BST<V, N>
24
+ implements IBinaryTree<V, N> {
23
25
  constructor(options?: RBTreeOptions) {
24
26
  super(options);
25
27
  }
@@ -241,9 +241,10 @@ export class Trie {
241
241
  * @param {string} prefix - The `prefix` parameter is a string that represents the prefix that we want to search for in the
242
242
  * trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
243
243
  * @param {number} max - The max count of words will be found
244
+ * @param isAllWhenEmptyPrefix - If true, when the prefix provided as '', returns all the words in the trie.
244
245
  * @returns {string[]} an array of strings.
245
246
  */
246
- getWords(prefix = '', max = Number.MAX_SAFE_INTEGER): string[] {
247
+ getWords(prefix = '', max = Number.MAX_SAFE_INTEGER, isAllWhenEmptyPrefix = false): string[] {
247
248
  prefix = this._caseProcess(prefix);
248
249
  const words: string[] = [];
249
250
  let found = 0;
@@ -270,7 +271,8 @@ export class Trie {
270
271
  if (nodeC) startNode = nodeC;
271
272
  }
272
273
  }
273
- if (startNode !== this.root) dfs(startNode, prefix);
274
+
275
+ if (isAllWhenEmptyPrefix || startNode !== this.root) dfs(startNode, prefix);
274
276
 
275
277
  return words;
276
278
  }