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

Commit ee98aa17 authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi Committed by Android Git Automerger
Browse files

am c5f35a9c: Merge "Calculate parent offset from the head of moved node."

* commit 'c5f35a9c':
  Calculate parent offset from the head of moved node.
parents d20bee71 c5f35a9c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ void DynamicPatriciaTrieNodeReader::fetchNodeInfoFromBufferAndProcessMovedNode(c
    mFlags = PatriciaTrieReadingUtils::getFlagsAndAdvancePosition(dictBuf, &pos);
    const int parentPos =
            DynamicPatriciaTrieReadingUtils::getParentPosAndAdvancePosition(dictBuf, &pos);
    mParentPos = (parentPos != 0) ? mNodePos + parentPos : NOT_A_DICT_POS;
    mParentPos = (parentPos != 0) ? nodePos + parentPos : NOT_A_DICT_POS;
    if (outCodePoints != 0) {
        mCodePointCount = PatriciaTrieReadingUtils::getCharsAndAdvancePosition(
                dictBuf, mFlags, maxCodePointCount, outCodePoints, &pos);
+9 −6
Original line number Diff line number Diff line
@@ -136,9 +136,10 @@ bool DynamicPatriciaTrieWritingHelper::markNodeAsMovedAndSetPosition(
            &writingPos)) {
        return false;
    }
    // Update moved position, which is stored in the parent position field.
    if (!DynamicPatriciaTrieWritingUtils::writeParentPositionAndAdvancePosition(
            mBuffer, movedPos, &writingPos)) {
    // Update moved position, which is stored in the parent offset field.
    const int movedPosOffset = movedPos - originalNode->getNodePos();
    if (!DynamicPatriciaTrieWritingUtils::writeParentOffsetAndAdvancePosition(
            mBuffer, movedPosOffset, &writingPos)) {
        return false;
    }
    return true;
@@ -150,6 +151,7 @@ bool DynamicPatriciaTrieWritingHelper::writeNodeToBuffer(const bool isBlackliste
        const int codePointCount, const int probability, const int childrenPos,
        const int originalBigramListPos, const int originalShortcutListPos,
        int *const writingPos) {
    const int nodePos = *writingPos;
    // Create node flags and write them.
    const PatriciaTrieReadingUtils::NodeFlags nodeFlags =
            PatriciaTrieReadingUtils::createAndGetFlags(isBlacklisted, isNotAWord,
@@ -160,9 +162,10 @@ bool DynamicPatriciaTrieWritingHelper::writeNodeToBuffer(const bool isBlackliste
            writingPos)) {
        return false;
    }
    // Write parent position
    if (!DynamicPatriciaTrieWritingUtils::writeParentPositionAndAdvancePosition(mBuffer, parentPos,
            writingPos)) {
    // Calculate a parent offset and write the offset.
    const int parentOffset = (parentPos != NOT_A_DICT_POS) ? parentPos - nodePos : NOT_A_DICT_POS;
    if (!DynamicPatriciaTrieWritingUtils::writeParentOffsetAndAdvancePosition(mBuffer,
            parentOffset, writingPos)) {
        return false;
    }
    // Write code points
+4 −4
Original line number Diff line number Diff line
@@ -68,11 +68,11 @@ const int DynamicPatriciaTrieWritingUtils::NODE_FLAG_FIELD_SIZE = 1;
    return buffer->writeUintAndAdvancePosition(nodeFlags, NODE_FLAG_FIELD_SIZE, nodeFlagsFieldPos);
}

/* static */ bool DynamicPatriciaTrieWritingUtils::writeParentPositionAndAdvancePosition(
        BufferWithExtendableBuffer *const buffer, const int parentPosition,
// Note that parentOffset is offset from node's head position.
/* static */ bool DynamicPatriciaTrieWritingUtils::writeParentOffsetAndAdvancePosition(
        BufferWithExtendableBuffer *const buffer, const int parentOffset,
        int *const parentPosFieldPos) {
    // Note that parentPosition is offset from node's head position.
    int offset = (parentPosition != NOT_A_DICT_POS) ? parentPosition : 0;
    int offset = (parentOffset != NOT_A_DICT_POS) ? parentOffset : 0;
    return writeDictOffset(buffer, offset, parentPosFieldPos);
}

+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ class DynamicPatriciaTrieWritingUtils {
            const DynamicPatriciaTrieReadingUtils::NodeFlags nodeFlags,
            int *const nodeFlagsFieldPos);

    static bool writeParentPositionAndAdvancePosition(BufferWithExtendableBuffer *const buffer,
    static bool writeParentOffsetAndAdvancePosition(BufferWithExtendableBuffer *const buffer,
            const int parentPosition, int *const parentPosFieldPos);

    static bool writeCodePointsAndAdvancePosition(BufferWithExtendableBuffer *const buffer,