Constructor
new Trie(wordsopt, strictopt)
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
words |
Array.<string> |
<optional> |
[]
|
Initial words to add to the Trie. |
strict |
boolean |
<optional> |
true
|
If true, removing a word cleans up unused nodes. If false, removal is faster but may leave unused nodes. |
Classes
Methods
add(word) → {boolean}
Parameters:
| Name | Type | Description |
|---|---|---|
word |
string | The word to add. |
Returns:
True if the word was added (didn't exist before), false otherwise.
- Type
- boolean
get(begin) → {Array.<string>}
- Description:
- Returns all words in the Trie that start with the given prefix.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
begin |
string | The prefix to search for. |
Returns:
An array of words starting with the prefix.
- Type
- Array.<string>
getData() → {Array}
Returns:
The root node of the Trie.
- Type
- Array
has(word) → {boolean}
Parameters:
| Name | Type | Description |
|---|---|---|
word |
string | The word to check. |
Returns:
True if the word exists, false otherwise.
- Type
- boolean
remove(word) → {boolean}
Parameters:
| Name | Type | Description |
|---|---|---|
word |
string | The word to remove. |
Returns:
True if the word was removed, false if it didn't exist.
- Type
- boolean