Mercurial > dedupe
comparison EditDistance.hpp @ 78:9744ec195be3
Encapsulate EditDistance with caching.
| author | Tom Fredrik Blenning Klaussen <bfg@bfgconsult.no> |
|---|---|
| date | Thu, 10 Oct 2013 01:07:52 +0200 |
| parents | e5fa379d4030 |
| children |
comparison
equal
deleted
inserted
replaced
| 77:a827f3687c4a | 78:9744ec195be3 |
|---|---|
| 1 #ifndef EDITDISTANCE_HPP | 1 #ifndef EDITDISTANCE_HPP |
| 2 #define EDITDISTANCE_HPP | 2 #define EDITDISTANCE_HPP |
| 3 | 3 |
| 4 #include "DBCache.hpp" | 4 #include <QtCore/QString> |
| 5 | |
| 6 template<typename Value> | |
| 7 struct InsertRegulator<OrderedPair<UniqueString>, Value > | |
| 8 { | |
| 9 uint n; | |
| 10 void start() | |
| 11 { | |
| 12 n = 0; | |
| 13 HuffmanString::getSet().setAutoRebuild(false); | |
| 14 } | |
| 15 | |
| 16 static void finish() | |
| 17 { | |
| 18 HuffmanString::getSet().rebuild(); | |
| 19 HuffmanString::getSet().setAutoRebuild(true); | |
| 20 } | |
| 21 | |
| 22 void next() | |
| 23 { | |
| 24 if (++n == 2048) | |
| 25 HuffmanString::getSet().rebuild(); | |
| 26 } | |
| 27 }; | |
| 28 | 5 |
| 29 class EditDistance { | 6 class EditDistance { |
| 30 protected: | |
| 31 typedef DBCache<OrderedPair<UniqueString>, int, true> cacheType; | |
| 32 public: | 7 public: |
| 33 static int Compute(QString a, QString b, bool removeDiacritics = false); | 8 static int Compute(QString a, QString b, bool removeDiacritics = false); |
| 34 static void removeDiacriticsNoCopy(QString& in); | 9 static void removeDiacriticsNoCopy(QString& in); |
| 35 static QString removeDiacritics(const QString& in); | 10 static QString removeDiacritics(const QString& in); |
| 36 | |
| 37 static cacheType* cache; | |
| 38 }; | 11 }; |
| 39 | 12 |
| 40 #endif //EDITDISTANCE_HPP | 13 #endif //EDITDISTANCE_HPP |
