diff options
author | 2012-04-26 23:50:21 -0700 | |
---|---|---|
committer | 2012-05-11 18:43:53 -0700 | |
commit | 4d289d39aeae21064f63d958974816ceee3e9fde (patch) | |
tree | 85e18a25bca6656542cba8f3368871b702d7b918 /native/jni/src/bigram_dictionary.cpp | |
parent | d7889d0fedc1b8aee4964dd5b974f3dc3655df20 (diff) | |
download | latinime-4d289d39aeae21064f63d958974816ceee3e9fde.tar.gz latinime-4d289d39aeae21064f63d958974816ceee3e9fde.tar.xz latinime-4d289d39aeae21064f63d958974816ceee3e9fde.zip |
Contacts dictionary rebuilds only when contact names have changed.
Bug: 6396600
Change-Id: Iad693ec4bab6351793d624e5c5b0a9f5c12a60e3
Diffstat (limited to 'native/jni/src/bigram_dictionary.cpp')
-rw-r--r-- | native/jni/src/bigram_dictionary.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/native/jni/src/bigram_dictionary.cpp b/native/jni/src/bigram_dictionary.cpp index 07031086c..7ed4dc439 100644 --- a/native/jni/src/bigram_dictionary.cpp +++ b/native/jni/src/bigram_dictionary.cpp @@ -128,7 +128,7 @@ int BigramDictionary::getBigrams(const int32_t *prevWord, int prevWordLength, in ++bigramCount; } } - } while (0 != (UnigramDictionary::FLAG_ATTRIBUTE_HAS_NEXT & bigramFlags)); + } while (UnigramDictionary::FLAG_ATTRIBUTE_HAS_NEXT & bigramFlags); return bigramCount; } @@ -189,5 +189,25 @@ bool BigramDictionary::checkFirstCharacter(unsigned short *word) { return false; } +bool BigramDictionary::isValidBigram(const int32_t *word1, int length1, const int32_t *word2, + int length2) { + const uint8_t* const root = DICT; + int pos = getBigramListPositionForWord(word1, length1); + // getBigramListPositionForWord returns 0 if this word isn't in the dictionary or has no bigrams + if (0 == pos) return false; + int nextWordPos = BinaryFormat::getTerminalPosition(root, word2, length2); + if (NOT_VALID_WORD == nextWordPos) return false; + int bigramFlags; + do { + bigramFlags = BinaryFormat::getFlagsAndForwardPointer(root, &pos); + const int bigramPos = BinaryFormat::getAttributeAddressAndForwardPointer(root, bigramFlags, + &pos); + if (bigramPos == nextWordPos) { + return true; + } + } while (UnigramDictionary::FLAG_ATTRIBUTE_HAS_NEXT & bigramFlags); + return false; +} + // TODO: Move functions related to bigram to here } // namespace latinime |