# HG changeset patch # User Tom Fredrik Blenning Klaussen # Date 1347573864 -7200 # Node ID 7b7e84356b39295df031acd2cf7c2666a4bbcc1e # Parent c8111de2e0bb2e4dc20cc276ba1a1b8929058d91 Introduce API for fine tuning inserts. Reduce the amount of rebuilds. diff -r c8111de2e0bb -r 7b7e84356b39 DBCache.hpp --- a/DBCache.hpp Thu Sep 13 23:53:35 2012 +0200 +++ b/DBCache.hpp Fri Sep 14 00:04:24 2012 +0200 @@ -18,6 +18,15 @@ #include +#include + +template +struct InsertRegulator { + static void start() {} + static void finish() {} + static void next() {} +}; + template struct SQLGenerator { @@ -264,11 +273,15 @@ if (!query.exec(repopulateQuery)) { throw SQLException(query); } + InsertRegulator regulator; + regulator.start(); while (query.next()) { Key key = *SQLGenerator::extract(query, "key"); Value value = *SQLGenerator::extract(query, "value"); memoryMap.insert(key, value); + regulator.next(); } + regulator.finish(); } QString queryString = QString("INSERT into %1 (%2, %3) VALUES(%4, %5);") .arg(dictName) diff -r c8111de2e0bb -r 7b7e84356b39 EditDistance.hpp --- a/EditDistance.hpp Thu Sep 13 23:53:35 2012 +0200 +++ b/EditDistance.hpp Fri Sep 14 00:04:24 2012 +0200 @@ -10,18 +10,37 @@ #include #include +template +struct InsertRegulator, 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 EditDistance { protected: - //typedef ThreadSafeLookup, int> cacheType; typedef DBCache, int, true> cacheType; - //typedef QMap, int> cacheType; - //typedef QHash, int> cacheType; public: static int Compute(QString a, QString b, bool removeDiacritics = false); static void removeDiacriticsNoCopy(QString& in); static QString removeDiacritics(const QString& in); - //static cacheType cache; static cacheType* cache; };