Add a variable-length header region to the binary format.
Also bump up the format version to 2.
Bug: 5686638
Change-Id: I3aafdd7e42c422202122998ec093280051aa8e07
diff --git a/native/src/dictionary.cpp b/native/src/dictionary.cpp
index 822c215..8e252f7 100644
--- a/native/src/dictionary.cpp
+++ b/native/src/dictionary.cpp
@@ -19,6 +19,7 @@
#define LOG_TAG "LatinIME: dictionary.cpp"
+#include "binary_format.h"
#include "dictionary.h"
namespace latinime {
@@ -41,10 +42,11 @@
mCorrection = new Correction(typedLetterMultiplier, fullWordMultiplier);
mWordsPriorityQueuePool = new WordsPriorityQueuePool(
maxWords, SUB_QUEUE_MAX_WORDS, maxWordLength);
- mUnigramDictionary = new UnigramDictionary(mDict, typedLetterMultiplier, fullWordMultiplier,
- maxWordLength, maxWords, maxAlternatives, IS_LATEST_DICT_VERSION);
- mBigramDictionary = new BigramDictionary(mDict, maxWordLength, maxAlternatives,
- IS_LATEST_DICT_VERSION, hasBigram(), this);
+ const unsigned int headerSize = BinaryFormat::getHeaderSize(mDict);
+ mUnigramDictionary = new UnigramDictionary(mDict + headerSize, typedLetterMultiplier,
+ fullWordMultiplier, maxWordLength, maxWords, maxAlternatives, IS_LATEST_DICT_VERSION);
+ mBigramDictionary = new BigramDictionary(mDict + headerSize, maxWordLength, maxAlternatives,
+ IS_LATEST_DICT_VERSION, true /* hasBigram */, this);
}
Dictionary::~Dictionary() {
@@ -54,10 +56,6 @@
delete mBigramDictionary;
}
-bool Dictionary::hasBigram() {
- return ((mDict[1] & 0xFF) == 1);
-}
-
bool Dictionary::isValidWord(unsigned short *word, int length) {
return mUnigramDictionary->isValidWord(word, length);
}