Mercurial > dedupe
comparison CachedEditDistance.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 | |
| children |
comparison
equal
deleted
inserted
replaced
| 77:a827f3687c4a | 78:9744ec195be3 |
|---|---|
| 1 #ifndef CACHEDEDITDISTANCE_HPP | |
| 2 #define CACHEDEDITDISTANCE_HPP | |
| 3 | |
| 4 #include "DBCache.hpp" | |
| 5 | |
| 6 #include "EditDistance.hpp" | |
| 7 | |
| 8 template<typename Value> | |
| 9 struct InsertRegulator<OrderedPair<UniqueString>, Value > | |
| 10 { | |
| 11 uint n; | |
| 12 void start() | |
| 13 { | |
| 14 n = 0; | |
| 15 HuffmanString::getSet().setAutoRebuild(false); | |
| 16 } | |
| 17 | |
| 18 static void finish() | |
| 19 { | |
| 20 HuffmanString::getSet().rebuild(); | |
| 21 HuffmanString::getSet().setAutoRebuild(true); | |
| 22 } | |
| 23 | |
| 24 void next() | |
| 25 { | |
| 26 if (++n == 2048) | |
| 27 HuffmanString::getSet().rebuild(); | |
| 28 } | |
| 29 }; | |
| 30 | |
| 31 class CachedEditDistance { | |
| 32 protected: | |
| 33 typedef DBCache<OrderedPair<UniqueString>, int, true> cacheType; | |
| 34 public: | |
| 35 static int Compute(QString a, QString b, bool removeDiacritics = false); | |
| 36 static void removeDiacriticsNoCopy(QString& in) | |
| 37 { | |
| 38 EditDistance::removeDiacriticsNoCopy(in); | |
| 39 } | |
| 40 static QString removeDiacritics(const QString& in) | |
| 41 { | |
| 42 return EditDistance::removeDiacritics(in); | |
| 43 } | |
| 44 | |
| 45 static cacheType* cache; | |
| 46 }; | |
| 47 | |
| 48 #endif //CACHEDEDITDISTANCE_HPP |
