-
Notifications
You must be signed in to change notification settings - Fork 0
/
anagram_dict.h
70 lines (61 loc) · 2.03 KB
/
anagram_dict.h
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* @file anagram_dict.h
* Definition of a class for finding anagrams of a given word from a word list
* given at construction.
*
* @author Matt Joras
* @date Winter 2013
*/
#ifndef ANAGRAM_DICT_H
#define ANAGRAM_DICT_H
#include <string>
#include <map>
#include <vector>
/**
* AnagramDict class. Provides interfaces for looking up all anagrams of a
* given word from a word list (from a file or given vector).
*
* @author Matt Joras
* @date Winter 2013
*/
class AnagramDict
{
public:
/**
* Constructs an AnagramDict from a filename with newline-separated
* words.
* @param filename The name of the word list file.
*/
AnagramDict(const std::string& filename);
/**
* Constructs an AnagramDict from a vector of words.
* @param words The vector of strings to be used as source words.
*/
AnagramDict(const std::vector<std::string>& words);
/**
* @param word The word used to find anagrams.
* Gets all anagrams of a given word from the dictionary.
* @return A vector of strings of anagrams of the given word. Empty
* vector returned if no anagrams are found or the word is not in the
* word list.
*/
std::vector<std::string> get_anagrams(const std::string& word) const;
/**
* Gets all known anagrams from the dictionary.
* @return A vector of vectors of strings. Each inner vector contains
* the "anagram siblings", i.e. words that are anagrams of one another.
* NOTE: It is impossible to have one of these vectors have less than
* two elements, i.e. words with no anagrams are ommitted.
*/
std::vector<std::vector<std::string>> get_all_anagrams() const;
private:
std::map<std::string, std::vector<std::string>> dict;
/**
* @param word The word to add to the dictionary
* Adds the word as a (key, value) pair to the dictionary.
* NOTE: word is the value. You will need to decide an appropriate key
* for the word
*/
void add_word_to_dict(const std::string& word);
};
#endif /* ANAGRAM_DICT_H */