summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lexiconparameters.cpp7
-rw-r--r--lexiconparameters.h2
-rw-r--r--quacker/lexicondialog.cpp72
-rw-r--r--quacker/lexicondialog.h7
-rw-r--r--quacker/settings.cpp68
-rw-r--r--quacker/settings.h2
-rw-r--r--quackleio/dawgfactory.cpp60
-rw-r--r--quackleio/dawgfactory.h17
8 files changed, 128 insertions, 107 deletions
diff --git a/lexiconparameters.cpp b/lexiconparameters.cpp
index bc10773..74de78f 100644
--- a/lexiconparameters.cpp
+++ b/lexiconparameters.cpp
@@ -82,8 +82,6 @@ class Quackle::V1LexiconInterpreter : public LexiconInterpreter
file >> lexparams.m_utf8Alphabet[i];
file.get(); // separator space
}
- file.get(); // whitespace separator
- lexparams.m_wordcount = (bytes[0] << 16) | (bytes[1] << 8) | bytes[2];
while (!file.eof())
{
file.read((char*)(lexparams.m_dawg) + i, 7);
@@ -123,18 +121,18 @@ class Quackle::V1LexiconInterpreter : public LexiconInterpreter
p = (dawg[index] << 16) + (dawg[index + 1] << 8) + (dawg[index + 2]);
letter = dawg[index + 3];
- t = (p != 0);
lastchild = ((letter & 64) != 0);
british = !(letter & 128);
letter = (letter & 63) + QUACKLE_FIRST_LETTER;
playability = (dawg[index + 4] << 16) + (dawg[index + 5] << 8) + (dawg[index + 6]);
+ t = (playability != 0);
}
virtual int versionNumber() const { return 1; }
};
LexiconParameters::LexiconParameters()
- : m_dawg(NULL), m_gaddag(NULL), m_interpreter(NULL), m_wordcount(0)
+ : m_dawg(NULL), m_gaddag(NULL), m_interpreter(NULL), m_wordCount(0)
{
memset(m_hash, 0, sizeof(m_hash));
}
@@ -155,6 +153,7 @@ void LexiconParameters::unloadDawg()
delete[] m_dawg;
m_dawg = NULL;
delete m_interpreter;
+ m_interpreter = NULL;
}
void LexiconParameters::unloadGaddag()
diff --git a/lexiconparameters.h b/lexiconparameters.h
index 4eda4f3..f29a589 100644
--- a/lexiconparameters.h
+++ b/lexiconparameters.h
@@ -88,7 +88,7 @@ protected:
string m_lexiconName;
LexiconInterpreter *m_interpreter;
char m_hash[16];
- int m_wordcount;
+ int m_wordCount;
vector<string> m_utf8Alphabet;
LexiconInterpreter* createInterpreter(char version) const;
diff --git a/quacker/lexicondialog.cpp b/quacker/lexicondialog.cpp
index f92efb1..6630e1f 100644
--- a/quacker/lexicondialog.cpp
+++ b/quacker/lexicondialog.cpp
@@ -40,7 +40,7 @@ public:
};
LexiconDialog::LexiconDialog(QWidget *parent, const QString &originalName) : QDialog(parent),
- m_wordFactory(NULL)
+ m_deleted(false), m_wordFactory(NULL)
{
m_originalName = originalName;
@@ -57,6 +57,7 @@ LexiconDialog::LexiconDialog(QWidget *parent, const QString &originalName) : QDi
m_lexiconInformation = new QLabel("");
m_lexiconInformation->setWordWrap(true);
+ m_lexiconInformation->setTextInteractionFlags(Qt::TextBrowserInteraction);
m_saveChanges = new QPushButton(tr("&Save Changes"));
m_cancel = new QPushButton(tr("&Cancel"));
@@ -107,6 +108,7 @@ LexiconDialog::LexiconDialog(QWidget *parent, const QString &originalName) : QDi
// hook up signals and slots
connect(m_lexiconName, SIGNAL(textEdited(const QString &)), this, SLOT(parametersChanged(const QString &)));
connect(m_addWordsFromFile, SIGNAL(clicked()), this, SLOT(addWordsFromFile()));
+ connect(m_clearAllWords, SIGNAL(clicked()), this, SLOT(loadOriginalDictionary()));
connect(m_saveChanges, SIGNAL(clicked()), this, SLOT(accept()));
connect(m_cancel, SIGNAL(clicked()), this, SLOT(reject()));
connect(m_deleteLexicon, SIGNAL(clicked()), this, SLOT(deleteLexicon()));
@@ -114,26 +116,13 @@ LexiconDialog::LexiconDialog(QWidget *parent, const QString &originalName) : QDi
setWindowTitle(tr("Configure Lexicon - Quackle"));
- Settings::populateComboFromFilenames(m_alphabetCombo, "alphabets", "");
+ Settings::populateComboFromFilenames(m_alphabetCombo, "alphabets", ".quackle_alphabet", "");
alphabetChanged(m_alphabetCombo->currentText());
- string dawgFileName = originalName.toStdString() + ".dawg";
- QString dawgFullFileName;
- if (!originalName.isEmpty())
- dawgFullFileName = QString::fromStdString(Quackle::LexiconParameters::findDictionaryFile(dawgFileName));
-
m_lexiconName->setValidator(m_fileNameValidator);
m_lexiconName->setText(m_originalName);
- if (!dawgFullFileName.isEmpty())
- {
- m_deleteLexicon->setEnabled(Quackle::LexiconParameters::hasUserDictionaryFile(dawgFileName));
- addWordsFromDawgFile(dawgFullFileName);
- }
- else
- m_deleteLexicon->setEnabled(false);
-
- updateLexiconInformation(true);
+ loadOriginalDictionary();
}
LexiconDialog::~LexiconDialog()
@@ -144,9 +133,11 @@ LexiconDialog::~LexiconDialog()
void LexiconDialog::deleteLexicon()
{
- delete m_wordFactory;
- m_wordFactory = NULL;
- updateLexiconInformation();
+ string lexiconNameStr = m_originalName.toStdString();
+ string filename = QUACKLE_DATAMANAGER->makeDataFilename("lexica", lexiconNameStr + ".dawg", true);
+ QFile(QString::fromStdString(filename)).remove();
+ m_deleted = true;
+ QDialog::accept();
}
void LexiconDialog::addWordsFromFile()
@@ -245,8 +236,40 @@ void LexiconDialog::addWordsFromTextFile(const QString &textFile)
}
}
+void LexiconDialog::loadOriginalDictionary()
+{
+ delete m_wordFactory;
+ m_wordFactory = NULL;
+ string dawgFileName = m_originalName.toStdString() + ".dawg";
+ QString dawgFullFileName;
+ if (!m_originalName.isEmpty())
+ dawgFullFileName = QString::fromStdString(Quackle::LexiconParameters::findDictionaryFile(dawgFileName));
+
+ if (!dawgFullFileName.isEmpty())
+ {
+ m_deleteLexicon->setEnabled(Quackle::LexiconParameters::hasUserDictionaryFile(dawgFileName));
+ m_lexiconInformation->setText(tr("Loading dictionary..."));
+ show();
+ qApp->processEvents();
+ addWordsFromDawgFile(dawgFullFileName);
+ }
+ else
+ m_deleteLexicon->setEnabled(false);
+
+ updateLexiconInformation(true);
+}
+
void LexiconDialog::accept()
{
+ string lexiconNameStr = m_lexiconName->text().toStdString();
+ string filename = QUACKLE_DATAMANAGER->makeDataFilename("lexica", lexiconNameStr + ".dawg", true);
+ m_lexiconInformation->setText(tr("Compressing and writing dictionary file...\nThis may take a few minutes."));
+ qApp->processEvents();
+ m_wordFactory->generate();
+ m_lexiconInformation->setText(tr("Writing dictionary file..."));
+ qApp->processEvents();
+ m_wordFactory->writeIndex(filename);
+ m_finalLexiconName = m_lexiconName->text();
QDialog::accept();
}
@@ -256,12 +279,6 @@ void LexiconDialog::updateLexiconInformation(bool firstTime)
QString text;
QString lengthText;
- // only recompute word count when the dictionary changes
- if (m_wordFactory && hash != m_previousHash)
- {
- m_wordFactory->computeWordCount();
- m_previousHash = hash;
- }
int wordCount = m_wordFactory ? m_wordFactory->wordCount() : 0;
if (wordCount == 0)
{
@@ -274,9 +291,7 @@ void LexiconDialog::updateLexiconInformation(bool firstTime)
if (firstTime)
m_originalHash = hash;
- text.append(tr("File name: "));
- text.append(tr("\n\nFile size: "));
- text.append(tr("\n\nWord count: "));
+ text.append(tr("Word count: "));
text.append(QString("%L1").arg(wordCount));
text.append("\n");
text.append(lengthText);
@@ -286,4 +301,5 @@ void LexiconDialog::updateLexiconInformation(bool firstTime)
m_lexiconInformation->setText(text);
m_saveChanges->setEnabled(hash != m_originalHash && !m_lexiconName->text().isEmpty());
+ m_clearAllWords->setEnabled(hash != m_originalHash);
}
diff --git a/quacker/lexicondialog.h b/quacker/lexicondialog.h
index fa80ec1..1f1605b 100644
--- a/quacker/lexicondialog.h
+++ b/quacker/lexicondialog.h
@@ -45,6 +45,9 @@ public:
~LexiconDialog();
virtual void accept();
+ bool itemWasDeleted() { return m_deleted; };
+ const QString &lexiconName() { return m_finalLexiconName; };
+
void updateLexiconInformation(bool firstTime = false);
protected slots:
@@ -52,6 +55,7 @@ protected slots:
void deleteLexicon();
void addWordsFromFile();
void alphabetChanged(const QString &);
+ void loadOriginalDictionary();
protected:
void addWordsFromDawgFile(const QString &dawgfile);
@@ -73,7 +77,8 @@ private:
QString m_originalName;
QString m_alphabetFileName;
QByteArray m_originalHash;
- QByteArray m_previousHash;
+ QString m_finalLexiconName;
+ bool m_deleted;
DawgFactory *m_wordFactory;
};
diff --git a/quacker/settings.cpp b/quacker/settings.cpp
index 3319955..6435605 100644
--- a/quacker/settings.cpp
+++ b/quacker/settings.cpp
@@ -107,7 +107,7 @@ void Settings::createGUI()
m_lexiconNameCombo = new QComboBox;
connect(m_lexiconNameCombo, SIGNAL(activated(const QString &)), this, SLOT(lexiconChanged(const QString &)));
- populateComboFromFilenames(m_lexiconNameCombo, "lexica", "lexicon");
+ populateComboFromFilenames(m_lexiconNameCombo, "lexica", ".dawg", "lexicon");
QLabel *lexiconNameLabel = new QLabel(tr("&Lexicon:"));
lexiconNameLabel->setBuddy(m_lexiconNameCombo);
@@ -118,7 +118,7 @@ void Settings::createGUI()
m_alphabetNameCombo = new QComboBox;
connect(m_alphabetNameCombo, SIGNAL(activated(const QString &)), this, SLOT(alphabetChanged(const QString &)));
- populateComboFromFilenames(m_alphabetNameCombo, "alphabets", "");
+ populateComboFromFilenames(m_alphabetNameCombo, "alphabets", ".quackle_alphabet", "");
QLabel *alphabetNameLabel = new QLabel(tr("&Alphabet:"));
alphabetNameLabel->setBuddy(m_alphabetNameCombo);
@@ -129,7 +129,7 @@ void Settings::createGUI()
m_themeNameCombo = new QComboBox;
connect(m_themeNameCombo, SIGNAL(activated(const QString &)), this, SLOT(themeChanged(const QString &)));
- populateComboFromFilenames(m_themeNameCombo, "themes", "");
+ populateComboFromFilenames(m_themeNameCombo, "themes", ".ini", "");
QLabel *themeNameLabel = new QLabel(tr("&Theme:"));
themeNameLabel->setBuddy(m_themeNameCombo);
@@ -140,7 +140,7 @@ void Settings::createGUI()
m_boardNameCombo = new QComboBox;
connect(m_boardNameCombo, SIGNAL(activated(const QString &)), this, SLOT(boardChanged(const QString &)));
- populateComboFromFilenames(m_boardNameCombo, "boards", "board");
+ populateComboFromFilenames(m_boardNameCombo, "boards", "", "board");
QLabel *boardNameLabel = new QLabel(tr("&Board:"));
boardNameLabel->setBuddy(m_boardNameCombo);
@@ -172,6 +172,8 @@ void Settings::createGUI()
void Settings::load()
{
m_lexiconNameCombo->setCurrentIndex(m_lexiconNameCombo->findText(QuackleIO::Util::stdStringToQString(QUACKLE_LEXICON_PARAMETERS->lexiconName())));
+ if (m_lexiconNameCombo->currentIndex() == -1)
+ m_lexiconNameCombo->setCurrentIndex(m_lexiconNameCombo->findText(QuackleIO::Util::stdStringToQString(QUACKLE_LEXICON_PARAMETERS->lexiconName()) + "*"));
m_lastGoodLexiconValue = m_lexiconNameCombo->currentIndex();
m_alphabetNameCombo->setCurrentIndex(m_alphabetNameCombo->findText(QuackleIO::Util::stdStringToQString(QUACKLE_ALPHABET_PARAMETERS->alphabetName())));
m_themeNameCombo->setCurrentIndex(m_themeNameCombo->findText(m_themeName));
@@ -269,12 +271,12 @@ void Settings::setQuackleToUseLexiconName(const QString &lexiconName)
else
QUACKLE_LEXICON_PARAMETERS->loadGaddag(gaddagFile);
- if (!QUACKLE_LEXICON_PARAMETERS->hasGaddag())
- {
- gaddagFile = QUACKLE_DATAMANAGER->makeDataFilename("lexica", lexiconNameStr + ".gaddag", true);
- buildGaddag(gaddagFile);
- QUACKLE_LEXICON_PARAMETERS->loadGaddag(gaddagFile);
- }
+ // if (!QUACKLE_LEXICON_PARAMETERS->hasGaddag())
+ // {
+ // gaddagFile = QUACKLE_DATAMANAGER->makeDataFilename("lexica", lexiconNameStr + ".gaddag", true);
+ // buildGaddag(gaddagFile);
+ // QUACKLE_LEXICON_PARAMETERS->loadGaddag(gaddagFile);
+ // }
QUACKLE_STRATEGY_PARAMETERS->initialize(lexiconNameStr);
}
@@ -342,6 +344,9 @@ void Settings::setQuackleToUseBoardName(const QString &boardName)
void Settings::lexiconChanged(const QString &lexiconName)
{
+ QString lexicon = lexiconName;
+ if (lexicon.endsWith("*"))
+ lexicon.truncate(lexicon.size() - 1);
if (m_lexiconNameCombo->currentIndex() == m_lexiconNameCombo->count() - 1)
{
editLexicon();
@@ -350,11 +355,11 @@ void Settings::lexiconChanged(const QString &lexiconName)
m_lexiconNameCombo->setCurrentIndex(m_lastGoodLexiconValue);
return;
}
- setQuackleToUseLexiconName(lexiconName);
+ setQuackleToUseLexiconName(lexicon);
m_lastGoodLexiconValue = m_lexiconNameCombo->currentIndex();
CustomQSettings settings;
- settings.setValue("quackle/settings/lexicon-name", lexiconName);
+ settings.setValue("quackle/settings/lexicon-name", lexicon);
emit refreshViews();
}
@@ -465,9 +470,6 @@ void Settings::editBoard()
void Settings::loadBoardNameCombo()
{
- if (m_lexiconNameCombo == 0)
- return;
-
while (m_boardNameCombo->count() > 0)
m_boardNameCombo->removeItem(0);
@@ -489,12 +491,30 @@ void Settings::loadBoardNameCombo()
void Settings::editLexicon()
{
QString name = m_lexiconNameCombo->currentText();
+ if (name.endsWith("*"))
+ name.truncate(name.size() - 1);
if (m_lexiconNameCombo->currentIndex() == m_lexiconNameCombo->count() - 1)
name = "";
LexiconDialog dialog(this, name);
if (dialog.exec())
{
- populateComboFromFilenames(m_lexiconNameCombo, "lexica", "lexicon");
+ populateComboFromFilenames(m_lexiconNameCombo, "lexica", ".dawg", "lexicon");
+ qApp->processEvents();
+ if (dialog.itemWasDeleted())
+ {
+ m_lexiconNameCombo->setCurrentIndex(m_lexiconNameCombo->findText(name));
+ QUACKLE_LEXICON_PARAMETERS->setLexiconName(""); // force lexicon to reload
+ QUACKLE_LEXICON_PARAMETERS->unloadAll();
+ if (m_lexiconNameCombo->currentIndex() != -1)
+ setQuackleToUseLexiconName(name);
+ }
+ else if (!dialog.lexiconName().isEmpty())
+ {
+ QUACKLE_LEXICON_PARAMETERS->setLexiconName(""); // force lexicon to reload
+ QUACKLE_LEXICON_PARAMETERS->unloadAll();
+ setQuackleToUseLexiconName(dialog.lexiconName());
+ m_lexiconNameCombo->setCurrentIndex(m_lexiconNameCombo->findText(name + "*"));
+ }
load();
}
}
@@ -508,7 +528,7 @@ void Settings::editAlphabet()
AlphabetDialog dialog(this);
if (dialog.exec())
{
- populateComboFromFilenames(m_alphabetNameCombo, "alphabets", "alphabet");
+ populateComboFromFilenames(m_alphabetNameCombo, "alphabets", ".quackle_alphabet", "alphabet");
load();
}
#endif // 0
@@ -529,8 +549,11 @@ void Settings::editTheme()
#endif // 0
}
-void Settings::populateComboFromFilenames(QComboBox* combo, const QString &path, const QString &label)
+void Settings::populateComboFromFilenames(QComboBox* combo, const QString &path, const QString &extension, const QString &label)
{
+ while (combo->count() > 0)
+ combo->removeItem(0);
+
QStringList fileList;
QDir dir(self()->m_appDataDir);
if (dir.cd(path))
@@ -547,6 +570,8 @@ void Settings::populateComboFromFilenames(QComboBox* combo, const QString &path,
for (i = fileList.begin(); i != fileList.end(); ++i)
{
fileName = *i;
+ if (!fileName.endsWith(extension))
+ continue;
periodPos = fileName.indexOf('.');
if (periodPos)
{
@@ -555,14 +580,13 @@ void Settings::populateComboFromFilenames(QComboBox* combo, const QString &path,
}
}
- for (i = fileList.begin(); i != fileList.end(); ++i)
+ for (i = list.begin(); i != list.end(); ++i)
{
- QStringList::iterator j = i;
- for (++j; j != fileList.end(); ++j)
+ for (QStringList::iterator j = i + 1; j != list.end(); ++j)
{
if (*i == *j)
{
- *i = "* " + *i;
+ *i = *i + "*";
list.erase(j);
break;
}
diff --git a/quacker/settings.h b/quacker/settings.h
index 7c5738e..babea3c 100644
--- a/quacker/settings.h
+++ b/quacker/settings.h
@@ -42,7 +42,7 @@ public:
static Settings *self();
// load up an item list based on a list of filenames
- static void populateComboFromFilenames(QComboBox* combo, const QString &path, const QString &label);
+ static void populateComboFromFilenames(QComboBox* combo, const QString &path, const QString &extension, const QString &label);
signals:
void refreshViews();
diff --git a/quackleio/dawgfactory.cpp b/quackleio/dawgfactory.cpp
index 869ef8e..4dd4ec3 100644
--- a/quackleio/dawgfactory.cpp
+++ b/quackleio/dawgfactory.cpp
@@ -28,6 +28,8 @@
DawgFactory::DawgFactory(const QString &alphabetFile)
+ : m_encodableWords(0), m_unencodableWords(0), m_duplicateWords(0),
+ m_countsByLength(Quackle::FixedLengthString::maxSize, 0)
{
QuackleIO::FlexibleAlphabetParameters *flexure = new QuackleIO::FlexibleAlphabetParameters;
flexure->load(alphabetFile);
@@ -40,7 +42,6 @@ DawgFactory::DawgFactory(const QString &alphabetFile)
m_root.lastchild = true;
m_hash.int32ptr[0] = m_hash.int32ptr[1] = m_hash.int32ptr[2] = m_hash.int32ptr[3] = 0;
- m_encodableWords = m_unencodableWords = m_duplicateWords = m_wordCount = 0;
}
DawgFactory::~DawgFactory()
@@ -48,7 +49,7 @@ DawgFactory::~DawgFactory()
delete m_alphas;
}
-bool DawgFactory::pushWord(const UVString& word, bool inSmaller, int playability)
+bool DawgFactory::pushWord(const UVString &word, bool inSmaller, int playability)
{
UVString leftover;
Quackle::LetterString encodedWord = m_alphas->encode(word, &leftover);
@@ -59,11 +60,12 @@ bool DawgFactory::pushWord(const UVString& word, bool inSmaller, int playability
return false;
}
-bool DawgFactory::pushWord(const Quackle::LetterString& word, bool inSmaller, int playability)
+bool DawgFactory::pushWord(const Quackle::LetterString &word, bool inSmaller, int playability)
{
if (m_root.pushWord(word, inSmaller, playability))
{
++m_encodableWords;
+ ++m_countsByLength[word.length()];
hashWord(word);
return true;
}
@@ -133,7 +135,7 @@ void DawgFactory::generate()
m_root.print(m_nodelist);
}
-void DawgFactory::writeIndex(const UVString& filename)
+void DawgFactory::writeIndex(const string &filename)
{
ofstream out(filename.c_str(), ios::out | ios::binary);
unsigned char bytes[7];
@@ -187,37 +189,26 @@ void DawgFactory::writeIndex(const UVString& filename)
}
}
-void DawgFactory::computeWordCount() const
-{
- m_countsByLength.resize(0);
- m_wordCount = m_root.wordCount(0, m_countsByLength);
-}
-
string DawgFactory::letterCountString() const
{
ostringstream str;
- if (m_countsByLength.size() < 16)
- m_countsByLength.resize(16, 0);
- str << "2s: " << std::setw(7) << std::right << std::setfill(' ') << m_countsByLength[2];
- str << "\t6s: " << std::setw(7) << std::right << std::setfill(' ') << m_countsByLength[6];
- str << "\t10s: " << std::setw(7) << std::right << std::setfill(' ') << m_countsByLength[10];
- str << "\t14s: " << std::setw(7) << std::right << std::setfill(' ') << m_countsByLength[14];
- str << "\n3s: " << std::setw(7) << std::right << std::setfill(' ') << m_countsByLength[3];
- str << "\t7s: " << std::setw(7) << std::right << std::setfill(' ') << m_countsByLength[7];
- str << "\t11s: " << std::setw(7) << std::right << std::setfill(' ') << m_countsByLength[11];
- str << "\t15s: " << std::setw(7) << std::right << std::setfill(' ') << m_countsByLength[15];
- str << "\n4s: " << std::setw(7) << std::right << std::setfill(' ') << m_countsByLength[4];
- str << "\t8s: " << std::setw(7) << std::right << std::setfill(' ') << m_countsByLength[8];
- str << "\t12s: " << std::setw(7) << std::right << std::setfill(' ') << m_countsByLength[12];
- str << "\n5s: " << std::setw(7) << std::right << std::setfill(' ') << m_countsByLength[5];
- str << "\t9s: " << std::setw(7) << std::right << std::setfill(' ') << m_countsByLength[9];
- str << "\t13s: " << std::setw(7) << std::right << std::setfill(' ') << m_countsByLength[13];
- str << "\n";
+ for (int i = 0; i < 4; i++)
+ {
+ for (int j = 0; j < 4; j++)
+ {
+ const int letterCount = j * 4 + i + 2;
+ if (j != 0)
+ str << "\t";
+ if (m_countsByLength[letterCount] > 0)
+ str << letterCount << "s: " << std::setw(7) << std::right << std::setfill(' ') << m_countsByLength[letterCount];
+ }
+ str << "\n";
+ }
return str.str();
}
-void DawgFactory::Node::print(vector< Node* >& nodelist)
+void DawgFactory::Node::print(vector< Node* > &nodelist)
{
written = true;
@@ -255,7 +246,7 @@ void DawgFactory::Node::print(vector< Node* >& nodelist)
// returns true if the word was actually added...false if it's a duplicate.
-bool DawgFactory::Node::pushWord(const Quackle::LetterString& word, bool inSmaller, int pb)
+bool DawgFactory::Node::pushWord(const Quackle::LetterString &word, bool inSmaller, int pb)
{
bool added;
if (word.length() == 0) {
@@ -318,17 +309,6 @@ bool DawgFactory::Node::equals(const Node &n) const
return true;
}
-int DawgFactory::Node::wordCount(unsigned int depth, vector<unsigned int> &countsByLength) const
-{
- int wordCount = ((playability == 0) ? 0 : 1);
- if (countsByLength.size() < depth + 1)
- countsByLength.resize(depth + 1, 0);
- countsByLength[depth] += wordCount;
- for (size_t i = 0; i < children.size(); i++)
- wordCount += children[i].wordCount(depth + 1, countsByLength);
- return wordCount;
-}
-
int DawgFactory::Node::letterSum() const
{
if (sumexplored)
diff --git a/quackleio/dawgfactory.h b/quackleio/dawgfactory.h
index 5872dc3..efcc455 100644
--- a/quackleio/dawgfactory.h
+++ b/quackleio/dawgfactory.h
@@ -30,19 +30,18 @@ public:
DawgFactory(const QString &alphabetFile);
~DawgFactory();
- void computeWordCount() const;
- int wordCount() const { return m_wordCount; };
+ int wordCount() const { return m_encodableWords; };
string letterCountString() const;
int nodeCount() const { return m_nodelist.size(); };
int encodableWords() const { return m_encodableWords; };
int unencodableWords() const { return m_unencodableWords; };
int duplicateWords() const { return m_duplicateWords; };
- bool pushWord(const UVString& word, bool inSmaller, int playability);
- bool pushWord(const Quackle::LetterString& word, bool inSmaller, int playability);
+ bool pushWord(const UVString &word, bool inSmaller, int playability);
+ bool pushWord(const Quackle::LetterString &word, bool inSmaller, int playability);
void hashWord(const Quackle::LetterString &word);
void generate();
- void writeIndex(const UVString& filename);
+ void writeIndex(const string &filename);
const char* hashBytes() { return m_hash.charptr; };
@@ -50,10 +49,9 @@ private:
class Node {
public:
bool pushWord(const Quackle::LetterString& word, bool inSmaller, int pb);
- void print(vector< Node* >& m_nodelist);
+ void print(vector< Node* > &m_nodelist);
int letterSum() const;
- int wordCount(unsigned int depth, vector<unsigned int> &countsByLength) const;
bool equals(const Node &n) const;
Quackle::Letter c;
@@ -67,7 +65,7 @@ private:
bool lastchild;
mutable bool sumexplored;
- mutable int sum;
+ mutable unsigned int sum;
mutable vector<int> counts;
bool deleted;
@@ -79,8 +77,7 @@ private:
int m_unencodableWords;
int m_duplicateWords;
vector< Node* > m_nodelist;
- mutable int m_wordCount;
- mutable vector<unsigned int> m_countsByLength;
+ vector<unsigned int> m_countsByLength;
Quackle::AlphabetParameters *m_alphas;
Node m_root;
union {