Mercurial > dedupe
changeset 24:d0502678429c
Multiplex between different stringtypes.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Wed, 05 Sep 2012 21:56:45 +0200 |
| parents | 5d14d8c2c299 |
| children | 9ce5b5855fe3 |
| files | UniqueString.cpp UniqueString.hpp |
| diffstat | 2 files changed, 52 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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<QString, QString> UniqueString::map; + +/* RBTree<QString> UniqueString::map; + +QMap<QString, int> UniqueString::lup; +uint UniqueString::numInserts; +*/
--- 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 <QtCore/QString> +#include <QtCore/QStringList> #include <QtCore/QDebug> -class UniqueString : public QString +class UniqueString { private: static RBTree<QString> map; + QString myString; + static QMap<QString, int> 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<QString> 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
