# HG changeset patch # User Tom Fredrik Blenning Klaussen # Date 1346875005 -7200 # Node ID d0502678429c4214ea601501c5f7249b90a64b7f # Parent 5d14d8c2c29919bc36199d0a47c4e13bdac57b27 Multiplex between different stringtypes. diff -r 5d14d8c2c299 -r d0502678429c UniqueString.cpp --- a/UniqueString.cpp Wed Sep 05 21:56:06 2012 +0200 +++ b/UniqueString.cpp Wed Sep 05 21:56:45 2012 +0200 @@ -1,4 +1,10 @@ #include "UniqueString.hpp" //QMap UniqueString::map; + +/* RBTree UniqueString::map; + +QMap UniqueString::lup; +uint UniqueString::numInserts; +*/ diff -r 5d14d8c2c299 -r d0502678429c UniqueString.hpp --- a/UniqueString.hpp Wed Sep 05 21:56:06 2012 +0200 +++ b/UniqueString.hpp Wed Sep 05 21:56:45 2012 +0200 @@ -19,29 +19,69 @@ QString::operator=(map.value(str)); } }; -#else +#elseif 0 #include "RBTree.hpp" #include +#include #include -class UniqueString : public QString +class UniqueString { private: static RBTree map; + QString myString; + static QMap lup; + static uint numInserts; public: + QStringList chunk(const QString& str) + { + QStringList list = str.split(""); + list << QString(); + return list; + } + UniqueString(const QString& str) { + //QString str = assemble(in_str); boost::optional present = map.find(str); if (!present) { - map.insert(str); - present = str; + QStringList chunks = chunk(str); + foreach (const QString& ch, chunks) { + ++lup[ch]; + } + if (++numInserts % 100 == 0) { + foreach(const QString& key, lup.keys()) { + qDebug() << key << ":" << lup[key]; + } + } + QString tmpStr = str; + tmpStr.squeeze(); + map.insert(tmpStr); + present = tmpStr; //qDebug() << map.optimal_depth() << " : " << map.avg_depth() << " : " << map.depth(); } - QString::operator=(*present); + myString = *present; + } + + operator const QString() const + { + return myString; + } + bool operator<(const UniqueString& rhs) const + { + return myString < rhs.myString; } -}; + + bool operator==(const UniqueString& rhs) const + { + return myString == rhs.myString; + } + }; +#else +#include "HuffmanString.hpp" +typedef HuffmanString UniqueString; #endif #endif //UNIQUESTRING_HPP