# `PTree`

# PTree

An experimental and very simple implementation of [prefix tree](https://en.wikipedia.org/wiki/Trie).

## 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. 

```elixir 
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 PTree
```

To see an example of use (working just in linux type OS with bash):
```elixir 
iex> PTree.Example.writer
```

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `ptree` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [
    {:ptree, "~> 0.1.0"}
  ]
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at <https://hexdocs.pm/prefix_tree>.

# `get_builtin_ptree`

```elixir
@spec get_builtin_ptree() :: PTree.Build.ptree()
```

# `search_words`

```elixir
@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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
