Check usesForgettingCurve in HeaderPolicy.

Bug: 6669677
Change-Id: I47ebfc50f477b2a6514fba6fad421dd90f29ecb1
This commit is contained in:
Keisuke Kuroyanagi 2013-09-05 12:28:38 +09:00
parent 91486bdb3d
commit 5901b5e1bd
2 changed files with 61 additions and 16 deletions

View file

@ -21,6 +21,8 @@
namespace latinime {
const char *const HeaderPolicy::MULTIPLE_WORDS_DEMOTION_RATE_KEY = "MULTIPLE_WORDS_DEMOTION_RATE";
const char *const HeaderPolicy::USES_FORGETTING_CURVE_KEY = "USES_FORGETTING_CURVE";
const char *const HeaderPolicy::LAST_UPDATED_TIME_KEY = "date";
const float HeaderPolicy::DEFAULT_MULTIPLE_WORD_COST_MULTIPLIER = 1.0f;
const float HeaderPolicy::MULTIPLE_WORD_COST_MULTIPLIER_SCALE = 100.0f;
@ -49,24 +51,47 @@ void HeaderPolicy::readHeaderValueOrQuestionMark(const char *const key, int *out
}
float HeaderPolicy::readMultipleWordCostMultiplier() const {
std::vector<int> multipleWordsDemotionRateKeyVector;
insertCharactersIntoVector(MULTIPLE_WORDS_DEMOTION_RATE_KEY,
&multipleWordsDemotionRateKeyVector);
HeaderReadingUtils::AttributeMap::const_iterator it =
mAttributeMap.find(multipleWordsDemotionRateKeyVector);
int attributeValue = 0;
if (getAttributeValueAsInt(MULTIPLE_WORDS_DEMOTION_RATE_KEY, &attributeValue)) {
if (attributeValue <= 0) {
return static_cast<float>(MAX_VALUE_FOR_WEIGHTING);
}
return MULTIPLE_WORD_COST_MULTIPLIER_SCALE / static_cast<float>(attributeValue);
} else {
return DEFAULT_MULTIPLE_WORD_COST_MULTIPLIER;
}
}
bool HeaderPolicy::readUsesForgettingCurveFlag() const {
int attributeValue = 0;
if (getAttributeValueAsInt(USES_FORGETTING_CURVE_KEY, &attributeValue)) {
return attributeValue != 0;
} else {
return false;
}
}
// Returns S_INT_MIN when the key is not found or the value is invalid.
int HeaderPolicy::readLastUpdatedTime() const {
int attributeValue = 0;
if (getAttributeValueAsInt(LAST_UPDATED_TIME_KEY, &attributeValue)) {
return attributeValue;
} else {
return S_INT_MIN;
}
}
// Returns whether the key is found or not and stores the found value into outValue.
bool HeaderPolicy::getAttributeValueAsInt(const char *const key, int *const outValue) const {
std::vector<int> keyVector;
insertCharactersIntoVector(key, &keyVector);
HeaderReadingUtils::AttributeMap::const_iterator it = mAttributeMap.find(keyVector);
if (it == mAttributeMap.end()) {
// The key was not found.
return DEFAULT_MULTIPLE_WORD_COST_MULTIPLIER;
return false;
}
const int headerValue = parseIntAttributeValue(&(it->second));
if (headerValue == S_INT_MIN) {
// Invalid value
return DEFAULT_MULTIPLE_WORD_COST_MULTIPLIER;
}
if (headerValue <= 0) {
return static_cast<float>(MAX_VALUE_FOR_WEIGHTING);
}
return MULTIPLE_WORD_COST_MULTIPLIER_SCALE / static_cast<float>(headerValue);
*outValue = parseIntAttributeValue(&(it->second));
return true;
}
/* static */ HeaderReadingUtils::AttributeMap HeaderPolicy::createAttributeMapAndReadAllAttributes(

View file

@ -32,7 +32,9 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
: mDictBuf(dictBuf), mDictionaryFlags(HeaderReadingUtils::getFlags(dictBuf)),
mSize(HeaderReadingUtils::getHeaderSize(dictBuf)),
mAttributeMap(createAttributeMapAndReadAllAttributes(mDictBuf)),
mMultiWordCostMultiplier(readMultipleWordCostMultiplier()) {}
mMultiWordCostMultiplier(readMultipleWordCostMultiplier()),
mUsesForgettingCurve(readUsesForgettingCurveFlag()),
mLastUpdatedTime(readLastUpdatedTime()) {}
~HeaderPolicy() {}
@ -57,6 +59,14 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
return mMultiWordCostMultiplier;
}
AK_FORCE_INLINE bool usesForgettingCurve() const {
return mUsesForgettingCurve;
}
AK_FORCE_INLINE int getLastUpdatedTime() const {
return mLastUpdatedTime;
}
void readHeaderValueOrQuestionMark(const char *const key,
int *outValue, int outValueSize) const;
@ -64,6 +74,8 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
DISALLOW_IMPLICIT_CONSTRUCTORS(HeaderPolicy);
static const char *const MULTIPLE_WORDS_DEMOTION_RATE_KEY;
static const char *const USES_FORGETTING_CURVE_KEY;
static const char *const LAST_UPDATED_TIME_KEY;
static const float DEFAULT_MULTIPLE_WORD_COST_MULTIPLIER;
static const float MULTIPLE_WORD_COST_MULTIPLIER_SCALE;
@ -72,9 +84,17 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
const int mSize;
HeaderReadingUtils::AttributeMap mAttributeMap;
const float mMultiWordCostMultiplier;
const bool mUsesForgettingCurve;
const int mLastUpdatedTime;
float readMultipleWordCostMultiplier() const;
bool readUsesForgettingCurveFlag() const;
int readLastUpdatedTime() const;
bool getAttributeValueAsInt(const char *const key, int *const outValue) const;
static HeaderReadingUtils::AttributeMap createAttributeMapAndReadAllAttributes(
const uint8_t *const dictBuf);