summaryrefslogtreecommitdiff
path: root/Homework/cs3460/typeahead/WordTree.hpp
blob: 0ef8ce07ddef0b9960a32a7f7b5e0e47ddd2a12c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <array>
#include <cstring>
#include <iostream>
#include <memory>
#include <queue>
#include <stdexcept>
#include <string>
#include <vector>

#ifndef WORDTREE_HPP
    #define WORDTREE_HPP

class WordTree
{
    struct TreeNode
    {
        bool m_endOfWord;
        std::array<std::shared_ptr<TreeNode>, 26> m_children;

        TreeNode();
    };
    std::shared_ptr<TreeNode> m_root;

  public:
    WordTree();
    ~WordTree();

    void add(const std::string& word);
    bool find(const std::string& word);
    std::vector<std::string> predict(std::string partial, std::uint8_t howMany);
    std::size_t size();
};

#endif // WORDTREE_HPP