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

main
Keisuke Kuroyanagi 2013-09-10 06:08:56 +00:00 committed by Android (Google) Code Review
commit c5f35a9c86
4 changed files with 15 additions and 12 deletions

View File

@ -34,7 +34,7 @@ void DynamicPatriciaTrieNodeReader::fetchNodeInfoFromBufferAndProcessMovedNode(c
mFlags = PatriciaTrieReadingUtils::getFlagsAndAdvancePosition(dictBuf, &pos); mFlags = PatriciaTrieReadingUtils::getFlagsAndAdvancePosition(dictBuf, &pos);
const int parentPos = const int parentPos =
DynamicPatriciaTrieReadingUtils::getParentPosAndAdvancePosition(dictBuf, &pos); 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) { if (outCodePoints != 0) {
mCodePointCount = PatriciaTrieReadingUtils::getCharsAndAdvancePosition( mCodePointCount = PatriciaTrieReadingUtils::getCharsAndAdvancePosition(
dictBuf, mFlags, maxCodePointCount, outCodePoints, &pos); dictBuf, mFlags, maxCodePointCount, outCodePoints, &pos);

View File

@ -136,9 +136,10 @@ bool DynamicPatriciaTrieWritingHelper::markNodeAsMovedAndSetPosition(
&writingPos)) { &writingPos)) {
return false; return false;
} }
// Update moved position, which is stored in the parent position field. // Update moved position, which is stored in the parent offset field.
if (!DynamicPatriciaTrieWritingUtils::writeParentPositionAndAdvancePosition( const int movedPosOffset = movedPos - originalNode->getNodePos();
mBuffer, movedPos, &writingPos)) { if (!DynamicPatriciaTrieWritingUtils::writeParentOffsetAndAdvancePosition(
mBuffer, movedPosOffset, &writingPos)) {
return false; return false;
} }
return true; return true;
@ -150,6 +151,7 @@ bool DynamicPatriciaTrieWritingHelper::writeNodeToBuffer(const bool isBlackliste
const int codePointCount, const int probability, const int childrenPos, const int codePointCount, const int probability, const int childrenPos,
const int originalBigramListPos, const int originalShortcutListPos, const int originalBigramListPos, const int originalShortcutListPos,
int *const writingPos) { int *const writingPos) {
const int nodePos = *writingPos;
// Create node flags and write them. // Create node flags and write them.
const PatriciaTrieReadingUtils::NodeFlags nodeFlags = const PatriciaTrieReadingUtils::NodeFlags nodeFlags =
PatriciaTrieReadingUtils::createAndGetFlags(isBlacklisted, isNotAWord, PatriciaTrieReadingUtils::createAndGetFlags(isBlacklisted, isNotAWord,
@ -160,9 +162,10 @@ bool DynamicPatriciaTrieWritingHelper::writeNodeToBuffer(const bool isBlackliste
writingPos)) { writingPos)) {
return false; return false;
} }
// Write parent position // Calculate a parent offset and write the offset.
if (!DynamicPatriciaTrieWritingUtils::writeParentPositionAndAdvancePosition(mBuffer, parentPos, const int parentOffset = (parentPos != NOT_A_DICT_POS) ? parentPos - nodePos : NOT_A_DICT_POS;
writingPos)) { if (!DynamicPatriciaTrieWritingUtils::writeParentOffsetAndAdvancePosition(mBuffer,
parentOffset, writingPos)) {
return false; return false;
} }
// Write code points // Write code points

View File

@ -68,11 +68,11 @@ const int DynamicPatriciaTrieWritingUtils::NODE_FLAG_FIELD_SIZE = 1;
return buffer->writeUintAndAdvancePosition(nodeFlags, NODE_FLAG_FIELD_SIZE, nodeFlagsFieldPos); return buffer->writeUintAndAdvancePosition(nodeFlags, NODE_FLAG_FIELD_SIZE, nodeFlagsFieldPos);
} }
/* static */ bool DynamicPatriciaTrieWritingUtils::writeParentPositionAndAdvancePosition( // Note that parentOffset is offset from node's head position.
BufferWithExtendableBuffer *const buffer, const int parentPosition, /* static */ bool DynamicPatriciaTrieWritingUtils::writeParentOffsetAndAdvancePosition(
BufferWithExtendableBuffer *const buffer, const int parentOffset,
int *const parentPosFieldPos) { int *const parentPosFieldPos) {
// Note that parentPosition is offset from node's head position. int offset = (parentOffset != NOT_A_DICT_POS) ? parentOffset : 0;
int offset = (parentPosition != NOT_A_DICT_POS) ? parentPosition : 0;
return writeDictOffset(buffer, offset, parentPosFieldPos); return writeDictOffset(buffer, offset, parentPosFieldPos);
} }

View File

@ -39,7 +39,7 @@ class DynamicPatriciaTrieWritingUtils {
const DynamicPatriciaTrieReadingUtils::NodeFlags nodeFlags, const DynamicPatriciaTrieReadingUtils::NodeFlags nodeFlags,
int *const nodeFlagsFieldPos); int *const nodeFlagsFieldPos);
static bool writeParentPositionAndAdvancePosition(BufferWithExtendableBuffer *const buffer, static bool writeParentOffsetAndAdvancePosition(BufferWithExtendableBuffer *const buffer,
const int parentPosition, int *const parentPosFieldPos); const int parentPosition, int *const parentPosFieldPos);
static bool writeCodePointsAndAdvancePosition(BufferWithExtendableBuffer *const buffer, static bool writeCodePointsAndAdvancePosition(BufferWithExtendableBuffer *const buffer,