From a137c21c9cc45e28af9b72f72f99cefb9bf12a3d Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 30 Jan 2014 18:15:35 +0900 Subject: [PATCH] [HD02] Make the date header attribute mandatory. Bug: 11281748 Change-Id: I48a6f3d95ca89ced0c51335527201ecabfb7998e --- .../latin/utils/UserHistoryDictIOUtils.java | 4 +-- .../dictionary/header/header_policy.cpp | 24 ++++++++--------- .../dictionary/header/header_policy.h | 26 +++++++++---------- .../v4/ver4_patricia_trie_writing_helper.cpp | 14 +++++----- .../utils/dict_file_writing_utils.cpp | 4 +-- 5 files changed, 34 insertions(+), 38 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtils.java b/java/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtils.java index db628fe18..a6ae640d3 100644 --- a/java/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtils.java @@ -46,7 +46,7 @@ public final class UserHistoryDictIOUtils { private static final boolean DEBUG = false; private static final String USES_FORGETTING_CURVE_KEY = "USES_FORGETTING_CURVE"; private static final String USES_FORGETTING_CURVE_VALUE = "1"; - private static final String LAST_UPDATED_TIME_KEY = "date"; + private static final String DATE_KEY = "date"; public interface OnAddWordListener { /** @@ -76,7 +76,7 @@ public final class UserHistoryDictIOUtils { final FormatOptions formatOptions, final HashMap options) { final FusionDictionary fusionDict = constructFusionDictionary(dict, bigrams, options); fusionDict.addOptionAttribute(USES_FORGETTING_CURVE_KEY, USES_FORGETTING_CURVE_VALUE); - fusionDict.addOptionAttribute(LAST_UPDATED_TIME_KEY, + fusionDict.addOptionAttribute(DATE_KEY, String.valueOf(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()))); try { dictEncoder.writeDictionary(fusionDict, formatOptions); diff --git a/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp index 37a5b3fe4..7504524f0 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp @@ -24,7 +24,7 @@ const char *const HeaderPolicy::REQUIRES_GERMAN_UMLAUT_PROCESSING_KEY = "REQUIRES_GERMAN_UMLAUT_PROCESSING"; // TODO: Change attribute string to "IS_DECAYING_DICT". const char *const HeaderPolicy::IS_DECAYING_DICT_KEY = "USES_FORGETTING_CURVE"; -const char *const HeaderPolicy::LAST_UPDATED_TIME_KEY = "date"; +const char *const HeaderPolicy::DATE_KEY = "date"; const char *const HeaderPolicy::LAST_DECAYED_TIME_KEY = "LAST_DECAYED_TIME"; const char *const HeaderPolicy::UNIGRAM_COUNT_KEY = "UNIGRAM_COUNT"; const char *const HeaderPolicy::BIGRAM_COUNT_KEY = "BIGRAM_COUNT"; @@ -73,13 +73,13 @@ bool HeaderPolicy::readRequiresGermanUmlautProcessing() const { REQUIRES_GERMAN_UMLAUT_PROCESSING_KEY, false); } -bool HeaderPolicy::fillInAndWriteHeaderToBuffer(const bool updatesLastUpdatedTime, - const bool updatesLastDecayedTime, const int unigramCount, const int bigramCount, +bool HeaderPolicy::fillInAndWriteHeaderToBuffer(const bool updatesLastDecayedTime, + const int unigramCount, const int bigramCount, const int extendedRegionSize, BufferWithExtendableBuffer *const outBuffer) const { int writingPos = 0; HeaderReadWriteUtils::AttributeMap attributeMapToWrite(mAttributeMap); - fillInHeader(updatesLastDecayedTime, updatesLastDecayedTime, - unigramCount, bigramCount, extendedRegionSize, &attributeMapToWrite); + fillInHeader(updatesLastDecayedTime, unigramCount, bigramCount, + extendedRegionSize, &attributeMapToWrite); if (!HeaderReadWriteUtils::writeDictionaryVersion(outBuffer, mDictFormatVersion, &writingPos)) { return false; @@ -106,18 +106,16 @@ bool HeaderPolicy::fillInAndWriteHeaderToBuffer(const bool updatesLastUpdatedTim return true; } -void HeaderPolicy::fillInHeader(const bool updatesLastUpdatedTime, - const bool updatesLastDecayedTime, const int unigramCount, const int bigramCount, - const int extendedRegionSize, HeaderReadWriteUtils::AttributeMap *outAttributeMap) const { +void HeaderPolicy::fillInHeader(const bool updatesLastDecayedTime, const int unigramCount, + const int bigramCount, const int extendedRegionSize, + HeaderReadWriteUtils::AttributeMap *outAttributeMap) const { HeaderReadWriteUtils::setIntAttribute(outAttributeMap, UNIGRAM_COUNT_KEY, unigramCount); HeaderReadWriteUtils::setIntAttribute(outAttributeMap, BIGRAM_COUNT_KEY, bigramCount); HeaderReadWriteUtils::setIntAttribute(outAttributeMap, EXTENDED_REGION_SIZE_KEY, extendedRegionSize); - if (updatesLastUpdatedTime) { - // Set current time as the last updated time. - HeaderReadWriteUtils::setIntAttribute(outAttributeMap, LAST_UPDATED_TIME_KEY, - TimeKeeper::peekCurrentTime()); - } + // Set the current time as the generation time. + HeaderReadWriteUtils::setIntAttribute(outAttributeMap, DATE_KEY, + TimeKeeper::peekCurrentTime()); if (updatesLastDecayedTime) { // Set current time as the last updated time. HeaderReadWriteUtils::setIntAttribute(outAttributeMap, LAST_DECAYED_TIME_KEY, diff --git a/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.h b/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.h index d65315212..a44f9f0fc 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.h +++ b/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.h @@ -39,8 +39,8 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy { mRequiresGermanUmlautProcessing(readRequiresGermanUmlautProcessing()), mIsDecayingDict(HeaderReadWriteUtils::readBoolAttributeValue(&mAttributeMap, IS_DECAYING_DICT_KEY, false /* defaultValue */)), - mLastUpdatedTime(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap, - LAST_UPDATED_TIME_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)), + mDate(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap, + DATE_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)), mLastDecayedTime(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap, LAST_DECAYED_TIME_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)), mUnigramCount(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap, @@ -62,10 +62,10 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy { mRequiresGermanUmlautProcessing(readRequiresGermanUmlautProcessing()), mIsDecayingDict(HeaderReadWriteUtils::readBoolAttributeValue(&mAttributeMap, IS_DECAYING_DICT_KEY, false /* defaultValue */)), - mLastUpdatedTime(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap, - LAST_UPDATED_TIME_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)), + mDate(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap, + DATE_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)), mLastDecayedTime(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap, - LAST_UPDATED_TIME_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)), + DATE_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)), mUnigramCount(0), mBigramCount(0), mExtendedRegionSize(0), mHasHistoricalInfoOfWords(HeaderReadWriteUtils::readBoolAttributeValue( &mAttributeMap, HAS_HISTORICAL_INFO_KEY, false /* defaultValue */)) {} @@ -75,7 +75,7 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy { : mDictFormatVersion(FormatUtils::UNKNOWN_VERSION), mDictionaryFlags(0), mSize(0), mAttributeMap(), mMultiWordCostMultiplier(0.0f), mRequiresGermanUmlautProcessing(false), mIsDecayingDict(false), - mLastUpdatedTime(0), mLastDecayedTime(0), mUnigramCount(0), mBigramCount(0), + mDate(0), mLastDecayedTime(0), mUnigramCount(0), mBigramCount(0), mExtendedRegionSize(0), mHasHistoricalInfoOfWords(false) {} ~HeaderPolicy() {} @@ -122,8 +122,8 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy { return mRequiresGermanUmlautProcessing; } - AK_FORCE_INLINE int getLastUpdatedTime() const { - return mLastUpdatedTime; + AK_FORCE_INLINE int getDate() const { + return mDate; } AK_FORCE_INLINE int getLastDecayedTime() const { @@ -149,11 +149,11 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy { void readHeaderValueOrQuestionMark(const char *const key, int *outValue, int outValueSize) const; - bool fillInAndWriteHeaderToBuffer(const bool updatesLastUpdatedTime, - const bool updatesLastDecayedTime, const int unigramCount, const int bigramCount, + bool fillInAndWriteHeaderToBuffer(const bool updatesLastDecayedTime, + const int unigramCount, const int bigramCount, const int extendedRegionSize, BufferWithExtendableBuffer *const outBuffer) const; - void fillInHeader(const bool updatesLastUpdatedTime, const bool updatesLastDecayedTime, + void fillInHeader(const bool updatesLastDecayedTime, const int unigramCount, const int bigramCount, const int extendedRegionSize, HeaderReadWriteUtils::AttributeMap *outAttributeMap) const; @@ -163,7 +163,7 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy { static const char *const MULTIPLE_WORDS_DEMOTION_RATE_KEY; static const char *const REQUIRES_GERMAN_UMLAUT_PROCESSING_KEY; static const char *const IS_DECAYING_DICT_KEY; - static const char *const LAST_UPDATED_TIME_KEY; + static const char *const DATE_KEY; static const char *const LAST_DECAYED_TIME_KEY; static const char *const UNIGRAM_COUNT_KEY; static const char *const BIGRAM_COUNT_KEY; @@ -179,7 +179,7 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy { const float mMultiWordCostMultiplier; const bool mRequiresGermanUmlautProcessing; const bool mIsDecayingDict; - const int mLastUpdatedTime; + const int mDate; const int mLastDecayedTime; const int mUnigramCount; const int mBigramCount; diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_writing_helper.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_writing_helper.cpp index b6f813c75..672097455 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_writing_helper.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_writing_helper.cpp @@ -39,12 +39,11 @@ void Ver4PatriciaTrieWritingHelper::writeToDictFile(const char *const dictDirPat BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE); const int extendedRegionSize = headerPolicy->getExtendedRegionSize() + mBuffers->getTrieBuffer()->getUsedAdditionalBufferSize(); - if (!headerPolicy->fillInAndWriteHeaderToBuffer(false /* updatesLastUpdatedTime */, - false /* updatesLastDecayedTime */, unigramCount, bigramCount, extendedRegionSize, - &headerBuffer)) { - AKLOGE("Cannot write header structure to buffer. updatesLastUpdatedTime: %d, " + if (!headerPolicy->fillInAndWriteHeaderToBuffer(false /* updatesLastDecayedTime */, + unigramCount, bigramCount, extendedRegionSize, &headerBuffer)) { + AKLOGE("Cannot write header structure to buffer. " "updatesLastDecayedTime: %d, unigramCount: %d, bigramCount: %d, " - "extendedRegionSize: %d", false, false, unigramCount, bigramCount, + "extendedRegionSize: %d", false, unigramCount, bigramCount, extendedRegionSize); return; } @@ -63,9 +62,8 @@ void Ver4PatriciaTrieWritingHelper::writeToDictFileWithGC(const int rootPtNodeAr } BufferWithExtendableBuffer headerBuffer( BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE); - if (!headerPolicy->fillInAndWriteHeaderToBuffer(true /* updatesLastUpdatedTime */, - true /* updatesLastDecayedTime */, unigramCount, bigramCount, - 0 /* extendedRegionSize */, &headerBuffer)) { + if (!headerPolicy->fillInAndWriteHeaderToBuffer(true /* updatesLastDecayedTime */, + unigramCount, bigramCount, 0 /* extendedRegionSize */, &headerBuffer)) { return; } dictBuffers.get()->flushHeaderAndDictBuffers(dictDirPath, &headerBuffer); diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.cpp b/native/jni/src/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.cpp index 1e57a0b5d..84403c807 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.cpp @@ -48,8 +48,8 @@ const char *const DictFileWritingUtils::TEMP_FILE_SUFFIX_FOR_WRITING_DICT_FILE = HeaderPolicy headerPolicy(FormatUtils::VERSION_4, attributeMap); Ver4DictBuffers::Ver4DictBuffersPtr dictBuffers = Ver4DictBuffers::createVer4DictBuffers(&headerPolicy); - headerPolicy.fillInAndWriteHeaderToBuffer(true /* updatesLastUpdatedTime */, - true /* updatesLastDecayedTime */, 0 /* unigramCount */, 0 /* bigramCount */, + headerPolicy.fillInAndWriteHeaderToBuffer(true /* updatesLastDecayedTime */, + 0 /* unigramCount */, 0 /* bigramCount */, 0 /* extendedRegionSize */, dictBuffers.get()->getWritableHeaderBuffer()); if (!DynamicPtWritingUtils::writeEmptyDictionary( dictBuffers.get()->getWritableTrieBuffer(), 0 /* rootPos */)) {