diff options
author | John Fultz <jfultz@wolfram.com> | 2015-08-20 04:49:46 -0500 |
---|---|---|
committer | John Fultz <jfultz@wolfram.com> | 2015-08-20 04:50:48 -0500 |
commit | 4ef5b33708a4ff0435d5c8254b860cd03a264c66 (patch) | |
tree | 42bd85545d978da36c8dedc5905e0a9f4e1665e0 /quackleio | |
parent | 909c37b77534b88eeafac7a03286692c31cbb1ef (diff) |
Bug fixes to GaddagFactory
A few things from my last commit needed to be
fixed or improved.
Diffstat (limited to 'quackleio')
-rw-r--r-- | quackleio/gaddagfactory.cpp | 24 | ||||
-rw-r--r-- | quackleio/gaddagfactory.h | 13 |
2 files changed, 24 insertions, 13 deletions
diff --git a/quackleio/gaddagfactory.cpp b/quackleio/gaddagfactory.cpp index 3a608f0..e2c726d 100644 --- a/quackleio/gaddagfactory.cpp +++ b/quackleio/gaddagfactory.cpp @@ -36,7 +36,12 @@ GaddagFactory::GaddagFactory(const QString& alphabetFile) root.lastchild = true; } -void GaddagFactory::pushWord(const QString& word) +GaddagFactory::~GaddagFactory() +{ + delete alphas; +} + +bool GaddagFactory::pushWord(const QString& word) { UVString originalString = QuackleIO::Util::qstringToString(word); @@ -61,12 +66,11 @@ void GaddagFactory::pushWord(const QString& word) } gaddagizedWords.push_back(newword); } + return true; } - else - { - UVcout << "not encodable without leftover: " << originalString << endl; - ++m_unencodableWords; - } + + ++m_unencodableWords; + return false; } void GaddagFactory::generate() @@ -82,7 +86,7 @@ void GaddagFactory::writeIndex(const QString& fname) { nodelist.push_back(&root); - root.print(nodelist, ""); + root.print(nodelist); ofstream out(QuackleIO::Util::qstringToStdString(fname).c_str(), ios::out | ios::binary); @@ -114,7 +118,7 @@ void GaddagFactory::writeIndex(const QString& fname) } -void GaddagFactory::Node::print(vector< Node* > nodelist, Quackle::LetterString prefix) +void GaddagFactory::Node::print(vector< Node* >& nodelist) { if (children.size() > 0) { @@ -126,11 +130,11 @@ void GaddagFactory::Node::print(vector< Node* > nodelist, Quackle::LetterString nodelist.push_back(&children[i]); for (size_t i = 0; i < children.size(); i++) - children[i].print(nodelist, prefix + children[i].c); + children[i].print(nodelist); } -void GaddagFactory::Node::pushWord(Quackle::LetterString word) +void GaddagFactory::Node::pushWord(const Quackle::LetterString& word) { if (word.length() == 0) { diff --git a/quackleio/gaddagfactory.h b/quackleio/gaddagfactory.h index ca3bc40..9eb8d72 100644 --- a/quackleio/gaddagfactory.h +++ b/quackleio/gaddagfactory.h @@ -16,6 +16,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#ifndef QUACKLE_GADDAGFACTORY_H +#define QUACKLE_GADDAGFACTORY_H + #include "flexiblealphabet.h" @@ -25,13 +28,14 @@ public: static const Quackle::Letter internalSeparatorRepresentation = QUACKLE_FIRST_LETTER + QUACKLE_MAXIMUM_ALPHABET_SIZE; GaddagFactory(const QString& alphabetFile); + ~GaddagFactory(); int wordCount() const { return gaddagizedWords.size(); }; int nodeCount() const { return nodelist.size(); }; int encodableWords() const { return m_encodableWords; }; int unencodableWords() const { return m_unencodableWords; }; - void pushWord(const QString& word); + bool pushWord(const QString& word); void sortWords() { sort(gaddagizedWords.begin(), gaddagizedWords.end()); }; void generate(); void writeIndex(const QString& fname); @@ -44,8 +48,8 @@ private: vector<Node> children; int pointer; bool lastchild; - void pushWord(Quackle::LetterString word); - void print(vector< Node* > nodelist, Quackle::LetterString prefix); + void pushWord(const Quackle::LetterString& word); + void print(vector< Node* >& nodelist); }; int m_encodableWords; @@ -57,3 +61,6 @@ private: }; + +#endif + |