lab_dict
Devious Dictionaries: Cleverness Through Association
 All Classes Namespaces Files Functions Variables
AnagramDict Class Reference

AnagramDict class. More...

#include <anagram_dict.h>

Collaboration diagram for AnagramDict:
[legend]

Public Member Functions

 AnagramDict (const std::string &filename)
 Constructs an AnagramDict from a filename with newline-separated words. More...
 
 AnagramDict (const std::vector< std::string > &words)
 Constructs an AnagramDict from a vector of words. More...
 
std::vector< std::stringget_anagrams (const std::string &word) const
 
std::vector< std::vector
< std::string > > 
get_all_anagrams () const
 Gets all known anagrams from the dictionary. More...
 

Private Attributes

std::map< std::string,
std::vector< std::string > > 
dict
 

Detailed Description

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

Constructor & Destructor Documentation

AnagramDict::AnagramDict ( const std::string filename)

Constructs an AnagramDict from a filename with newline-separated words.

Parameters
filenameThe name of the word list file.
AnagramDict::AnagramDict ( const std::vector< std::string > &  words)

Constructs an AnagramDict from a vector of words.

Parameters
wordsThe vector of strings to be used as source words.

Member Function Documentation

vector< vector< string > > AnagramDict::get_all_anagrams ( ) const

Gets all known anagrams from the dictionary.

Returns
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.
vector< string > AnagramDict::get_anagrams ( const std::string word) const
Parameters
wordThe word used to find anagrams. Gets all anagrams of a given word from the dictionary.
Returns
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.
Parameters
wordThe word to find anagrams of.
Returns
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.

The documentation for this class was generated from the following files: