Autocomplete
Description
The Dictionary
struct stores a collection of words, each with its corresponding weight. In this structure, each word is represented as a path within a tree, where each node along the path corresponds to a character in the word. Terminal nodes hold both the word itself and its weight. These terminal nodes store the complete word to expedite lookups, eliminating the need for backtracking and reconstructing the word from individual characters.
For example, words
A, 1
AA, 2
ABC, 3
Would be represented as
Dictionary
Usage
Both build
and build_without_weights
methods provide a convenient way to initialize and construct a Dictionary
object from a list of words, either with or without weights. These methods abstract away the details of manually inserting each word into the dictionary, making it easier to create and work with Dictionary
objects in your code.
// Example using build method
let words_with_weights = vec!;
let dictionary = build;
// Example using build_without_weights method
let words = vec!;
let dictionary_unweighted = build_without_weights;
To query the Dictionary
by prefix, use words
methods.
// Example using words
dictionary.words
// [
// ("ABC", 3),
// ("AA", 2),
// ("A", 1),
// ]
License
This project is licensed under the MIT license. Please see the LICENSE file for more details.