Mercurial > dedupe
view UniqueString.hpp @ 115:404795616b1e default tip
Added a lot of common files to ignore
| author | Tom Fredrik Blenning Klaussen <bfg@bfgconsult.no> |
|---|---|
| date | Sat, 25 Mar 2017 17:43:57 +0100 |
| parents | b9515dc35fe4 |
| children |
line wrap: on
line source
#ifndef UNIQUESTRING_HPP #define UNIQUESTRING_HPP #if 0 #include <QtCore/QMap> #include <QtCore/QString> class UniqueString : public QString { private: static QMap<QString, QString> map; public: UniqueString(const QString& str) { if (!map.contains(str)) { map.insert(str, str); } QString::operator=(map.value(str)); } }; #elseif 0 #include "RBTree.hpp" #include <QtCore/QString> #include <QtCore/QStringList> 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) { 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; } 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
