PTree (Prefix Tree v0.1.0)
Copy MarkdownPTree
An experimental and very simple implementation of prefix tree.
Usage
PTree allow to load in compile time a words list. Just put a text file "words.txt" in the application root. If the file does not exists the builtin list will be empty.
iex> PTree.search_words("he") # Search in builtin PTree
["hesitant", "helpless", "helpful", "help", "hellish", "heavy", "heavenly",
"heat", "heartbreaking", "heap", "healthy", "health", "heal", "heady", "head"]
iex> ptree = PTree.Build.build_ptree(words_list) # Build a custom PTree from a words list
iex> PTree.search_words("he", ptree) # Search in a custom PTreeTo see an example of use (working just in linux type OS with bash):
iex> PTree.Example.writerInstallation
If available in Hex, the package can be installed
by adding ptree to your list of dependencies in mix.exs:
def deps do
[
{:ptree, "~> 0.1.0"}
]
endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/prefix_tree.
Summary
Functions
If you do not send ptree (second parameter) or it is nil, this function will use the builtin PTree.
Functions
@spec get_builtin_ptree() :: PTree.Build.ptree()
@spec search_words( prefix :: String.t(), prefix_tree :: PTree.Build.ptree(), opts :: list() ) :: PTree.Build.words()
If you do not send ptree (second parameter) or it is nil, this function will use the builtin PTree.
Options availables:
- :sort -> return the words list ordered
- take: n -> return only the first n words