Mercurial > dedupe
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CachedEditDistance.hpp Thu Oct 10 01:07:52 2013 +0200 @@ -0,0 +1,48 @@ +#ifndef CACHEDEDITDISTANCE_HPP +#define CACHEDEDITDISTANCE_HPP + +#include "DBCache.hpp" + +#include "EditDistance.hpp" + +template<typename Value> +struct InsertRegulator<OrderedPair<UniqueString>, Value > +{ + uint n; + void start() + { + n = 0; + HuffmanString::getSet().setAutoRebuild(false); + } + + static void finish() + { + HuffmanString::getSet().rebuild(); + HuffmanString::getSet().setAutoRebuild(true); + } + + void next() + { + if (++n == 2048) + HuffmanString::getSet().rebuild(); + } +}; + +class CachedEditDistance { +protected: + typedef DBCache<OrderedPair<UniqueString>, int, true> cacheType; +public: + static int Compute(QString a, QString b, bool removeDiacritics = false); + static void removeDiacriticsNoCopy(QString& in) + { + EditDistance::removeDiacriticsNoCopy(in); + } + static QString removeDiacritics(const QString& in) + { + return EditDistance::removeDiacritics(in); + } + + static cacheType* cache; +}; + +#endif //CACHEDEDITDISTANCE_HPP
