@kamilmielnik/trie / Trie
Defined in: Trie.ts:18
A class representing the Trie data structure.
new Trie(
root
):Trie
Defined in: Trie.ts:52
Creates a new Trie with optionally given root Node.
Node
= {}
Root Node of the Trie to be created.
readonly
root:Node
Defined in: Trie.ts:45
Represents the root Node of the Trie. It's not a copy. Mutate at your own risk.
add(
word
):Node
Defined in: Trie.ts:62
Inserts given word into the Trie.
string
Word to be inserted into the Trie.
Node representing the end of the added word.
find(
prefix
):undefined
|Node
Defined in: Trie.ts:72
Finds Node representing given prefix in the Trie.
string
Prefix to be found.
undefined
| Node
Node representing a given prefix, undefined if there is no such node.
has(
word
):boolean
Defined in: Trie.ts:82
Tells you whether given word is in the Trie.
string
Word to be found.
boolean
true if given word is in the Trie, false otherwise.
hasPrefix(
prefix
):boolean
Defined in: Trie.ts:94
Tells you whether there are any words with given prefix in the Trie.
See: https://en.wikipedia.org/wiki/String_operations#Prefixes
string
Prefix to be found.
boolean
true if there are any words with given prefix in the Trie, false otherwise.
remove(
word
):boolean
Defined in: Trie.ts:104
Removes given word from the Trie if it exists.
string
Word to be removed.
boolean
true if the word was removed, false otherwise.
serialize():
string
Defined in: Trie.ts:121
Converts the Trie into a string.
The inverse of deserialize.
It serializes 42.8 MB Polish dictionary down to 18.7 MB (-56%).
It serializes 1.9 MB English (US) dictionary down to 1.4 MB (-30%).
It serializes 3 MB English (GB) dictionary down to 2 MB (-32%).
string
String with serialized data.
toArray(
options
?):Descendant
[]
Defined in: Trie.ts:131
Finds all descendants of the Trie's root and returns them as an array.
See TraverseOptions.
An array of descendants.
traverse(
callback
,options
?):void
Defined in: Trie.ts:141
Visits every descendant Node of the Trie and calls a callback.
Callback that will be called for each visited Node. Return true from callback to stop traversing.
See TraverseOptions.
void
static
deserialize(serialized
):Trie
Defined in: Trie.ts:27
Creates a new Trie by deserializing given string.
The inverse of serialize.
string
String with serialized data.
Trie representing deserialized data.
static
fromArray(words
):Trie
Defined in: Trie.ts:37
Creates a new Trie based on array of words.
string
[]
array of words to put in the Trie.
New Trie containing all given words.