summaryrefslogtreecommitdiff
path: root/quackleio
diff options
context:
space:
mode:
Diffstat (limited to 'quackleio')
-rw-r--r--quackleio/dawgfactory.cpp37
-rw-r--r--quackleio/dawgfactory.h8
2 files changed, 41 insertions, 4 deletions
diff --git a/quackleio/dawgfactory.cpp b/quackleio/dawgfactory.cpp
index e7ada85..362dfdc 100644
--- a/quackleio/dawgfactory.cpp
+++ b/quackleio/dawgfactory.cpp
@@ -17,6 +17,8 @@
*/
+#include <iomanip>
+#include <ios>
#include <iostream>
#include <QtCore>
#include <QCryptographicHash>
@@ -184,6 +186,34 @@ void DawgFactory::writeIndex(const UVString& filename)
}
}
+int DawgFactory::wordCount() const
+{
+ m_countsByLength.resize(0);
+ return 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";
+ return str.str();
+}
void DawgFactory::Node::print(vector< Node* >& nodelist)
@@ -287,11 +317,14 @@ bool DawgFactory::Node::equals(const Node &n) const
return true;
}
-int DawgFactory::Node::wordCount() const
+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();
+ wordCount += children[i].wordCount(depth + 1, countsByLength);
return wordCount;
}
diff --git a/quackleio/dawgfactory.h b/quackleio/dawgfactory.h
index 1a1aa7d..8dd6e03 100644
--- a/quackleio/dawgfactory.h
+++ b/quackleio/dawgfactory.h
@@ -19,6 +19,7 @@
#ifndef QUACKLE_DAWGFACTORY_H
#define QUACKLE_DAWGFACTORY_H
+#include <string>
#include <vector>
#include "flexiblealphabet.h"
@@ -29,7 +30,8 @@ public:
DawgFactory(const QString &alphabetFile);
~DawgFactory();
- int wordCount() const { return m_root.wordCount(); };
+ int wordCount() const;
+ string letterCountString() const;
int nodeCount() const { return m_nodelist.size(); };
int encodableWords() const { return m_encodableWords; };
int unencodableWords() const { return m_unencodableWords; };
@@ -50,7 +52,7 @@ private:
void print(vector< Node* >& m_nodelist);
int letterSum() const;
- int wordCount() const;
+ int wordCount(unsigned int depth, vector<unsigned int> &countsByLength) const;
bool equals(const Node &n) const;
Quackle::Letter c;
@@ -65,6 +67,7 @@ private:
mutable bool sumexplored;
mutable int sum;
+ mutable vector<int> counts;
bool deleted;
Node* cloneof;
@@ -75,6 +78,7 @@ private:
int m_unencodableWords;
int m_duplicateWords;
vector< Node* > m_nodelist;
+ mutable vector<unsigned int> m_countsByLength;
Quackle::AlphabetParameters *m_alphas;
Node m_root;
union {