Mercurial > dedupe
comparison UniqueString.hpp @ 16:06166d6c083b
Add configuration processing.
Cache DB values
Add a custom RBTree to save space.
Track multiple DB connections properly.
More testing.
Add ValueExistsException.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Tue, 28 Aug 2012 18:58:02 +0200 |
| parents | |
| children | d0502678429c |
comparison
equal
deleted
inserted
replaced
| 15:199fc63c60c1 | 16:06166d6c083b |
|---|---|
| 1 #ifndef UNIQUESTRING_HPP | |
| 2 #define UNIQUESTRING_HPP | |
| 3 | |
| 4 #if 0 | |
| 5 #include <QtCore/QMap> | |
| 6 #include <QtCore/QString> | |
| 7 | |
| 8 class UniqueString : public QString | |
| 9 { | |
| 10 private: | |
| 11 static QMap<QString, QString> map; | |
| 12 | |
| 13 public: | |
| 14 UniqueString(const QString& str) | |
| 15 { | |
| 16 if (!map.contains(str)) { | |
| 17 map.insert(str, str); | |
| 18 } | |
| 19 QString::operator=(map.value(str)); | |
| 20 } | |
| 21 }; | |
| 22 #else | |
| 23 #include "RBTree.hpp" | |
| 24 #include <QtCore/QString> | |
| 25 #include <QtCore/QDebug> | |
| 26 | |
| 27 class UniqueString : public QString | |
| 28 { | |
| 29 private: | |
| 30 static RBTree<QString> map; | |
| 31 | |
| 32 public: | |
| 33 UniqueString(const QString& str) | |
| 34 { | |
| 35 boost::optional<QString> present = map.find(str); | |
| 36 if (!present) { | |
| 37 map.insert(str); | |
| 38 present = str; | |
| 39 //qDebug() << map.optimal_depth() << " : " << map.avg_depth() << " : " << map.depth(); | |
| 40 } | |
| 41 QString::operator=(*present); | |
| 42 | |
| 43 } | |
| 44 }; | |
| 45 #endif | |
| 46 | |
| 47 #endif //UNIQUESTRING_HPP |
