Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e531c224 authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi
Browse files

Move a flag about switching dynamic update to java.

Bug: 6669677

Change-Id: I6aa99cae4a227f9202179c2873d13473a773e024
parent 5bf96a8f
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -49,6 +49,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
    /** Whether to print debug output to log */
    private static boolean DEBUG = false;

    // TODO: Remove and enable dynamic update in native code.
    /** Whether to call binary dictionary dynamically updating methods. */
    private static boolean ENABLE_BINARY_DICTIONARY_DYNAMIC_UPDATE = false;

    /**
     * The maximum length of a word in this dictionary.
     */
@@ -72,6 +76,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
     */
    private BinaryDictionary mBinaryDictionary;

    // TODO: Remove and handle dictionaries in native code.
    /** The in-memory dictionary used to generate the binary dictionary. */
    protected AbstractDictionaryWriter mDictionaryWriter;

@@ -225,6 +230,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
        // TODO: Use a queue to reflect what needs to be reflected.
        if (mLocalDictionaryController.writeLock().tryLock()) {
            try {
                if (ENABLE_BINARY_DICTIONARY_DYNAMIC_UPDATE) {
                    mBinaryDictionary.addUnigramWord(word, frequency);
                }
                // TODO: Remove.
                mDictionaryWriter.addUnigramWord(word, shortcutTarget, frequency, isNotAWord);
            } finally {
                mLocalDictionaryController.writeLock().unlock();
@@ -245,6 +254,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
        // TODO: Use a queue to reflect what needs to be reflected.
        if (mLocalDictionaryController.writeLock().tryLock()) {
            try {
                if (ENABLE_BINARY_DICTIONARY_DYNAMIC_UPDATE) {
                    mBinaryDictionary.addBigramWords(word0, word1, frequency);
                }
                // TODO: Remove.
                mDictionaryWriter.addBigramWords(word0, word1, frequency, isValid,
                        0 /* lastTouchedTime */);
            } finally {
@@ -265,6 +278,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
        // TODO: Use a queue to reflect what needs to be reflected.
        if (mLocalDictionaryController.writeLock().tryLock()) {
            try {
                if (ENABLE_BINARY_DICTIONARY_DYNAMIC_UPDATE) {
                    mBinaryDictionary.removeBigramWords(word0, word1);
                }
                // TODO: Remove.
                mDictionaryWriter.removeBigramWords(word0, word1);
            } finally {
                mLocalDictionaryController.writeLock().unlock();
+5 −0
Original line number Diff line number Diff line
@@ -204,6 +204,7 @@ static void latinime_BinaryDictionary_addUnigramWord(JNIEnv *env, jclass clazz,
    }
    jsize wordLength = env->GetArrayLength(word);
    int codePoints[wordLength];
    env->GetIntArrayRegion(word, 0, wordLength, codePoints);
    dictionary->addUnigramWord(codePoints, wordLength, probability);
}

@@ -215,8 +216,10 @@ static void latinime_BinaryDictionary_addBigramWords(JNIEnv *env, jclass clazz,
    }
    jsize word0Length = env->GetArrayLength(word0);
    int word0CodePoints[word0Length];
    env->GetIntArrayRegion(word0, 0, word0Length, word0CodePoints);
    jsize word1Length = env->GetArrayLength(word1);
    int word1CodePoints[word1Length];
    env->GetIntArrayRegion(word1, 0, word1Length, word1CodePoints);
    dictionary->addBigramWords(word0CodePoints, word0Length, word1CodePoints,
            word1Length, probability);
}
@@ -229,8 +232,10 @@ static void latinime_BinaryDictionary_removeBigramWords(JNIEnv *env, jclass claz
    }
    jsize word0Length = env->GetArrayLength(word0);
    int word0CodePoints[word0Length];
    env->GetIntArrayRegion(word0, 0, word0Length, word0CodePoints);
    jsize word1Length = env->GetArrayLength(word1);
    int word1CodePoints[word1Length];
    env->GetIntArrayRegion(word1, 0, word1Length, word1CodePoints);
    dictionary->removeBigramWords(word0CodePoints, word0Length, word1CodePoints,
            word1Length);
}
+13 −32
Original line number Diff line number Diff line
@@ -26,9 +26,6 @@

namespace latinime {

// TODO: Enable dynamic update and remove this flag.
const bool DynamicPatriciaTrieWritingHelper::ENABLE_DYNAMIC_UPDATE = false;

bool DynamicPatriciaTrieWritingHelper::addUnigramWord(
        DynamicPatriciaTrieReadingHelper *const readingHelper,
        const int *const wordCodePoints, const int codePointCount, const int probability) {
@@ -49,33 +46,21 @@ bool DynamicPatriciaTrieWritingHelper::addUnigramWord(
            const int nextIndex = matchedCodePointCount + j;
            if (nextIndex >= codePointCount || !readingHelper->isMatchedCodePoint(j,
                    wordCodePoints[matchedCodePointCount + j])) {
                if (ENABLE_DYNAMIC_UPDATE) {
                return reallocatePtNodeAndAddNewPtNodes(nodeReader,
                        readingHelper->getMergedNodeCodePoints(), j, probability,
                        wordCodePoints + matchedCodePointCount,
                        codePointCount - matchedCodePointCount);
                } else {
                    return false;
                }
            }
        }
        // All characters are matched.
        if (codePointCount == readingHelper->getTotalCodePointCount()) {
            if (ENABLE_DYNAMIC_UPDATE) {
            return setPtNodeProbability(nodeReader, probability,
                    readingHelper->getMergedNodeCodePoints());
            } else {
                return false;
            }
        }
        if (!nodeReader->hasChildren()) {
            if (ENABLE_DYNAMIC_UPDATE) {
            return createChildrenPtNodeArrayAndAChildPtNode(nodeReader, probability,
                    wordCodePoints + readingHelper->getTotalCodePointCount(),
                    codePointCount - readingHelper->getTotalCodePointCount());
            } else {
                return false;
            }
        }
        // Advance to the children nodes.
        parentPos = nodeReader->getNodePos();
@@ -86,14 +71,10 @@ bool DynamicPatriciaTrieWritingHelper::addUnigramWord(
        return false;
    }
    int pos = readingHelper->getPosOfLastForwardLinkField();
    if (ENABLE_DYNAMIC_UPDATE) {
    return createAndInsertNodeIntoPtNodeArray(parentPos,
            wordCodePoints + readingHelper->getPrevTotalCodePointCount(),
            codePointCount - readingHelper->getPrevTotalCodePointCount(),
            probability, &pos);
    } else {
        return false;
    }
}

bool DynamicPatriciaTrieWritingHelper::addBigramWords(const int word0Pos, const int word1Pos,
+0 −1
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ class DynamicPatriciaTrieWritingHelper {
 private:
    DISALLOW_IMPLICIT_CONSTRUCTORS(DynamicPatriciaTrieWritingHelper);

    static const bool ENABLE_DYNAMIC_UPDATE;
    BufferWithExtendableBuffer *const mBuffer;
    DynamicBigramListPolicy *const mBigramPolicy;
    DynamicShortcutListPolicy *const mShortcutPolicy;